Skip to content

Commit

Permalink
Merge pull request #14 from imclerran/fix-adaptive-nav-prompt
Browse files Browse the repository at this point in the history
Add word wrapping for packages on confirmation screen
  • Loading branch information
imclerran authored Jun 6, 2024
2 parents 8e6be81 + deb741e commit 318351d
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/View.roc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ buildControlPromptStr = \actions, promptsDict ->
|> List.dropIf (\str -> Str.isEmpty str)
|> Str.joinWith " | "

## Render a multi-line text with word wrapping
renderMultiLineText : List Str, { startCol: I32, startRow: I32, maxCol: I32, wrapCol: I32, wordDelim ? Str, fg ? Core.Color } -> List Core.DrawFn
renderMultiLineText = \words, { startCol, startRow, maxCol, wrapCol, wordDelim ? " ", fg ? Standard White } ->
firstLineWidth = maxCol - startCol
consecutiveWidths = maxCol - wrapCol
delims = List.repeat wordDelim (List.len words - 1) |> List.append ""
wordsWithDelims = List.map2 words delims \word, delim -> Str.concat word delim
lineList =
List.walk wordsWithDelims [] \lines, word ->
when lines is
[line] ->
if Num.toI32 (Str.countUtf8Bytes line + Str.countUtf8Bytes word) <= firstLineWidth then
[Str.concat line word]
else
[line, word]
[.. as prevLines, line] ->
if Num.toI32 (Str.countUtf8Bytes line + Str.countUtf8Bytes word) <= consecutiveWidths then
List.concat prevLines [Str.concat line word]
else
List.concat prevLines [line, word]
[] -> [word]
List.mapWithIndex lineList \line, idx ->
if idx == 0 then
Core.drawText line { r: startRow, c: startCol, fg }
else
Core.drawText line { r: startRow + (Num.toI32 idx), c: wrapCol, fg }

## Generate the list of functions to draw the platform select page.
renderPlatformSelect : Model -> List Core.DrawFn
renderPlatformSelect = \model ->
Expand Down Expand Up @@ -169,8 +196,15 @@ renderConfirmation = \model ->
Core.drawText "Platform:" { r: model.menuRow + 1, c: 2, fg: Standard Magenta },
Core.drawText config.platform { r: model.menuRow + 1, c: 12, fg: Standard White },
Core.drawText "Packages:" { r: model.menuRow + 2, c: 2, fg: Standard Magenta },
Core.drawText (config.packages |> Str.joinWith ", ") { r: model.menuRow + 2, c: 12, fg: Standard White },
],
renderMultiLineText config.packages {
startCol: 12,
startRow: (model.menuRow + 2),
maxCol: (model.screen.width - 1),
wrapCol: 2,
wordDelim: ", ",
fg: (Standard White)
},
]

_ -> []
Expand Down

0 comments on commit 318351d

Please sign in to comment.