Skip to content

Commit

Permalink
TerminalScrollPane
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Aug 1, 2024
1 parent f5051a6 commit 19a770b
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 21 deletions.
22 changes: 3 additions & 19 deletions demo/src/main/scala/demo/ColourWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import roguelikestarterkit.ui.component.Component
import roguelikestarterkit.ui.components.BoundsType
import roguelikestarterkit.ui.components.TerminalButton
import roguelikestarterkit.ui.components.TerminalLabel
import roguelikestarterkit.ui.components.TerminalScrollPane
import roguelikestarterkit.ui.components.common.Anchor
import roguelikestarterkit.ui.components.common.ComponentLayout
import roguelikestarterkit.ui.components.common.Overflow
Expand Down Expand Up @@ -67,28 +68,11 @@ object ColourWindow:
.withBoundsMode(BoundsMode.inherit)
.withLayout(ComponentLayout.Vertical(Padding(3, 1, 1, 1)))
.anchor(
ScrollPane(
TerminalScrollPane(
BindingKey("colour-window-scroll-pane"),
BoundsMode.offset(-2, -4),
content,
TerminalButton
.fromTile(
Tile.`#`,
TerminalButton.Theme(
charSheet,
RGBA.Black -> RGBA.Silver,
RGBA.Black -> RGBA.White,
RGBA.White -> RGBA.Black,
hasBorder = false
)
)
).withScrollBackground(bounds =>
Layer(
Shape.Box(
bounds.toScreenSpace(charSheet.size),
Fill.Color(RGBA.SlateGray)
)
)
charSheet
),
Anchor.TopLeft.withPadding(Padding(3, 1, 1, 1))
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package roguelikestarterkit.ui.components

import indigo.*
import roguelikestarterkit.tiles.Tile
import roguelikestarterkit.ui.component.Component
import roguelikestarterkit.ui.components.group.BoundsMode
import roguelikestarterkit.ui.components.group.ScrollPane
import roguelikestarterkit.ui.datatypes.Bounds
import roguelikestarterkit.ui.datatypes.CharSheet
import roguelikestarterkit.ui.datatypes.Dimensions

object TerminalScrollPane:

def apply[A, ReferenceData](
bindingKey: BindingKey,
content: A,
charSheet: CharSheet
)(using c: Component[A, ReferenceData]): ScrollPane[A, ReferenceData] =
val theme = Theme(charSheet)
ScrollPane(
bindingKey,
content,
theme.scrollBar
).withScrollBackground(theme.background)

def apply[A, ReferenceData](
bindingKey: BindingKey,
content: A,
theme: Theme
)(using c: Component[A, ReferenceData]): ScrollPane[A, ReferenceData] =
ScrollPane(
bindingKey,
content,
theme.scrollBar
).withScrollBackground(theme.background)

def apply[A, ReferenceData](
bindingKey: BindingKey,
boundsMode: BoundsMode,
content: A,
charSheet: CharSheet
)(using
c: Component[A, ReferenceData]
): ScrollPane[A, ReferenceData] =
val theme = Theme(charSheet)
ScrollPane(
bindingKey,
boundsMode,
content,
theme.scrollBar
).withScrollBackground(theme.background)

def apply[A, ReferenceData](
bindingKey: BindingKey,
boundsMode: BoundsMode,
content: A,
theme: Theme
)(using
c: Component[A, ReferenceData]
): ScrollPane[A, ReferenceData] =
ScrollPane(
bindingKey,
boundsMode,
content,
theme.scrollBar
).withScrollBackground(theme.background)

def apply[A, ReferenceData](
bindingKey: BindingKey,
dimensions: Dimensions,
content: A,
charSheet: CharSheet
)(using
c: Component[A, ReferenceData]
): ScrollPane[A, ReferenceData] =
val theme = Theme(charSheet)
ScrollPane(
bindingKey,
dimensions,
content,
theme.scrollBar
).withScrollBackground(theme.background)

def apply[A, ReferenceData](
bindingKey: BindingKey,
dimensions: Dimensions,
content: A,
theme: Theme
)(using
c: Component[A, ReferenceData]
): ScrollPane[A, ReferenceData] =
ScrollPane(
bindingKey,
dimensions,
content,
theme.scrollBar
).withScrollBackground(theme.background)

def apply[A, ReferenceData](
bindingKey: BindingKey,
width: Int,
height: Int,
content: A,
charSheet: CharSheet
)(using
c: Component[A, ReferenceData]
): ScrollPane[A, ReferenceData] =
val theme = Theme(charSheet)
ScrollPane(
bindingKey,
width,
height,
content,
theme.scrollBar
).withScrollBackground(theme.background)

def apply[A, ReferenceData](
bindingKey: BindingKey,
width: Int,
height: Int,
content: A,
theme: Theme
)(using
c: Component[A, ReferenceData]
): ScrollPane[A, ReferenceData] =
ScrollPane(
bindingKey,
width,
height,
content,
theme.scrollBar
).withScrollBackground(theme.background)

final case class Theme(
charSheet: CharSheet,
scrollBar: Button[Unit],
background: Bounds => Layer
)
object Theme:
private val defaultBgColor: Fill = Fill.Color(RGBA.White.mix(RGBA.Black, 0.8))

def apply(charSheet: CharSheet): Theme = Theme(
charSheet,
TerminalButton
.fromTile(
Tile.`#`,
TerminalButton.Theme(
charSheet,
RGBA.Black -> RGBA.Silver,
RGBA.Black -> RGBA.White,
RGBA.White -> RGBA.Black,
hasBorder = false
)
),
bounds =>
Layer(
Shape.Box(
bounds.toScreenSpace(charSheet.size),
defaultBgColor
)
)
)
3 changes: 1 addition & 2 deletions ui/src/main/scala/roguelikestarterkit/ui/window/Window.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import roguelikestarterkit.ui.datatypes.UIContext
Scrolling TODOs:
- TerminalScrollPane
- scroll up/down/left/right arrow buttons (use scroll speed in options)
- mouse wheel events (use scroll speed in options?)
- ways to describe scrolling: Fixed amount, proportional, etc.
Expand All @@ -26,7 +25,7 @@ Scrolling TODOs:
Missing stuff:
- Possible to disable the rest of the UI while holding down on a button?
- Terminal title bar doesn't blend nicely with the rest of the window.
- Support for Pointer events on components and windows(?). (Once the issues with PointerState are resolved.)
- One problem here is that if you want to use, say, a TextBox, then you need a BoundaryLocator instance. That comes from UIContext, but we can't have UIContext present as it makes the code untestable currently.
- Might need to make ComponentList's adjust their size based on their content, otherwise they'll be hard to use/use with scrolling.
Expand Down

0 comments on commit 19a770b

Please sign in to comment.