wip set view
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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:))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user