This commit is contained in:
Alexander Heldt
2025-12-06 22:46:56 +01:00
parent 73cf46eef4
commit de5c2367fa
6 changed files with 152 additions and 157 deletions

View File

@@ -1,72 +1,59 @@
import gleam/dict
import gleam/io
import gleam/string
import gleeunit
import gleeunit/should
import musicplayer/ui/virtual_ansi
import musicplayer/ui/layout.{Layout, Percent, Section, Style}
import musicplayer/ui/layout.{Percent, Section, Style}
pub fn main() -> Nil {
gleeunit.main()
}
pub fn percent_layout_test() {
let layout =
Layout(
width: 80,
height: 20,
nodes: dict.from_list([
#(
layout.Root,
layout.Row(
content: "container",
style: Style(dimensions: Percent(width: 100, height: 100)),
children: [
Section("Row1"),
Section("Row2"),
],
),
),
#(
Section("Row1"),
layout.Row(
content: "row 1",
style: Style(dimensions: Percent(width: 100, height: 50)),
children: [
Section("A"),
Section("B"),
],
),
),
#(
let nodes = [
#(
Section("Row1"),
layout.Row(
content: "row 1",
style: Style(dimensions: Percent(width: 100, height: 50)),
children: [
Section("A"),
layout.Cell(
content: "cell 1",
style: Style(dimensions: Percent(width: 50, height: 100)),
),
),
#(
Section("B"),
layout.Cell(
content: "cell 2",
style: Style(dimensions: Percent(width: 50, height: 100)),
),
),
#(
Section("Row2"),
layout.Row(
content: "row 1",
style: Style(dimensions: Percent(width: 100, height: 50)),
children: [],
),
),
]),
)
],
),
),
#(
Section("A"),
layout.Cell(
content: "cell 1",
style: Style(dimensions: Percent(width: 50, height: 100)),
),
),
#(
Section("B"),
layout.Cell(
content: "cell 2",
style: Style(dimensions: Percent(width: 50, height: 100)),
),
),
#(
Section("Row2"),
layout.Row(
content: "row 1",
style: Style(dimensions: Percent(width: 100, height: 50)),
children: [],
),
),
]
let columns = 80
let rows = 20
let layout = layout.new(columns, rows, nodes)
let expected =
"
container──────────────────────────────────────────────────────────────────────┐
┌──────────────────────────────────────────────────────────────────────────────┐
│row 1────────────────────────────────────────────────────────────────────────┐│
││cell 1───────────────────────────────┐cell 2───────────────────────────────┐││
│││ ││ │││

View File

@@ -18,12 +18,12 @@ pub fn render(layout: Layout) -> String {
let screen =
layout.render_generic(
layout,
int.to_float(layout.width),
int.to_float(layout.height),
int.to_float(layout.columns),
int.to_float(layout.rows),
1,
1,
0,
layout.Root,
layout.Section(layout.root_section),
dict.new(),
test_renders,
)