working-but-not-columnwise
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
import gleam/dict
|
import gleam/dict
|
||||||
import gleam/erlang/process.{type Subject}
|
import gleam/float
|
||||||
import gleam/int
|
import gleam/int
|
||||||
import gleam/list
|
import gleam/list
|
||||||
import gleam/string
|
import gleam/string
|
||||||
|
|
||||||
import musicplayer/logging/control as logging_control
|
|
||||||
import musicplayer/logging/logging
|
import musicplayer/logging/logging
|
||||||
import musicplayer/ui/internal
|
import musicplayer/ui/internal
|
||||||
|
|
||||||
@@ -23,8 +22,6 @@ pub type Section {
|
|||||||
pub type Node {
|
pub type Node {
|
||||||
Node(
|
Node(
|
||||||
content: String,
|
content: String,
|
||||||
x: Int,
|
|
||||||
y: Int,
|
|
||||||
width_percent: Int,
|
width_percent: Int,
|
||||||
height_percent: Int,
|
height_percent: Int,
|
||||||
children: List(Section),
|
children: List(Section),
|
||||||
@@ -36,18 +33,11 @@ pub fn new() -> Layout {
|
|||||||
dict.from_list([
|
dict.from_list([
|
||||||
#(
|
#(
|
||||||
Root,
|
Root,
|
||||||
Node(
|
Node(content: "", width_percent: 100, height_percent: 100, children: [
|
||||||
content: "",
|
// Header,
|
||||||
x: 1,
|
// Search,
|
||||||
y: 1,
|
PlaybackTime,
|
||||||
width_percent: 100,
|
]),
|
||||||
height_percent: 100,
|
|
||||||
children: [
|
|
||||||
// Header,
|
|
||||||
// Search,
|
|
||||||
PlaybackTime,
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
// #(
|
// #(
|
||||||
// Header,
|
// Header,
|
||||||
@@ -58,9 +48,7 @@ pub fn new() -> Layout {
|
|||||||
PlaybackTime,
|
PlaybackTime,
|
||||||
Node(
|
Node(
|
||||||
content: "00:00",
|
content: "00:00",
|
||||||
x: 1,
|
width_percent: 50,
|
||||||
y: 2,
|
|
||||||
width_percent: 100,
|
|
||||||
height_percent: 100,
|
height_percent: 100,
|
||||||
children: [],
|
children: [],
|
||||||
),
|
),
|
||||||
@@ -93,39 +81,86 @@ pub fn update_dimensions(layout: Layout, width: Int, height: Int) -> Layout {
|
|||||||
Layout(..layout, width:, height:)
|
Layout(..layout, width:, height:)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(logger: Subject(logging_control.Control), layout: Layout) -> Nil {
|
pub fn render(layout: Layout) -> Nil {
|
||||||
internal.clear_screen()
|
internal.clear_screen()
|
||||||
[layout.width, layout.height]
|
[layout.width, layout.height]
|
||||||
|> list.map(int.to_string)
|
|> list.map(int.to_string)
|
||||||
|> string.join(" ")
|
|> string.join(" ")
|
||||||
|> string.append("layout - render: ", _)
|
|> string.append("layout - render: ", _)
|
||||||
|> logging.log(logger, _)
|
|> logging.log
|
||||||
|
|
||||||
render_loop(layout, layout.width, layout.height, Root)
|
let container_width = int.to_float(layout.width)
|
||||||
|
let container_height = int.to_float(layout.height)
|
||||||
|
let container_top_left_x = 1
|
||||||
|
let container_top_left_y = 1
|
||||||
|
|
||||||
|
render_loop(
|
||||||
|
layout,
|
||||||
|
container_width,
|
||||||
|
container_height,
|
||||||
|
container_top_left_x,
|
||||||
|
container_top_left_y,
|
||||||
|
Root,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_loop(
|
pub fn render_loop(
|
||||||
layout: Layout,
|
layout: Layout,
|
||||||
container_width: Int,
|
container_width: Float,
|
||||||
container_height: Int,
|
container_height: Float,
|
||||||
|
container_top_left_x: Int,
|
||||||
|
container_top_left_y: Int,
|
||||||
from: Section,
|
from: Section,
|
||||||
) -> Nil {
|
) -> Nil {
|
||||||
|
let margin = 2.0
|
||||||
|
|
||||||
case dict.get(layout.nodes, from) {
|
case dict.get(layout.nodes, from) {
|
||||||
Error(_) -> Nil
|
Error(_) -> Nil
|
||||||
Ok(node) -> {
|
Ok(node) -> {
|
||||||
list.each(node.children, fn(child) {
|
list.each(node.children, fn(child) {
|
||||||
let cw = container_width * { node.width_percent / 100 }
|
let cw =
|
||||||
let ch = container_height * { node.height_percent / 100 }
|
container_width
|
||||||
|
*. { int.to_float(node.width_percent) /. 100.0 }
|
||||||
|
-. margin
|
||||||
|
|> float.floor
|
||||||
|
|
||||||
render_loop(layout, cw, ch, child)
|
let ch =
|
||||||
|
container_height
|
||||||
|
*. { int.to_float(node.height_percent) /. 100.0 }
|
||||||
|
-. margin
|
||||||
|
|> float.floor
|
||||||
|
|
||||||
|
let cx = container_top_left_x + 1
|
||||||
|
let cy = container_top_left_y + 1
|
||||||
|
|
||||||
|
render_loop(layout, cw, ch, cx, cy, child)
|
||||||
})
|
})
|
||||||
|
|
||||||
let width = container_width * { node.width_percent / 100 }
|
logging.log("section: " <> string.inspect(from))
|
||||||
let height = container_height * { node.height_percent / 100 }
|
logging.log("container width: " <> float.to_string(container_width))
|
||||||
|
logging.log("container height: " <> float.to_string(container_height))
|
||||||
|
|
||||||
draw_box(node.x, node.y, width, height)
|
let width =
|
||||||
|
container_width *. { int.to_float(node.width_percent) /. 100.0 }
|
||||||
|
|> float.floor
|
||||||
|
|> float.truncate
|
||||||
|
|
||||||
internal.print_at(node.content, node.x, node.y)
|
let height =
|
||||||
|
container_height *. { int.to_float(node.height_percent) /. 100.0 }
|
||||||
|
|> float.floor
|
||||||
|
|> float.truncate
|
||||||
|
|
||||||
|
logging.log("width: " <> int.to_string(width))
|
||||||
|
logging.log("height: " <> int.to_string(height))
|
||||||
|
|
||||||
|
let cx = container_top_left_x
|
||||||
|
let cy = container_top_left_y
|
||||||
|
logging.log("cx: " <> int.to_string(cx))
|
||||||
|
logging.log("cy: " <> int.to_string(cy))
|
||||||
|
|
||||||
|
draw_box(cx, cy, width, height)
|
||||||
|
// Box heading
|
||||||
|
internal.print_at(node.content, cx, cy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ pub fn new() -> Result(Subject(Control), String) {
|
|||||||
internal.clear_screen()
|
internal.clear_screen()
|
||||||
internal.hide_cursor()
|
internal.hide_cursor()
|
||||||
|
|
||||||
redraw_loop(logger, redraw)
|
redraw_loop(redraw)
|
||||||
})
|
})
|
||||||
|
|
||||||
Ok(ui)
|
Ok(ui)
|
||||||
@@ -85,14 +85,11 @@ fn handle_message(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn redraw_loop(
|
fn redraw_loop(redraw: Subject(Layout)) -> Nil {
|
||||||
logger: Subject(logging_control.Control),
|
|
||||||
redraw: Subject(Layout),
|
|
||||||
) -> Nil {
|
|
||||||
process.receive_forever(redraw)
|
process.receive_forever(redraw)
|
||||||
|> layout.render(logger, _)
|
|> layout.render
|
||||||
|
|
||||||
redraw_loop(logger, redraw)
|
redraw_loop(redraw)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_dimensions_on_interval(ui: Subject(Control), interval_ms: Int) {
|
fn update_dimensions_on_interval(ui: Subject(Control), interval_ms: Int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user