Skip to content

Commit

Permalink
Update scaladoc
Browse files Browse the repository at this point in the history
  • Loading branch information
JD557 committed May 18, 2024
1 parent 4d65cc5 commit bc55ce0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/shared/src/main/scala/eu/joaocosta/interim/Component.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package eu.joaocosta.interim

/** A Component is something that can be shown in the UI.
*
* It uses the current input state and UI context to draw itself and returns the current value.
*/
type Component[+T] = (inputState: InputState.Historical, uiContext: UiContext) ?=> T

/** A Component that returns a value.
*/
trait ComponentWithValue[T]:
def render(area: Rect, value: Ref[T]): Component[Unit]

Expand All @@ -16,6 +22,10 @@ trait ComponentWithValue[T]:
case x: T => applyValue(area, x)
case x: Ref[T] => applyRef(area, x)

/** A Component that returns a value.
*
* The area can be computed dynamically based on a layout allocator.
*/
trait DynamicComponentWithValue[T] extends ComponentWithValue[T]:
def allocateArea(using allocator: LayoutAllocator.AreaAllocator): Rect

Expand All @@ -25,13 +35,19 @@ trait DynamicComponentWithValue[T] extends ComponentWithValue[T]:
inline def apply(value: T | Ref[T])(using allocator: LayoutAllocator.AreaAllocator): Component[T] =
apply(allocateArea, value)

/** A Component that computes its value based on a body.
*/
trait ComponentWithBody[I, F[_]]:
def render[T](area: Rect, body: I => T): Component[F[T]]

def apply[T](area: Rect)(body: I => T): Component[F[T]] = render(area, body)

def apply[T](area: Rect)(body: => T)(using ev: I =:= Unit): Component[F[T]] = render(area, _ => body)

/** A Component that computes its value based on a body.
*
* The area can be computed dynamically based on a layout allocator.
*/
trait DynamicComponentWithBody[I, F[_]] extends ComponentWithBody[I, F]:
def allocateArea(using allocator: LayoutAllocator.AreaAllocator): Rect

Expand Down
3 changes: 3 additions & 0 deletions core/shared/src/main/scala/eu/joaocosta/interim/Panel.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package eu.joaocosta.interim

/*
* Panels are a mix of a component and a layout. They perform rendering operations, but also provide a draw area.
*/
trait Panel[I, F[_]]:
def render[T](area: Ref[PanelState[Rect]], body: I => T): Component[F[T]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ object TextLayout:
)
layout(textOp.text, 0, Nil).filter(char => (char.area & textOp.area) == char.area)

/** Computes the area that some text will occupy
*
* @param boundingArea area where the text can be inserted
* @param text string of text
* @param font font to use
*/
def computeArea(
boundingArea: Rect,
text: String,
Expand Down

0 comments on commit bc55ce0

Please sign in to comment.