Skip to content

Commit

Permalink
insert spacer between goal categories (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo authored Feb 8, 2023
1 parent ab647f0 commit 2f783c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/Swarm/Game/Scenario/Objective/Presentation/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ type CategorizedGoals = Map GoalStatus (NonEmpty Objective)
data GoalEntry
= Header GoalStatus
| Goal GoalStatus Objective
| Spacer

isHeader :: GoalEntry -> Bool
isHeader = \case
Header _ -> True
_ -> False
shouldSkipSelection :: GoalEntry -> Bool
shouldSkipSelection = \case
Goal _ _ -> False
_ -> True

data GoalTracking = GoalTracking
{ announcements :: [Announcement]
Expand Down
7 changes: 5 additions & 2 deletions src/Swarm/Game/Scenario/Objective/Presentation/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Brick.Widgets.Center
import Brick.Widgets.List qualified as BL
import Control.Applicative ((<|>))
import Control.Lens hiding (Const, from)
import Data.List (intercalate)
import Data.List.NonEmpty qualified as NE
import Data.Map.Strict qualified as M
import Data.Maybe (listToMaybe)
Expand All @@ -23,7 +24,7 @@ makeListWidget :: GoalTracking -> BL.List Name GoalEntry
makeListWidget (GoalTracking _announcements categorizedObjs) =
BL.listMoveTo 1 $ BL.list (GoalWidgets ObjectivesList) (V.fromList objList) 1
where
objList = concatMap f $ M.toList categorizedObjs
objList = intercalate [Spacer] $ map f $ M.toList categorizedObjs
f (h, xs) = Header h : map (Goal h) (NE.toList xs)

renderGoalsDisplay :: GoalDisplay -> Widget Name
Expand Down Expand Up @@ -79,6 +80,7 @@ drawGoalListItem ::
GoalEntry ->
Widget Name
drawGoalListItem _isSelected e = case e of
Spacer -> str " "
Header gs -> withAttr boldAttr $ str $ show gs
Goal gs obj -> getCompletionIcon obj gs <+> titleWidget
where
Expand All @@ -87,5 +89,6 @@ drawGoalListItem _isSelected e = case e of

singleGoalDetails :: GoalEntry -> Widget Name
singleGoalDetails = \case
Header _gs -> displayParagraphs [" "]
Goal _gs obj -> displayParagraphs $ obj ^. objectiveGoal
-- Only Goal entries are selectable, so we should never see this:
_ -> emptyWidget
2 changes: 1 addition & 1 deletion src/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ handleModalEvent = \case
_ -> handleInfoPanelEvent modalScroll (VtyEvent ev)
_ -> handleInfoPanelEvent modalScroll (VtyEvent ev)
where
refreshList lw = nestEventM' lw $ handleListEventWithSeparators ev isHeader
refreshList lw = nestEventM' lw $ handleListEventWithSeparators ev shouldSkipSelection

-- | Write the @ScenarioInfo@ out to disk when exiting a game.
saveScenarioInfoOnQuit :: (MonadIO m, MonadState AppState m) => m ()
Expand Down

0 comments on commit 2f783c5

Please sign in to comment.