Move render_layout to layout module

This commit is contained in:
Alexander Heldt
2025-11-29 19:02:33 +01:00
parent 5e8ba9a4b0
commit e524a865fe
2 changed files with 16 additions and 13 deletions

View File

@@ -1,4 +1,7 @@
import gleam/dict
import gleam/list
import musicplayer/ui/internal
pub type Layout {
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 {
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)
}
}
}

View File

@@ -1,4 +1,3 @@
import gleam/dict
import gleam/erlang/process.{type Subject}
import gleam/int
import gleam/list
@@ -9,7 +8,7 @@ import musicplayer/logging/control as logging_control
import musicplayer/logging/logging
import musicplayer/ui/control.{type Control}
import musicplayer/ui/internal
import musicplayer/ui/layout.{type Layout, type Section}
import musicplayer/ui/layout.{type Layout}
pub type State(redraw, content) {
State(
@@ -99,8 +98,8 @@ fn handle_message(
fn redraw_on_update_loop(redraw: Subject(Layout)) -> Nil {
let layout = process.receive_forever(redraw)
render_layout(layout, layout.Root)
internal.clear_screen()
layout.render(layout, layout.Root)
redraw_on_update_loop(redraw)
}
@@ -120,13 +119,3 @@ fn update_dimensions_on_interval(
process.sleep(interval_ms)
update_dimensions_on_interval(logger, 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)
}
}
}