wip set view

This commit is contained in:
Alexander Heldt
2025-12-25 17:51:32 +01:00
parent 0ef94d7c89
commit a3c5c203f1
3 changed files with 11 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import musicplayer/ui/layout.{type Section}
pub type Control {
UpdateDimensions(columns: Int, rows: Int)
UpdateState(section: Section, content: String)
SetView(view_idx: layout.ViewIdx)
Exit(reply_to: Subject(Nil))
}

View File

@@ -123,6 +123,9 @@ pub fn update_dimensions(layout: Layout, columns: Int, rows: Int) -> Layout {
Layout(..layout, columns:, rows:)
}
pub fn set_view(layout: Layout, view_idx: ViewIdx) -> Layout {
Layout(..layout, current_view: view_idx)
}
pub fn render(layout: Layout) -> Nil {
let context =
@@ -142,6 +145,7 @@ pub fn render(layout: Layout) -> Nil {
render_loop(
view,
context,
// TODO extract to function `view_index`
Section(string.append("view_", string.inspect(layout.current_view))),
buffer,
)

View File

@@ -120,6 +120,12 @@ fn handle_message(
process.send(reply_to, Nil)
actor.stop()
}
control.SetView(view_idx) -> {
let layout = layout.set_view(state.layout, view_idx)
actor.send(state.redraw, layout)
actor.continue(State(..state, layout:))
}
}
}