Layout consist of multiple Views

This commit is contained in:
Alexander Heldt
2025-12-21 13:21:14 +01:00
parent ed69566f6f
commit 95eaeb60f4
4 changed files with 177 additions and 116 deletions

View File

@@ -12,45 +12,47 @@ pub fn main() -> Nil {
}
pub fn percent_layout_test() {
let nodes = [
#(
Section("Row1"),
layout.Row(
content: "row 1",
style: Style(dimensions: Percent(width: 100, height: 50)),
children: [
Section("A"),
Section("B"),
],
let views = [
[
#(
Section("Row1"),
layout.Row(
content: "row 1",
style: Style(dimensions: Percent(width: 100, height: 50)),
children: [
Section("A"),
Section("B"),
],
),
),
),
#(
Section("A"),
layout.Cell(
content: "cell 1",
style: Style(dimensions: Percent(width: 50, height: 100)),
#(
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("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("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 layout = layout.new(columns, rows, views)
let expected =
"
@@ -87,11 +89,13 @@ pub fn percent_layout_test() {
position_index: 0,
)
let assert Ok(view) = dict.get(layout.views, layout.current_view)
let flushed =
layout.render_loop(
layout,
view,
context,
Section(layout.root_section),
Section(string.append("view_", string.inspect(layout.current_view))),
dict.new(),
)
|> plot.flush_buffer(layout.columns, layout.rows)