This commit is contained in:
Alexander Heldt
2025-12-06 19:55:11 +01:00
parent fff9e32895
commit 73cf46eef4
4 changed files with 65 additions and 47 deletions

View File

@@ -5,23 +5,23 @@ import gleeunit
import gleeunit/should
import musicplayer/ui/virtual_ansi
import musicplayer/ui/layout.{Layout, Section, Style}
import musicplayer/ui/layout.{Layout, Percent, Section, Style}
pub fn main() -> Nil {
gleeunit.main()
}
pub fn foo_test() {
pub fn percent_layout_test() {
let layout =
Layout(
width: 80,
height: 20,
nodes: dict.from_list([
#(
Section("Root"),
layout.Root,
layout.Row(
content: "container",
style: Style(width_percent: 100, height_percent: 100),
style: Style(dimensions: Percent(width: 100, height: 100)),
children: [
Section("Row1"),
Section("Row2"),
@@ -32,7 +32,7 @@ pub fn foo_test() {
Section("Row1"),
layout.Row(
content: "row 1",
style: Style(width_percent: 100, height_percent: 50),
style: Style(dimensions: Percent(width: 100, height: 50)),
children: [
Section("A"),
Section("B"),
@@ -43,21 +43,21 @@ pub fn foo_test() {
Section("A"),
layout.Cell(
content: "cell 1",
style: Style(width_percent: 50, height_percent: 100),
style: Style(dimensions: Percent(width: 50, height: 100)),
),
),
#(
Section("B"),
layout.Cell(
content: "cell 2",
style: Style(width_percent: 50, height_percent: 100),
style: Style(dimensions: Percent(width: 50, height: 100)),
),
),
#(
Section("Row2"),
layout.Row(
content: "row 1",
style: Style(width_percent: 100, height_percent: 50),
style: Style(dimensions: Percent(width: 100, height: 50)),
children: [],
),
),
@@ -88,8 +88,7 @@ container───────────────────────
└──────────────────────────────────────────────────────────────────────────────┘
"
let visual =
virtual_ansi.render(layout, Section("Root"), layout.width, layout.height)
let visual = virtual_ansi.render(layout)
case visual == string.trim(expected) {
True -> Nil
False -> {

View File

@@ -3,12 +3,12 @@ import gleam/int
import gleam/list
import gleam/string
import musicplayer/ui/layout.{type Layout, type Section, Renders}
import musicplayer/ui/layout.{type Layout, Renders}
pub type Screen =
dict.Dict(#(Int, Int), String)
pub fn render(layout: Layout, root: Section, width: Int, height: Int) -> String {
pub fn render(layout: Layout) -> String {
let test_renders =
Renders(
box: fn(screen, x, y, w, h) { box(screen, x, y, w, h) },
@@ -18,12 +18,12 @@ pub fn render(layout: Layout, root: Section, width: Int, height: Int) -> String
let screen =
layout.render_generic(
layout,
int.to_float(width),
int.to_float(height),
int.to_float(layout.width),
int.to_float(layout.height),
1,
1,
0,
root,
layout.Root,
dict.new(),
test_renders,
)