Skip to content

Commit

Permalink
ComponentGroup reworked, tests failing.
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Jun 2, 2024
1 parent b513113 commit 504cd45
Show file tree
Hide file tree
Showing 15 changed files with 814 additions and 821 deletions.
2 changes: 1 addition & 1 deletion demo/src/main/scala/demo/ColourWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ object ColorPalette:
// componentGroup = model.componentGroup.cascade(newBounds)
// )

def refresh(model: ColorPalette): ColorPalette =
def refresh(reference: Unit, model: ColorPalette): ColorPalette =
model
// .copy(
// componentGroup = model.componentGroup.reflow
Expand Down
112 changes: 54 additions & 58 deletions demo/src/main/scala/demo/ComponentsWindow2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,64 @@ object ComponentsWindow2:

def window(
charSheet: CharSheet
): WindowModel[ComponentList[Int], Int] =
): WindowModel[ComponentGroup[Int], Int] =
WindowModel(
windowId,
charSheet,
ComponentList(Bounds(0, 0, 20, 3)) { (count: Int) =>
Batch(Label[Int]("How many windows: ", Label.Theme(charSheet))) ++
Batch.fill(count)(Label("x", Label.Theme(charSheet)))
}
.add((count: Int) =>
Batch.fill(count)(
Button[Int]("Button", Button.Theme(charSheet)).onClick(Log("count: " + count))
)
:+ Button[Int]("test", Button.Theme(charSheet)).onClick(Log("test"))
ComponentGroup()
.withLayout(ComponentLayout.Vertical(Padding(0, 0, 1, 0)))
.add(
ComponentGroup()
.withLayout(ComponentLayout.Horizontal(Padding(0, 1, 0, 0)))
.add(
Label("label 1", Label.Theme(charSheet)),
Label("label 2", Label.Theme(charSheet)),
Label("label 3", Label.Theme(charSheet))
)
)
// .add(
// ComponentGroup()
// .withLayout(ComponentLayout.Horizontal(Padding(0, 1, 0, 0)))
// .add(
// Batch(
// "History" -> Batch(),
// "Controls" -> Batch(),
// "Quit" -> Batch()
// ).map { case (label, clickEvents) =>
// Button(
// label,
// Button.Theme(charSheet)
// ).onClick(clickEvents)
// }
// )
// )
// .add(
// ComponentList(Bounds(0, 0, 20, 3)) { (count: Int) =>
// Batch(Label[Int]("How many windows: ", Label.Theme(charSheet))) ++
// Batch.fill(count)(Label("x", Label.Theme(charSheet)))
// }
// .withLayout(ComponentLayout.Vertical())
// )
// .add(
// ComponentList(Bounds(0, 0, 20, 3)) { (count: Int) =>
// Batch(Label[Int]("How many windows: ", Label.Theme(charSheet))) ++
// Batch.fill(count)(Label("x", Label.Theme(charSheet)))
// }
// .add((count: Int) =>
// Batch.fill(count)(
// Button[Int]("Button", Button.Theme(charSheet)).onClick(Log("count: " + count))
// )
// :+ Button[Int]("test", Button.Theme(charSheet)).onClick(Log("test"))
// )
// .add((i: Int) => TextArea[Int]("abc.\nde,f\n0123456! " + i, TextArea.Theme(charSheet)))
// .withLayout(ComponentLayout.Vertical(Padding.zero))
// )
// .add(
// Input(20, Input.Theme(charSheet))
// )
.add(
TextArea("abc.\nde,f\n0123456!", TextArea.Theme(charSheet))
)
.add((i: Int) => TextArea[Int]("abc.\nde,f\n0123456! " + i, TextArea.Theme(charSheet)))
.withLayout(ComponentLayout.Vertical(Padding.zero))
// ComponentGroup()
// .withLayout(ComponentLayout.Vertical(Padding(0, 0, 1, 0)))
// .add(
// ComponentGroup()
// .withLayout(ComponentLayout.Horizontal(Padding(0, 1, 0, 0)))
// .add(
// Label("label 1", Label.Theme(charSheet)),
// Label("label 2", Label.Theme(charSheet)),
// Label("label 3", Label.Theme(charSheet))
// )
// )
// .add(
// ComponentGroup()
// .withLayout(ComponentLayout.Horizontal(Padding(0, 1, 0, 0)))
// .add(
// Batch(
// "History" -> Batch(),
// "Controls" -> Batch(),
// "Quit" -> Batch()
// ).map { case (label, clickEvents) =>
// Button(
// label,
// Button.Theme(charSheet)
// ).onClick(clickEvents)
// }
// )
// )
// .add(
// ComponentList(Bounds(0, 0, 20, 3)) { (count: Int) =>
// Batch(Label[Int]("How many windows: ", Label.Theme(charSheet))) ++
// Batch.fill(count)(Label("x", Label.Theme(charSheet)))
// }
// .withLayout(ComponentLayout.Vertical())
// )
// .add(
// ComponentList(Bounds(0, 0, 20, 3)) { (count: Int) =>
// Batch.fill(count)(Button("y", Button.Theme(charSheet)))
// }
// .withLayout(ComponentLayout.Vertical())
// )
// .add(
// Input(20, Input.Theme(charSheet))
// )
// .add(
// TextArea("abc.\nde,f\n0123456!", TextArea.Theme(charSheet))
// )
)
.withTitle("More component examples")
.moveTo(2, 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trait Component[A, ReferenceData]:
/** Used internally to instruct the component that the layout has changed in some way, and that it
* should reflow it's contents - whatever that means in the context of this component type.
*/
def reflow(model: A): A
def reflow(reference: ReferenceData, model: A): A

/** Informs the Component that something about its parent has changed in case it needs to take
* action. Currently the only cascaded change is the bounds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait StatelessComponent[A, ReferenceData] extends Component[A, ReferenceData]:
model: A
): Outcome[ComponentFragment]

def reflow(model: A): A = model
def reflow(reference: ReferenceData, model: A): A = model
def cascade(model: A, parentBounds: Bounds): A = model
def updateModel(context: UiContext[ReferenceData], model: A): GlobalEvent => Outcome[A] =
case e => Outcome(model)
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,6 @@ final case class Input(
def withLoseFocusActions(actions: => Batch[GlobalEvent]): Input =
this.copy(onLoseFocus = () => actions)

// Delegates, for convenience.

def update[StartupData, ContextData](
context: UiContext[?]
): GlobalEvent => Outcome[Input] =
summon[Component[Input, ?]].updateModel(context, this)

def present[StartupData, ContextData](
context: UiContext[?]
): Outcome[ComponentFragment] =
summon[Component[Input, ?]].present(context, this)

def reflow: Input =
summon[Component[Input, ?]].reflow(this)

def cascade(parentBounds: Bounds): Input =
summon[Component[Input, ?]].cascade(this, parentBounds)

object Input:

/** Minimal input constructor with custom rendering function
Expand Down Expand Up @@ -345,7 +327,7 @@ object Input:
context.running
)

def reflow(model: Input): Input =
def reflow(reference: ReferenceData, model: Input): Input =
model

def cascade(model: Input, parentBounds: Bounds): Input =
Expand Down
Loading

0 comments on commit 504cd45

Please sign in to comment.