Skip to content

Commit

Permalink
Might be getting somewhere...
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed May 31, 2024
1 parent 1ece5a4 commit e3aac0e
Show file tree
Hide file tree
Showing 19 changed files with 1,172 additions and 1,079 deletions.
86 changes: 45 additions & 41 deletions demo/src/main/scala/demo/ColourWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,36 @@ object ColourWindow:
windowId,
charSheet,
ColorPalette(
ComponentGroup(Bounds(0, 0, 23, 23))
.withLayout(ComponentLayout.Vertical())
.inheritBounds
.add(
ComponentGroup(Bounds(0, 0, 23, 10))
.withLayout(ComponentLayout.Horizontal(Overflow.Wrap))
.offsetSize(0, -4)
.add(
// Custom rendered buttons for the swatches
outrunner16.colors.map { rgba =>
Button(Bounds(0, 0, 3, 3))(presentSwatch(charSheet, rgba, None))
// .onClick(<Emit some event...>)
.presentOver(presentSwatch(charSheet, rgba, Option(RGBA.White)))
.presentDown(presentSwatch(charSheet, rgba, Option(RGBA.Black)))
}
)
)
.add(
// Default button renderer
Button(
"Load palette",
Button.Theme(
charSheet,
RGBA.Silver -> RGBA.Black,
RGBA.White -> RGBA.Black,
RGBA.Black -> RGBA.White,
hasBorder = true
)
)
)
// ComponentGroup(Bounds(0, 0, 23, 23))
// .withLayout(ComponentLayout.Vertical())
// .inheritBounds
// // .add(
// // ComponentGroup(Bounds(0, 0, 23, 10))
// // .withLayout(ComponentLayout.Horizontal(Overflow.Wrap))
// // .offsetSize(0, -4)
// // .add(
// // // Custom rendered buttons for the swatches
// // outrunner16.colors.map { rgba =>
// // Button(Bounds(0, 0, 3, 3))(presentSwatch(charSheet, rgba, None))
// // // .onClick(<Emit some event...>)
// // .presentOver(presentSwatch(charSheet, rgba, Option(RGBA.White)))
// // .presentDown(presentSwatch(charSheet, rgba, Option(RGBA.Black)))
// // }
// // )
// // )
// .add(
// // Default button renderer
// Button(
// "Load palette",
// Button.Theme(
// charSheet,
// RGBA.Silver -> RGBA.Black,
// RGBA.White -> RGBA.Black,
// RGBA.Black -> RGBA.White,
// hasBorder = true
// )
// )
// )
)
)
.withTitle("Colour Palette")
Expand Down Expand Up @@ -110,7 +110,7 @@ object ColourWindow:
)
)

final case class ColorPalette(componentGroup: ComponentGroup[Unit])
final case class ColorPalette(/*componentGroup: ComponentGroup[Unit]*/)
object ColorPalette:

given WindowContent[ColorPalette, Unit] with
Expand All @@ -120,22 +120,26 @@ object ColorPalette:
model: ColorPalette
): GlobalEvent => Outcome[ColorPalette] =
case e =>
model.componentGroup.update(context)(e).map { c =>
model.copy(componentGroup = c)
}
Outcome(model)
// model.componentGroup.update(context)(e).map { c =>
// model.copy(componentGroup = c)
// }

def present(
context: UiContext[Unit],
model: ColorPalette
): Outcome[Layer] =
model.componentGroup.present(context).map(_.toLayer)
// model.componentGroup.present(context).map(_.toLayer)
Outcome(Layer.empty)

def cascade(model: ColorPalette, newBounds: Bounds): ColorPalette =
model.copy(
componentGroup = model.componentGroup.cascade(newBounds)
)
model
// .copy(
// componentGroup = model.componentGroup.cascade(newBounds)
// )

def refresh(model: ColorPalette): ColorPalette =
model.copy(
componentGroup = model.componentGroup.reflow
)
model
// .copy(
// componentGroup = model.componentGroup.reflow
// )
173 changes: 87 additions & 86 deletions demo/src/main/scala/demo/ComponentsWindow.scala
Original file line number Diff line number Diff line change
@@ -1,93 +1,94 @@
package demo
// package demo

import indigo.*
import roguelikestarterkit.*
// import indigo.*
// import roguelikestarterkit.*

object ComponentsWindow:
// object ComponentsWindow:

private val graphic = Graphic(0, 0, TerminalMaterial(AssetName(""), RGBA.White, RGBA.Black))
// private val graphic = Graphic(0, 0, TerminalMaterial(AssetName(""), RGBA.White, RGBA.Black))

val windowId: WindowId = WindowId("ComponentsWindow")
// val windowId: WindowId = WindowId("ComponentsWindow")

def window(
charSheet: CharSheet
): WindowModel[ComponentGroup[Int], Int] =
WindowModel(
windowId,
charSheet,
ComponentGroup(Bounds(0, 0, 23, 23))
.withLayout(ComponentLayout.Vertical(Padding(0, 0, 1)))
.inheritBounds
.add(
Button(
"Hello!",
Button.Theme(
charSheet,
RGBA.Silver -> RGBA.Black,
RGBA.White -> RGBA.Black,
RGBA.Black -> RGBA.White,
hasBorder = true
)
)
)
.add(
Button(
"World!",
Button.Theme(
charSheet,
RGBA.Silver -> RGBA.Black,
RGBA.Green -> RGBA.Black,
RGBA.Black -> RGBA.Yellow,
hasBorder = false
)
),
Button("Default!", Button.Theme(charSheet))
)
.add {
Button(
(i: Int) => "Count" + (if i > 0 then s": $i" else ""),
Button.Theme(charSheet).addBorder
)
}
.add(
Button[Int](Bounds(0, 0, 5, 2)) { case (coords, bounds, _) =>
Outcome(
ComponentFragment(
Shape.Box(
bounds.toScreenSpace(charSheet.size).moveTo(coords.toScreenSpace(charSheet.size)),
Fill.LinearGradient(Point.zero, RGBA.Cyan, Point(50, 0), RGBA.Magenta)
)
)
)
}
)
.add(
Label("Custom rendered label") { case (offset, label, dimensions) =>
val size = dimensions.unsafeToSize
// def window(
// charSheet: CharSheet
// ): WindowModel[ComponentGroup[Int], Int] =
// WindowModel(
// windowId,
// charSheet,
// // ComponentGroup(Bounds(0, 0, 23, 23))
// // .withLayout(ComponentLayout.Vertical(Padding(0, 0, 1)))
// // .inheritBounds
// // .add(
// // Button(
// // "Hello!",
// // Button.Theme(
// // charSheet,
// // RGBA.Silver -> RGBA.Black,
// // RGBA.White -> RGBA.Black,
// // RGBA.Black -> RGBA.White,
// // hasBorder = true
// // )
// // )
// // )
// // .add(
// // Button(
// // "World!",
// // Button.Theme(
// // charSheet,
// // RGBA.Silver -> RGBA.Black,
// // RGBA.Green -> RGBA.Black,
// // RGBA.Black -> RGBA.Yellow,
// // hasBorder = false
// // )
// // ),
// // Button("Default!", Button.Theme(charSheet))
// // )
// // .add {
// // Button(
// // (i: Int) => "Count" + (if i > 0 then s": $i" else ""),
// // Button.Theme(charSheet).addBorder
// // )
// // }
// // .add(
// // Button[Int](Bounds(0, 0, 5, 2)) { case (coords, bounds, _) =>
// // Outcome(
// // ComponentFragment(
// // Shape.Box(
// // bounds.toScreenSpace(charSheet.size).moveTo(coords.toScreenSpace(charSheet.size)),
// // Fill.LinearGradient(Point.zero, RGBA.Cyan, Point(50, 0), RGBA.Magenta)
// // )
// // )
// // )
// // }
// // )
// // .add(
// // Label[Int]("Custom rendered label", (_, t) => Bounds(0, 0, t.length, 1)) {
// // case (offset, label, dimensions) =>
// // val size = dimensions.unsafeToSize

val terminal =
RogueTerminalEmulator(size)
.putLine(Point.zero, label, RGBA.Red, RGBA.Zero)
.toCloneTiles(
CloneId("label"),
offset.toScreenSpace(charSheet.size),
charSheet.charCrops
) { case (fg, bg) =>
graphic.withMaterial(TerminalMaterial(charSheet.assetName, fg, bg))
}
// // val terminal =
// // RogueTerminalEmulator(size)
// // .putLine(Point.zero, label, RGBA.Red, RGBA.Zero)
// // .toCloneTiles(
// // CloneId("label"),
// // offset.toScreenSpace(charSheet.size),
// // charSheet.charCrops
// // ) { case (fg, bg) =>
// // graphic.withMaterial(TerminalMaterial(charSheet.assetName, fg, bg))
// // }

Outcome(ComponentFragment(terminal))
}
)
.add(
Label("Terminal rendered label", Label.Theme(charSheet, RGBA.Magenta, RGBA.Cyan)),
Label("Default theme", Label.Theme(charSheet)),
Label((count: Int) => "Mouse over windows: " + count, Label.Theme(charSheet))
)
)
.withTitle("Components example")
.moveTo(0, 0)
.resizeTo(25, 25)
.isDraggable
.isResizable
.isCloseable
// // Outcome(ComponentFragment(terminal))
// // }
// // )
// // .add(
// // Label("Terminal rendered label", Label.Theme(charSheet, RGBA.Magenta, RGBA.Cyan)),
// // Label("Default theme", Label.Theme(charSheet)),
// // Label((count: Int) => "Mouse over windows: " + count, Label.Theme(charSheet))
// // )
// )
// .withTitle("Components example")
// .moveTo(0, 0)
// .resizeTo(25, 25)
// .isDraggable
// .isResizable
// .isCloseable
Loading

0 comments on commit e3aac0e

Please sign in to comment.