Skip to content

Commit

Permalink
Basic content, not quite right.
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Oct 26, 2023
1 parent 99965ce commit f45826d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
14 changes: 10 additions & 4 deletions paint/src/main/scala/roguepaint/PaintScene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ object PaintScene extends Scene[Size, Model, ViewModel]:
Outcome(
SceneUpdateFragment(
Layer(
Batch(viewModel.bg) ++
tiles.clones
Batch(viewModel.bg)
)
)
.addCloneBlanks(tiles.blanks)
) |+| tiles
)

final case class PaintModel(windowManager: WindowManagerModel)
Expand Down Expand Up @@ -110,6 +108,14 @@ object PaintModel:
.isCloseable
.isDraggable
.focus
.withContents { bounds =>
SceneUpdateFragment(
Shape.Circle(
Circle(bounds.center, Math.min(bounds.size.width, bounds.size.height) / 2),
Fill.Color(RGBA.Blue)
)
)
}
)
)

Expand Down
18 changes: 14 additions & 4 deletions paint/src/main/scala/roguepaint/components/Window.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ object Window:
Batch(WindowManagerEvent.Close(model.id))
else Batch.empty
val focus =
if actionsAllowed && !model.static && model.bounds.resize(model.bounds.size - 1).contains(gridPos) then
Batch(WindowManagerEvent.GiveFocusAt(gridPos))
if actionsAllowed && !model.static && model.bounds
.resize(model.bounds.size - 1)
.contains(gridPos)
then Batch(WindowManagerEvent.GiveFocusAt(gridPos))
else Batch.empty

Outcome(viewModel)
Expand Down Expand Up @@ -156,8 +158,11 @@ object Window:
case _ =>
Outcome(viewModel)

def present(viewModel: WindowViewModel): TerminalClones =
viewModel.terminalClones
def present(model: WindowModel, viewModel: WindowViewModel): SceneUpdateFragment =
SceneUpdateFragment(
viewModel.terminalClones.clones
).addCloneBlanks(viewModel.terminalClones.blanks) |+|
model.contents(model.bounds.resize(model.bounds.size * charSize).moveTo(model.bounds.position * charSize))

opaque type WindowId = String
object WindowId:
Expand All @@ -168,6 +173,7 @@ final case class WindowModel(
id: WindowId,
bounds: Rectangle,
title: Option[String],
contents: Rectangle => SceneUpdateFragment,
draggable: Boolean,
resizable: Boolean,
closeable: Boolean,
Expand Down Expand Up @@ -206,6 +212,9 @@ final case class WindowModel(
def withTitle(value: String): WindowModel =
this.copy(title = Option(value))

def withContents(f: Rectangle => SceneUpdateFragment): WindowModel =
this.copy(contents = f)

def withDraggable(value: Boolean): WindowModel =
this.copy(draggable = value)
def isDraggable: WindowModel =
Expand Down Expand Up @@ -251,6 +260,7 @@ object WindowModel:
id,
Rectangle(Point.zero, Size.zero),
None,
(r: Rectangle) => SceneUpdateFragment.empty,
false,
false,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object WindowManager:
frameContext: FrameContext[Size],
model: WindowManagerModel,
viewModel: WindowManagerViewModel
): TerminalClones =
): SceneUpdateFragment =
model.windows
.flatMap { m =>
viewModel.windows.find(_.id == m.id) match
Expand All @@ -51,9 +51,9 @@ object WindowManager:
Batch.empty

case Some(vm) =>
Batch(Window.present(vm))
Batch(Window.present(m, vm))
}
.foldLeft(TerminalClones.empty)(_ |+| _)
.foldLeft(SceneUpdateFragment.empty)(_ |+| _)

extension (tc: TerminalClones)
def |+|(other: TerminalClones): TerminalClones =
Expand Down

0 comments on commit f45826d

Please sign in to comment.