From 5435ef47501e2bc89862385fc4111251eb1575fb Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Fri, 6 Sep 2024 23:48:39 -0700 Subject: [PATCH] wip: table rendering --- src/swarm-tui/Swarm/TUI/Model/Dialog/Robot.hs | 53 ++++++++++--------- src/swarm-tui/Swarm/TUI/Model/UI.hs | 12 +---- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/swarm-tui/Swarm/TUI/Model/Dialog/Robot.hs b/src/swarm-tui/Swarm/TUI/Model/Dialog/Robot.hs index 8456f251d..1a77b8dae 100644 --- a/src/swarm-tui/Swarm/TUI/Model/Dialog/Robot.hs +++ b/src/swarm-tui/Swarm/TUI/Model/Dialog/Robot.hs @@ -56,8 +56,8 @@ data RobotRenderingContext = RobotRenderingContext makeLenses ''RobotRenderingContext -emptyRobotDisplay :: RobotDisplay -emptyRobotDisplay = +emptyRobotDisplay :: Set DebugOption -> RobotDisplay +emptyRobotDisplay uiDbg = RobotDisplay { _robotsDisplayMode = RobotList , _lastFocusedRobotId = Nothing @@ -66,13 +66,14 @@ emptyRobotDisplay = MixedRenderers { cell = dc , rowHdr = Just rowHdr - , colHdr = Just colHdr + , colHdr = Just $ colHdr uiDbg , colHdrRowHdr = Just $ ColHdrRowHdr $ \_ _ -> vLimit 1 (fill ' ') <=> hBorder } } renderTheRobots :: RobotDisplay -> Widget Name -renderTheRobots rd = renderMixedTabularList (rd ^. libRenderers) (LstFcs True) (rd ^. libList) +renderTheRobots rd = + renderMixedTabularList (rd ^. libRenderers) (LstFcs True) (rd ^. libList) columnHdrAttr :: AttrName columnHdrAttr = attrName "columnHeader" @@ -80,15 +81,17 @@ columnHdrAttr = attrName "columnHeader" rowHdrAttr :: AttrName rowHdrAttr = attrName "rowHeader" -colHdr :: MixedColHdr Name Widths -colHdr = +colHdr :: Set DebugOption -> MixedColHdr Name Widths +colHdr uiDbg = MixedColHdr - { draw = \_ (MColC (Ix ci)) -> case colHdrs V.!? ci of + { draw = \_ (MColC (Ix ci)) -> case hdrs V.!? ci of Just ch -> withAttr columnHdrAttr (padRight Max (str ch) <+> str " ") <=> hBorder Nothing -> emptyWidget , widths = \(Widths song) -> song , height = ColHdrH 2 } + where + hdrs = colHdrs uiDbg rowHdr :: RowHdr Name LibRobotRow rowHdr = @@ -103,8 +106,24 @@ rowHdr = , toRH = \_ (Ix i) -> i + 1 } -colHdrs :: Vector String -colHdrs = V.fromList ["Artist", "Title", "Album"] +colHdrs :: Set DebugOption -> Vector String +colHdrs uiDbg = V.fromList augmentedHeadings + where + headings = + [ "Name" + , "Age" + , "Pos" + , "Items" + , "Status" + , "Actns" + , "Cmds" + , "Cycles" + , "Activity" + , "Log" + ] + -- headers = withAttr robotAttr . txt <$> augmentedHeadings + augmentedHeadings = applyWhen debugRID ("ID" :) headings + debugRID = uiDbg ^. Lens.contains ListRobotIDs wpr :: WidthsPerRow LibRobotRow Widths wpr = WsPerR $ \(Widths song) e -> case e of @@ -143,22 +162,8 @@ wprk = WsPerRK $ \(AvlW aW) _ -> robotsTable :: RobotRenderingContext -> BT.Table Name robotsTable c = - BT.table $ - map (padLeftRight 1) <$> (headers : robotRows) + BT.table [] where - headings = - [ "Name" - , "Age" - , "Pos" - , "Items" - , "Status" - , "Actns" - , "Cmds" - , "Cycles" - , "Activity" - , "Log" - ] - headers = withAttr robotAttr . txt <$> applyWhen debugRID ("ID" :) headings robotRows = mkRobotRow <$> robots mkRobotRow robot = applyWhen debugRID (idWidget :) cells diff --git a/src/swarm-tui/Swarm/TUI/Model/UI.hs b/src/swarm-tui/Swarm/TUI/Model/UI.hs index 83f9231d3..025c1f868 100644 --- a/src/swarm-tui/Swarm/TUI/Model/UI.hs +++ b/src/swarm-tui/Swarm/TUI/Model/UI.hs @@ -62,29 +62,21 @@ module Swarm.TUI.Model.UI ( import Brick (AttrMap) import Brick.Focus -import Brick.Widgets.List qualified as BL import Control.Arrow ((&&&)) import Control.Effect.Accum import Control.Effect.Lift import Control.Lens hiding (from, (<.>)) -import Data.Bits (FiniteBits (finiteBitSize)) import Data.List.Extra (enumerate) import Data.Map (Map) import Data.Map qualified as M import Data.Sequence (Seq) import Data.Set (Set) -import Data.Text (Text) import Data.Text qualified as T import Swarm.Game.Achievement.Attainment import Swarm.Game.Achievement.Definitions import Swarm.Game.Achievement.Persistence import Swarm.Game.Failure (SystemFailure) import Swarm.Game.ResourceLoading (getSwarmHistoryPath) -import Swarm.Game.ScenarioInfo ( - ScenarioInfoPair, - ) -import Swarm.Game.Universe -import Swarm.Game.World.Coords import Swarm.TUI.Editor.Model import Swarm.TUI.Inventory.Sorting import Swarm.TUI.Launch.Model @@ -97,7 +89,7 @@ import Swarm.TUI.Model.Repl import Swarm.TUI.Model.UI.Gameplay import Swarm.TUI.View.Attribute.Attr (swarmAttrMap) import Swarm.Util -import Swarm.Util.Lens (makeLensesExcluding, makeLensesNoSigs) +import Swarm.Util.Lens (makeLensesNoSigs) import System.Clock -- * Toplevel UIState definition @@ -207,7 +199,7 @@ initUIState speedFactor showMainMenu debug = do { _uiModal = Nothing , _uiGoal = emptyGoalDisplay , _uiStructure = emptyStructureDisplay - , _uiRobot = emptyRobotDisplay + , _uiRobot = emptyRobotDisplay debug } , _uiIsAutoPlay = False , _uiTiming =