Skip to content

Commit

Permalink
Component based UI system
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Jan 5, 2025
1 parent bf76986 commit 70ae794
Show file tree
Hide file tree
Showing 50 changed files with 5,354 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package indigoextras.ui.component

import indigo.*
import indigoextras.ui.datatypes.Bounds
import indigoextras.ui.datatypes.Dimensions
import indigoextras.ui.datatypes.UIContext

/** A typeclass that confirms that some type `A` can be used as a `Component` provides the necessary operations for that
* type to act as a component.
*/
trait Component[A, ReferenceData]:

/** The position and size of the component
*/
def bounds(reference: ReferenceData, model: A): Bounds

/** Update this componenets model.
*/
def updateModel(
context: UIContext[ReferenceData],
model: A
): GlobalEvent => Outcome[A]

/** Produce a renderable output for this component, based on the component's model.
*/
def present(
context: UIContext[ReferenceData],
model: A
): Outcome[Layer]

/** Used internally to instruct the component that the layout has changed in some way, and that it should
* reflow/refresh it's contents - whatever that means in the context of this component type.
*/
def refresh(reference: ReferenceData, model: A, parentDimensions: Dimensions): A

object Component:

given [ReferenceData]: Component[Unit, ReferenceData] =
new Component[Unit, ReferenceData]:
def bounds(reference: ReferenceData, model: Unit): Bounds =
Bounds.zero

def updateModel(
context: UIContext[ReferenceData],
model: Unit
): GlobalEvent => Outcome[Unit] =
_ => Outcome(model)

def present(
context: UIContext[ReferenceData],
model: Unit
): Outcome[Layer] =
Outcome(Layer.empty)

def refresh(reference: ReferenceData, model: Unit, parentDimensions: Dimensions): Unit =
()
Loading

0 comments on commit 70ae794

Please sign in to comment.