Skip to content

Commit

Permalink
Repackaged ScrollPane, ComponentGroup and ComponentList
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Aug 3, 2024
1 parent 3929453 commit 072a88c
Show file tree
Hide file tree
Showing 28 changed files with 109 additions and 100 deletions.
16 changes: 8 additions & 8 deletions demo/src/main/scala/demo/ColourWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import roguelikestarterkit.*
import roguelikestarterkit.syntax.*
import roguelikestarterkit.ui.component.Component
import roguelikestarterkit.ui.components.BoundsType
import roguelikestarterkit.ui.components.ComponentGroup
import roguelikestarterkit.ui.components.ScrollPane
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
import roguelikestarterkit.ui.components.common.Padding
import roguelikestarterkit.ui.components.group.BoundsMode
import roguelikestarterkit.ui.components.group.ComponentGroup
import roguelikestarterkit.ui.components.group.FitMode
import roguelikestarterkit.ui.components.group.ScrollPane
import roguelikestarterkit.ui.components.datatypes.Anchor
import roguelikestarterkit.ui.components.datatypes.BoundsMode
import roguelikestarterkit.ui.components.datatypes.ComponentLayout
import roguelikestarterkit.ui.components.datatypes.FitMode
import roguelikestarterkit.ui.components.datatypes.Overflow
import roguelikestarterkit.ui.components.datatypes.Padding
import roguelikestarterkit.ui.window.Space
import roguelikestarterkit.ui.window.TerminalWindow

Expand Down
8 changes: 4 additions & 4 deletions demo/src/main/scala/demo/ComponentsWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package demo
import indigo.*
import roguelikestarterkit.*
import roguelikestarterkit.syntax.*
import roguelikestarterkit.ui.components.ComponentGroup
import roguelikestarterkit.ui.components.TerminalButton
import roguelikestarterkit.ui.components.TerminalLabel
import roguelikestarterkit.ui.components.common.ComponentLayout
import roguelikestarterkit.ui.components.common.Overflow
import roguelikestarterkit.ui.components.common.Padding
import roguelikestarterkit.ui.components.group.ComponentGroup
import roguelikestarterkit.ui.components.datatypes.ComponentLayout
import roguelikestarterkit.ui.components.datatypes.Overflow
import roguelikestarterkit.ui.components.datatypes.Padding
import roguelikestarterkit.ui.window.TerminalWindow

object ComponentsWindow:
Expand Down
12 changes: 6 additions & 6 deletions demo/src/main/scala/demo/ComponentsWindow2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package demo
import indigo.*
import indigo.syntax.*
import roguelikestarterkit.*
import roguelikestarterkit.ui.components.ComponentGroup
import roguelikestarterkit.ui.components.ComponentList
import roguelikestarterkit.ui.components.TerminalButton
import roguelikestarterkit.ui.components.TerminalInput
import roguelikestarterkit.ui.components.TerminalLabel
import roguelikestarterkit.ui.components.TerminalTextArea
import roguelikestarterkit.ui.components.common.ComponentId
import roguelikestarterkit.ui.components.common.ComponentLayout
import roguelikestarterkit.ui.components.common.Overflow
import roguelikestarterkit.ui.components.common.Padding
import roguelikestarterkit.ui.components.group.ComponentGroup
import roguelikestarterkit.ui.components.list.ComponentList
import roguelikestarterkit.ui.components.datatypes.ComponentId
import roguelikestarterkit.ui.components.datatypes.ComponentLayout
import roguelikestarterkit.ui.components.datatypes.Overflow
import roguelikestarterkit.ui.components.datatypes.Padding
import roguelikestarterkit.ui.window.TerminalWindow

object ComponentsWindow2:
Expand Down
12 changes: 6 additions & 6 deletions demo/src/main/scala/demo/MenuWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package demo

import indigo.*
import roguelikestarterkit.*
import roguelikestarterkit.ui.components.ComponentGroup
import roguelikestarterkit.ui.components.ComponentList
import roguelikestarterkit.ui.components.TerminalButton
import roguelikestarterkit.ui.components.common.ComponentId
import roguelikestarterkit.ui.components.common.ComponentLayout
import roguelikestarterkit.ui.components.common.Overflow
import roguelikestarterkit.ui.components.common.Padding
import roguelikestarterkit.ui.components.group.ComponentGroup
import roguelikestarterkit.ui.components.list.ComponentList
import roguelikestarterkit.ui.components.datatypes.ComponentId
import roguelikestarterkit.ui.components.datatypes.ComponentLayout
import roguelikestarterkit.ui.components.datatypes.Overflow
import roguelikestarterkit.ui.components.datatypes.Padding
import roguelikestarterkit.ui.window.TerminalWindow

object MenuWindow:
Expand Down
4 changes: 2 additions & 2 deletions demo/src/main/scala/demo/NoTerminalUI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import indigo.scenes.*
import indigo.shared.subsystems.SubSystemFrameContext.*
import roguelikestarterkit.*
import roguelikestarterkit.ui.component.Component
import roguelikestarterkit.ui.components.group.ComponentGroup
import roguelikestarterkit.ui.components.list.ComponentList
import roguelikestarterkit.ui.components.ComponentGroup
import roguelikestarterkit.ui.components.ComponentList

object NoTerminalUI extends Scene[Size, Model, ViewModel]:

Expand Down
8 changes: 4 additions & 4 deletions demo/src/main/scala/demo/RogueLikeGame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import indigo.*
import indigo.scenes.*
import indigoextras.subsystems.FPSCounter
import roguelikestarterkit.*
import roguelikestarterkit.ui.components.common.ComponentId
import roguelikestarterkit.ui.components.group.BoundsMode
import roguelikestarterkit.ui.components.group.ComponentGroup
import roguelikestarterkit.ui.components.list.ComponentList
import roguelikestarterkit.ui.components.ComponentGroup
import roguelikestarterkit.ui.components.ComponentList
import roguelikestarterkit.ui.components.datatypes.BoundsMode
import roguelikestarterkit.ui.components.datatypes.ComponentId

import scala.scalajs.js.annotation.JSExportTopLevel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ 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.components.datatypes.BoundsMode
import roguelikestarterkit.ui.datatypes.Bounds
import roguelikestarterkit.ui.datatypes.CharSheet
import roguelikestarterkit.ui.datatypes.Dimensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import roguelikestarterkit.Tile
import roguelikestarterkit.UIContext
import roguelikestarterkit.terminal.RogueTerminalEmulator
import roguelikestarterkit.ui.component.Component
import roguelikestarterkit.ui.components.common.Padding
import roguelikestarterkit.ui.components.datatypes.Padding
import roguelikestarterkit.ui.datatypes.Bounds

object TerminalWindow:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package roguelikestarterkit.ui.components

import roguelikestarterkit.ui.components.common.Padding
import roguelikestarterkit.ui.components.datatypes.Padding
import roguelikestarterkit.ui.datatypes.Bounds

enum BoundsType[ReferenceData, A]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package roguelikestarterkit.ui.components
import indigo.*
import indigo.syntax.*
import roguelikestarterkit.ui.component.Component
import roguelikestarterkit.ui.components.common.ComponentLayout.Horizontal
import roguelikestarterkit.ui.components.datatypes.ComponentLayout.Horizontal
import roguelikestarterkit.ui.datatypes.Bounds
import roguelikestarterkit.ui.datatypes.Coords
import roguelikestarterkit.ui.datatypes.Dimensions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package roguelikestarterkit.ui.components.group
package roguelikestarterkit.ui.components

import indigo.*
import roguelikestarterkit.ui.component.*
import roguelikestarterkit.ui.components.common.Anchor
import roguelikestarterkit.ui.components.common.ComponentEntry
import roguelikestarterkit.ui.components.common.ComponentId
import roguelikestarterkit.ui.components.common.ComponentLayout
import roguelikestarterkit.ui.components.common.ContainerLikeFunctions
import roguelikestarterkit.ui.components.common.Overflow
import roguelikestarterkit.ui.components.common.Padding
import roguelikestarterkit.ui.components.datatypes.Anchor
import roguelikestarterkit.ui.components.datatypes.BoundsMode
import roguelikestarterkit.ui.components.datatypes.ComponentEntry
import roguelikestarterkit.ui.components.datatypes.ComponentId
import roguelikestarterkit.ui.components.datatypes.ComponentLayout
import roguelikestarterkit.ui.components.datatypes.ContainerLikeFunctions
import roguelikestarterkit.ui.components.datatypes.FitMode
import roguelikestarterkit.ui.components.datatypes.Overflow
import roguelikestarterkit.ui.components.datatypes.Padding
import roguelikestarterkit.ui.datatypes.*

import scala.annotation.tailrec

/** Describes a fixed arrangement of components, manages their layout, which may include anchored
* components.
*/
final case class ComponentGroup[ReferenceData] private[group] (
final case class ComponentGroup[ReferenceData] private[components] (
boundsMode: BoundsMode,
layout: ComponentLayout,
components: Batch[ComponentEntry[?, ReferenceData]],
Expand Down Expand Up @@ -70,7 +72,7 @@ object ComponentGroup:

def apply[ReferenceData](): ComponentGroup[ReferenceData] =
ComponentGroup(
BoundsMode.default,
roguelikestarterkit.ui.components.datatypes.BoundsMode.default,
ComponentLayout.Horizontal(Padding.zero, Overflow.Wrap),
Batch.empty,
_ => Layer.empty,
Expand All @@ -92,7 +94,7 @@ object ComponentGroup:

def apply[ReferenceData](dimensions: Dimensions): ComponentGroup[ReferenceData] =
ComponentGroup(
BoundsMode.fixed(dimensions),
roguelikestarterkit.ui.components.datatypes.BoundsMode.fixed(dimensions),
ComponentLayout.Horizontal(Padding.zero, Overflow.Wrap),
Batch.empty,
_ => Layer.empty,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package roguelikestarterkit.ui.components.list
package roguelikestarterkit.ui.components

import indigo.*
import roguelikestarterkit.ui.component.*
import roguelikestarterkit.ui.components.common.Anchor
import roguelikestarterkit.ui.components.common.ComponentEntry
import roguelikestarterkit.ui.components.common.ComponentId
import roguelikestarterkit.ui.components.common.ComponentLayout
import roguelikestarterkit.ui.components.common.ContainerLikeFunctions
import roguelikestarterkit.ui.components.common.Padding
import roguelikestarterkit.ui.components.datatypes.Anchor
import roguelikestarterkit.ui.components.datatypes.ComponentEntry
import roguelikestarterkit.ui.components.datatypes.ComponentId
import roguelikestarterkit.ui.components.datatypes.ComponentLayout
import roguelikestarterkit.ui.components.datatypes.ContainerLikeFunctions
import roguelikestarterkit.ui.components.datatypes.Padding
import roguelikestarterkit.ui.datatypes.*
import ultraviolet.syntax.layout

import scala.annotation.tailrec

/** Describes a dynamic list of components, and their realtive layout.
*/
final case class ComponentList[ReferenceData] private (
final case class ComponentList[ReferenceData] private[components] (
content: ReferenceData => Batch[ComponentEntry[?, ReferenceData]],
stateMap: Map[ComponentId, Any],
layout: ComponentLayout,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package roguelikestarterkit.ui.components.group
package roguelikestarterkit.ui.components

import indigo.*
import roguelikestarterkit.ui.component.*
import roguelikestarterkit.ui.components.Button
import roguelikestarterkit.ui.components.DragData
import roguelikestarterkit.ui.components.common.Anchor
import roguelikestarterkit.ui.components.common.ComponentEntry
import roguelikestarterkit.ui.components.common.ComponentId
import roguelikestarterkit.ui.components.common.ComponentLayout
import roguelikestarterkit.ui.components.common.ContainerLikeFunctions
import roguelikestarterkit.ui.components.common.Overflow
import roguelikestarterkit.ui.components.common.Padding
import roguelikestarterkit.ui.components.datatypes.Anchor
import roguelikestarterkit.ui.components.datatypes.BoundsMode
import roguelikestarterkit.ui.components.datatypes.ComponentEntry
import roguelikestarterkit.ui.components.datatypes.ComponentId
import roguelikestarterkit.ui.components.datatypes.ComponentLayout
import roguelikestarterkit.ui.components.datatypes.ContainerLikeFunctions
import roguelikestarterkit.ui.components.datatypes.FitMode
import roguelikestarterkit.ui.components.datatypes.Overflow
import roguelikestarterkit.ui.components.datatypes.Padding
import roguelikestarterkit.ui.components.datatypes.ScrollMode
import roguelikestarterkit.ui.components.datatypes.ScrollOptions
import roguelikestarterkit.ui.datatypes.*
import roguelikestarterkit.ui.shaders.LayerMask

Expand All @@ -20,7 +24,7 @@ import scala.annotation.tailrec
/** Describes a fixed arrangement of components, manages their layout, which may include anchored
* components.
*/
final case class ScrollPane[A, ReferenceData] private[group] (
final case class ScrollPane[A, ReferenceData] private[components] (
bindingKey: BindingKey,
boundsMode: BoundsMode,
dimensions: Dimensions, // The actual cached dimensions of the scroll pane
Expand Down Expand Up @@ -97,14 +101,14 @@ object ScrollPane:
)(using c: Component[A, ReferenceData]): ScrollPane[A, ReferenceData] =
ScrollPane(
bindingKey,
BoundsMode.default,
roguelikestarterkit.ui.components.datatypes.BoundsMode.default,
Dimensions.zero,
Bounds.zero,
0.0,
ScrollPane.makeComponentEntry(content),
setupScrollButton(bindingKey, scrollBar),
_ => Layer.empty,
ScrollOptions.default
roguelikestarterkit.ui.components.datatypes.ScrollOptions.default
)

def apply[A, ReferenceData](
Expand All @@ -124,7 +128,7 @@ object ScrollPane:
ScrollPane.makeComponentEntry(content),
setupScrollButton(bindingKey, scrollBar),
_ => Layer.empty,
ScrollOptions.default
roguelikestarterkit.ui.components.datatypes.ScrollOptions.default
)

def apply[A, ReferenceData](
Expand All @@ -137,14 +141,14 @@ object ScrollPane:
): ScrollPane[A, ReferenceData] =
ScrollPane(
bindingKey,
BoundsMode.fixed(dimensions),
roguelikestarterkit.ui.components.datatypes.BoundsMode.fixed(dimensions),
dimensions,
Bounds.zero,
0.0,
ScrollPane.makeComponentEntry(content),
setupScrollButton(bindingKey, scrollBar),
_ => Layer.empty,
ScrollOptions.default
roguelikestarterkit.ui.components.datatypes.ScrollOptions.default
)

def apply[A, ReferenceData](
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package roguelikestarterkit.ui.components.common
package roguelikestarterkit.ui.components.datatypes

import roguelikestarterkit.ui.datatypes.Bounds
import roguelikestarterkit.ui.datatypes.Coords
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package roguelikestarterkit.ui.components.group
package roguelikestarterkit.ui.components.datatypes

import roguelikestarterkit.ui.datatypes.Bounds
import roguelikestarterkit.ui.datatypes.Coords
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package roguelikestarterkit.ui.components.common
package roguelikestarterkit.ui.components.datatypes

import indigo.*
import roguelikestarterkit.ui.component.Component
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package roguelikestarterkit.ui.components.datatypes

opaque type ComponentId = String

object ComponentId:

def apply(value: String): ComponentId = value
def None: ComponentId = ""

extension (c: ComponentId) def value: String = c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package roguelikestarterkit.ui.components.common
package roguelikestarterkit.ui.components.datatypes

import roguelikestarterkit.ui.datatypes.Dimensions

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package roguelikestarterkit.ui.components.common
package roguelikestarterkit.ui.components.datatypes

import indigo.*
import roguelikestarterkit.ui.datatypes.Bounds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package roguelikestarterkit.ui.components.group
package roguelikestarterkit.ui.components.datatypes

/** Fit mode describes how dynamic bounds decide to expand and shink based on their contents or the
* available space, in one dimension, i.e. width or height. This allows us to say "fill the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package roguelikestarterkit.ui.components.common
package roguelikestarterkit.ui.components.datatypes

/** Overflow describes what to do in the event that a component's layout position is beyond the
* bounds of the `ComponentGroup`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package roguelikestarterkit.ui.components.common
package roguelikestarterkit.ui.components.datatypes

import roguelikestarterkit.ui.datatypes.Bounds

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package roguelikestarterkit.ui.components.group
package roguelikestarterkit.ui.components.datatypes

final case class ScrollOptions(
scrollMode: ScrollMode,
Expand Down
Loading

0 comments on commit 072a88c

Please sign in to comment.