diff --git a/src/Swarm/TUI/Controller.hs b/src/Swarm/TUI/Controller.hs index 9add43d8..e52da905 100644 --- a/src/Swarm/TUI/Controller.hs +++ b/src/Swarm/TUI/Controller.hs @@ -224,12 +224,17 @@ handleMainEvent s = \case continueWithoutRedraw s _ -> continueWithoutRedraw (s & uiState . uiWorldCursor .~ Nothing) MouseUp n _ _mouseLoc -> do - setFocus s $ case n of + let s' = + s & case n of + InventoryListItem pos -> uiState . uiInventory . traverse . _2 %~ BL.listMoveTo pos + _ -> id + setFocus s' $ case n of -- Adapt click event origin to their right panel. -- For the REPL and the World view, using 'Brick.Widgets.Core.clickable' correctly set the origin. -- However this does not seems to work for the robot and info panel. -- Thus we force the destination focus here. InventoryList -> RobotPanel + InventoryListItem _ -> RobotPanel InfoViewport -> InfoPanel _ -> n -- dispatch any other events to the focused panel handler diff --git a/src/Swarm/TUI/Model.hs b/src/Swarm/TUI/Model.hs index 9a66fd5d..876b81b5 100644 --- a/src/Swarm/TUI/Model.hs +++ b/src/Swarm/TUI/Model.hs @@ -176,13 +176,15 @@ data Name | -- | The list of inventory items for the currently -- focused robot. InventoryList + | -- | The inventory item position in the InventoryList. + InventoryListItem Int | -- | The list of main menu choices. MenuList | -- | The list of scenario choices. ScenarioList | -- | The scrollable viewport for the info panel. InfoViewport - deriving (Eq, Ord, Show, Read, Enum, Bounded) + deriving (Eq, Ord, Show, Read) infoScroll :: ViewportScroll Name infoScroll = viewportScroll InfoViewport diff --git a/src/Swarm/TUI/View.hs b/src/Swarm/TUI/View.hs index 2602e5a7..e7e9640b 100644 --- a/src/Swarm/TUI/View.hs +++ b/src/Swarm/TUI/View.hs @@ -500,6 +500,7 @@ drawRobotPanel :: AppState -> Widget Name drawRobotPanel s = case (s ^. gameState . to focusedRobot, s ^. uiState . uiInventory) of (Just r, Just (_, lst)) -> let V2 x y = r ^. robotLocation + drawClickableItem pos selb = clickable (InventoryListItem pos) . drawItem (lst ^. BL.listSelectedL) pos selb in padBottom Max $ vBox [ hCenter $ @@ -508,7 +509,7 @@ drawRobotPanel s = case (s ^. gameState . to focusedRobot, s ^. uiState . uiInve , padLeft (Pad 2) $ str (printf "(%d, %d)" x y) , padLeft (Pad 2) $ displayEntity (r ^. robotEntity) ] - , padAll 1 (BL.renderListWithIndex (drawItem (lst ^. BL.listSelectedL)) True lst) + , padAll 1 (BL.renderListWithIndex drawClickableItem True lst) ] _ -> padRight Max . padBottom Max $ str " "