-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5051a6
commit 19a770b
Showing
3 changed files
with
166 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
...like-starterkit/src/main/scala/roguelikestarterkit/ui/components/TerminalScrollPane.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters