Move render_layout to layout module
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import gleam/dict
|
import gleam/dict
|
||||||
|
import gleam/list
|
||||||
|
|
||||||
|
import musicplayer/ui/internal
|
||||||
|
|
||||||
pub type Layout {
|
pub type Layout {
|
||||||
Layout(width: Int, height: Int, nodes: dict.Dict(Section, Node))
|
Layout(width: Int, height: Int, nodes: dict.Dict(Section, Node))
|
||||||
@@ -56,3 +59,14 @@ pub fn update_section(
|
|||||||
pub fn update_dimensions(layout: Layout, width: Int, height: Int) -> Layout {
|
pub fn update_dimensions(layout: Layout, width: Int, height: Int) -> Layout {
|
||||||
Layout(..layout, width:, height:)
|
Layout(..layout, width:, height:)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn render(layout: Layout, from: Section) -> Nil {
|
||||||
|
case dict.get(layout.nodes, from) {
|
||||||
|
Error(_) -> Nil
|
||||||
|
Ok(node) -> {
|
||||||
|
list.each(node.children, fn(child) { render(layout, child) })
|
||||||
|
|
||||||
|
internal.print_at(node.content, node.x, node.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import gleam/dict
|
|
||||||
import gleam/erlang/process.{type Subject}
|
import gleam/erlang/process.{type Subject}
|
||||||
import gleam/int
|
import gleam/int
|
||||||
import gleam/list
|
import gleam/list
|
||||||
@@ -8,7 +7,7 @@ import gleam/string
|
|||||||
import musicplayer/logging/logging
|
import musicplayer/logging/logging
|
||||||
import musicplayer/ui/control.{type Control}
|
import musicplayer/ui/control.{type Control}
|
||||||
import musicplayer/ui/internal
|
import musicplayer/ui/internal
|
||||||
import musicplayer/ui/layout.{type Layout, type Section}
|
import musicplayer/ui/layout.{type Layout}
|
||||||
|
|
||||||
pub type State(redraw, content) {
|
pub type State(redraw, content) {
|
||||||
State(redraw: Subject(Layout), layout: Layout)
|
State(redraw: Subject(Layout), layout: Layout)
|
||||||
@@ -92,8 +91,8 @@ fn handle_message(
|
|||||||
fn redraw_on_update_loop(redraw: Subject(Layout)) -> Nil {
|
fn redraw_on_update_loop(redraw: Subject(Layout)) -> Nil {
|
||||||
let layout = process.receive_forever(redraw)
|
let layout = process.receive_forever(redraw)
|
||||||
|
|
||||||
render_layout(layout, layout.Root)
|
|
||||||
internal.clear_screen()
|
internal.clear_screen()
|
||||||
|
layout.render(layout, layout.Root)
|
||||||
|
|
||||||
redraw_on_update_loop(redraw)
|
redraw_on_update_loop(redraw)
|
||||||
}
|
}
|
||||||
@@ -109,13 +108,3 @@ fn update_dimensions_on_interval(ui: Subject(Control), interval_ms: Int) {
|
|||||||
process.sleep(interval_ms)
|
process.sleep(interval_ms)
|
||||||
update_dimensions_on_interval(ui, interval_ms)
|
update_dimensions_on_interval(ui, interval_ms)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_layout(layout: Layout, from: Section) -> Nil {
|
|
||||||
case dict.get(layout.nodes, from) {
|
|
||||||
Error(_) -> Nil
|
|
||||||
Ok(node) -> {
|
|
||||||
list.each(node.children, fn(child) { render_layout(layout, child) })
|
|
||||||
internal.print_at(node.content, node.x, node.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user