Skip to content

Commit d7a04e4

Browse files
Improve menu highlight and add padding
1 parent 155c64d commit d7a04e4

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/Swarm/TUI/Attr.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ swarmAttrMap =
4747
, (sandAttr, fg (V.rgbColor @Int 194 178 128))
4848
, (fireAttr, fg V.red `V.withStyle` V.bold)
4949
, (redAttr, fg V.red)
50+
, (notifAttr, fg V.yellow `V.withStyle` V.bold)
5051
, (greenAttr, fg V.green)
5152
, (blueAttr, fg V.blue)
5253
, (deviceAttr, fg V.yellow `V.withStyle` V.bold)
@@ -85,6 +86,7 @@ robotAttr
8586
, baseAttr
8687
, fireAttr
8788
, redAttr
89+
, notifAttr
8890
, greenAttr
8991
, blueAttr
9092
, woodAttr
@@ -119,13 +121,14 @@ snowAttr = "snow"
119121
sandAttr = "sand"
120122
fireAttr = "fire"
121123
redAttr = "red"
124+
highlightAttr = "highlight"
122125
greenAttr = "green"
123126
blueAttr = "blue"
124127
rockAttr = "rock"
125128
woodAttr = "wood"
126129
baseAttr = "base"
127130
deviceAttr = "device"
128-
highlightAttr = "highlight"
131+
notifAttr = "notif"
129132
sepAttr = "sep"
130133
infoAttr = "info"
131134
defAttr = "def"

src/Swarm/TUI/View.hs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,15 @@ helpWidget = (helpKeys <=> fill ' ') <+> (helpCommands <=> fill ' ')
363363
]
364364

365365
helpRecipes :: Int -> [Recipe Entity] -> Widget Name
366-
helpRecipes count xs = viewport RecipesViewport Vertical (vBox recipesLists)
366+
helpRecipes count xs = viewport RecipesViewport Vertical (padTop (Pad 1) $ vBox recipesLists)
367367
where
368368
(news, knowns) = splitAt count xs
369369
recipesLists = drawRecipes news <> sepRecipes <> drawRecipes knowns
370370
drawRecipes = map (padLeftRight 18 . padBottom (Pad 1) . drawRecipe Nothing Nothing)
371371
-- TODO: figure out how to make the whole hBorder to be red, not just the label
372372
sepRecipes
373373
| count > 0 && not (null knowns) =
374-
[ padBottom (Pad 1) (withAttr "red" $ hBorderWithLabel (padLeftRight 1 (txt "new↑")))
374+
[ padBottom (Pad 1) (withAttr redAttr $ hBorderWithLabel (padLeftRight 1 (txt "new↑")))
375375
]
376376
| otherwise = []
377377

@@ -392,6 +392,7 @@ drawKeyMenu s =
392392
. (++ [gameModeWidget])
393393
. map (padLeftRight 1 . drawKeyCmd)
394394
. (globalKeyCmds ++)
395+
. map (\(k, n) -> (NoHighlight, k, n))
395396
. keyCmdsFor
396397
. focusGetCurrent
397398
. view (uiState . uiFocusRing)
@@ -405,11 +406,11 @@ drawKeyMenu s =
405406

406407
availRecipes
407408
| null (s ^. gameState . availableRecipes) = []
408-
| otherwise = [("F2", knownMark (s ^. gameState . availableRecipesNewCount) <> "Recipes")]
409-
410-
knownMark count
411-
| count > 0 = "*"
412-
| otherwise = ""
409+
| otherwise =
410+
let highlight
411+
| s ^. gameState . availableRecipesNewCount > 0 = Highlighted
412+
| otherwise = NoHighlight
413+
in [(highlight, "F2", "Recipes")]
413414

414415
gameModeWidget =
415416
padLeft Max . padLeftRight 1
@@ -419,7 +420,10 @@ drawKeyMenu s =
419420
False -> "Classic"
420421
True -> "Creative"
421422
globalKeyCmds =
422-
[("F1", "help")] <> availRecipes <> [("Tab", "cycle")] <> [("^k", "creative") | cheat]
423+
[(NoHighlight, "F1", "help")]
424+
<> availRecipes
425+
<> [(NoHighlight, "Tab", "cycle")]
426+
<> [(NoHighlight, "^k", "creative") | cheat]
423427

424428
keyCmdsFor (Just REPLPanel) =
425429
[ ("↓↑", "history")
@@ -445,9 +449,12 @@ drawKeyMenu s =
445449
]
446450
keyCmdsFor _ = []
447451

452+
data KeyHighlight = NoHighlight | Highlighted
453+
448454
-- | Draw a single key command in the menu.
449-
drawKeyCmd :: (Text, Text) -> Widget Name
450-
drawKeyCmd (key, cmd) = txt $ T.concat ["[", key, "] ", cmd]
455+
drawKeyCmd :: (KeyHighlight, Text, Text) -> Widget Name
456+
drawKeyCmd (Highlighted, key, cmd) = hBox [withAttr notifAttr (txt $ T.concat ["[", key, "] "]), txt cmd]
457+
drawKeyCmd (NoHighlight, key, cmd) = txt $ T.concat ["[", key, "] ", cmd]
451458

452459
------------------------------------------------------------
453460
-- World panel

0 commit comments

Comments
 (0)