Compare commits
2 Commits
dc7af935ec
...
68bf808635
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68bf808635 | ||
|
|
4329625cf4 |
@@ -8,6 +8,7 @@ import gleam/string
|
||||
|
||||
import musicplayer/ui/internal
|
||||
import musicplayer/ui/plot.{type Buffer}
|
||||
import musicplayer/ui/style.{type Style, Percent, Style}
|
||||
|
||||
pub const root_section = "reserved_root_section"
|
||||
|
||||
@@ -19,15 +20,6 @@ pub type Section {
|
||||
PlaybackTime
|
||||
}
|
||||
|
||||
pub type Dimension {
|
||||
Percent(width: Int, height: Int)
|
||||
// TODO add Flex that flows
|
||||
}
|
||||
|
||||
pub type Style {
|
||||
Style(dimensions: Dimension)
|
||||
}
|
||||
|
||||
pub type Node {
|
||||
Row(heading: Option(String), style: Style, children: List(Section))
|
||||
Cell(heading: Option(String), style: Style)
|
||||
@@ -88,7 +80,7 @@ fn view_loop(i: ViewIdx, view_nodes: List(#(Section, Node))) -> View {
|
||||
view_index_section(i),
|
||||
Row(
|
||||
heading: None,
|
||||
style: Style(dimensions: Percent(width: 100, height: 100)),
|
||||
style: Style(dimensions: Percent(width: 100, height: 100), border: None),
|
||||
children: orphans,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import gleam/option.{Some}
|
||||
|
||||
import musicplayer/ui/internal
|
||||
import musicplayer/ui/layout.{Percent, Section, Style}
|
||||
import musicplayer/ui/layout.{Section}
|
||||
import musicplayer/ui/layout_examples/wait_for_input.{wait_for_input}
|
||||
import musicplayer/ui/style.{Percent, Style}
|
||||
|
||||
pub fn main() {
|
||||
let assert Ok(columns) = internal.io_get_columns()
|
||||
@@ -24,7 +25,10 @@ fn two_rows_with_cells(columns: Int, rows: Int) -> layout.Layout {
|
||||
Section("Row1"),
|
||||
layout.Row(
|
||||
heading: Some("row 1"),
|
||||
style: Style(dimensions: Percent(width: 100, height: 50)),
|
||||
style: Style(
|
||||
dimensions: Percent(width: 100, height: 50),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
children: [
|
||||
Section("A"),
|
||||
Section("B"),
|
||||
@@ -35,21 +39,30 @@ fn two_rows_with_cells(columns: Int, rows: Int) -> layout.Layout {
|
||||
Section("A"),
|
||||
layout.Cell(
|
||||
heading: Some("cell 1"),
|
||||
style: Style(dimensions: Percent(width: 50, height: 50)),
|
||||
style: Style(
|
||||
dimensions: Percent(width: 50, height: 50),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
),
|
||||
),
|
||||
#(
|
||||
Section("B"),
|
||||
layout.Cell(
|
||||
heading: Some("cell 2"),
|
||||
style: Style(dimensions: Percent(width: 50, height: 50)),
|
||||
style: Style(
|
||||
dimensions: Percent(width: 50, height: 50),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
),
|
||||
),
|
||||
#(
|
||||
Section("Row2"),
|
||||
layout.Row(
|
||||
heading: Some("row 2"),
|
||||
style: Style(dimensions: Percent(width: 50, height: 50)),
|
||||
style: Style(
|
||||
dimensions: Percent(width: 50, height: 50),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
children: [],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -57,8 +57,9 @@ pub fn box_with_heading(
|
||||
height: Int,
|
||||
heading: String,
|
||||
) -> Buffer {
|
||||
let heading_margin = 1
|
||||
box(buffer, x, y, width, height)
|
||||
|> text(heading, x, y)
|
||||
|> text(heading, x + heading_margin, y)
|
||||
}
|
||||
|
||||
fn horizontal_line(
|
||||
|
||||
34
src/musicplayer/ui/style.gleam
Normal file
34
src/musicplayer/ui/style.gleam
Normal file
@@ -0,0 +1,34 @@
|
||||
import gleam/option.{type Option}
|
||||
|
||||
pub type Dimension {
|
||||
Percent(width: Int, height: Int)
|
||||
// TODO add Flex that flows
|
||||
}
|
||||
|
||||
pub type Border {
|
||||
BorderNone
|
||||
BorderSingle
|
||||
}
|
||||
|
||||
pub type Style {
|
||||
Style(dimensions: Dimension, border: Option(Border))
|
||||
}
|
||||
|
||||
pub type BorderChars {
|
||||
BorderChars(
|
||||
top_left: String,
|
||||
top_right: String,
|
||||
bottom_left: String,
|
||||
bottom_right: String,
|
||||
horisontal: String,
|
||||
vertical: String,
|
||||
)
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Box-drawing_characters
|
||||
pub fn border_chars(border: Border) -> BorderChars {
|
||||
case border {
|
||||
BorderNone -> BorderChars("", "", "", "", "", "")
|
||||
BorderSingle -> BorderChars("┌", "┐", "└", "┘", "─", "│")
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import musicplayer/logging/logging
|
||||
import musicplayer/ui/control.{type Control}
|
||||
import musicplayer/ui/internal
|
||||
import musicplayer/ui/layout.{type Layout}
|
||||
import musicplayer/ui/style
|
||||
|
||||
pub type State(redraw, content) {
|
||||
State(redraw: Subject(Layout), layout: Layout)
|
||||
@@ -25,10 +26,10 @@ pub fn new() -> Result(Subject(Control), String) {
|
||||
layout.Header,
|
||||
layout.Row(
|
||||
heading: Some("Foo <1> | Bar (2)"),
|
||||
style: layout.Style(dimensions: layout.Percent(
|
||||
width: 100,
|
||||
height: 50,
|
||||
)),
|
||||
style: style.Style(
|
||||
dimensions: style.Percent(width: 100, height: 50),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
children: [],
|
||||
),
|
||||
),
|
||||
@@ -36,10 +37,10 @@ pub fn new() -> Result(Subject(Control), String) {
|
||||
layout.PlaybackTime,
|
||||
layout.Row(
|
||||
heading: None,
|
||||
style: layout.Style(dimensions: layout.Percent(
|
||||
width: 100,
|
||||
height: 50,
|
||||
)),
|
||||
style: style.Style(
|
||||
dimensions: style.Percent(width: 100, height: 50),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
children: [],
|
||||
),
|
||||
),
|
||||
@@ -49,10 +50,10 @@ pub fn new() -> Result(Subject(Control), String) {
|
||||
layout.Header,
|
||||
layout.Row(
|
||||
heading: Some("Foo (1) | Bar <2>"),
|
||||
style: layout.Style(dimensions: layout.Percent(
|
||||
width: 100,
|
||||
height: 33,
|
||||
)),
|
||||
style: style.Style(
|
||||
dimensions: style.Percent(width: 100, height: 33),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
children: [],
|
||||
),
|
||||
),
|
||||
@@ -60,10 +61,10 @@ pub fn new() -> Result(Subject(Control), String) {
|
||||
layout.Search,
|
||||
layout.Row(
|
||||
heading: None,
|
||||
style: layout.Style(dimensions: layout.Percent(
|
||||
width: 100,
|
||||
height: 33,
|
||||
)),
|
||||
style: style.Style(
|
||||
dimensions: style.Percent(width: 100, height: 33),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
children: [],
|
||||
),
|
||||
),
|
||||
@@ -71,10 +72,10 @@ pub fn new() -> Result(Subject(Control), String) {
|
||||
layout.PlaybackTime,
|
||||
layout.Row(
|
||||
heading: None,
|
||||
style: layout.Style(dimensions: layout.Percent(
|
||||
width: 100,
|
||||
height: 33,
|
||||
)),
|
||||
style: style.Style(
|
||||
dimensions: style.Percent(width: 100, height: 33),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
children: [],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -5,8 +5,9 @@ import gleam/string
|
||||
import gleeunit
|
||||
import gleeunit/should
|
||||
|
||||
import musicplayer/ui/layout.{Percent, RenderContext, Section, Style}
|
||||
import musicplayer/ui/layout.{RenderContext, Section}
|
||||
import musicplayer/ui/plot
|
||||
import musicplayer/ui/style.{Percent, Style}
|
||||
|
||||
pub fn main() -> Nil {
|
||||
gleeunit.main()
|
||||
@@ -19,7 +20,10 @@ pub fn percent_layout_test() {
|
||||
Section("Row1"),
|
||||
layout.Row(
|
||||
heading: Some("row 1"),
|
||||
style: Style(dimensions: Percent(width: 100, height: 50)),
|
||||
style: Style(
|
||||
dimensions: Percent(width: 100, height: 50),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
children: [
|
||||
Section("A"),
|
||||
Section("B"),
|
||||
@@ -30,21 +34,30 @@ pub fn percent_layout_test() {
|
||||
Section("A"),
|
||||
layout.Cell(
|
||||
heading: Some("cell 1"),
|
||||
style: Style(dimensions: Percent(width: 50, height: 100)),
|
||||
style: Style(
|
||||
dimensions: Percent(width: 50, height: 100),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
),
|
||||
),
|
||||
#(
|
||||
Section("B"),
|
||||
layout.Cell(
|
||||
heading: Some("cell 2"),
|
||||
style: Style(dimensions: Percent(width: 50, height: 100)),
|
||||
style: Style(
|
||||
dimensions: Percent(width: 50, height: 100),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
),
|
||||
),
|
||||
#(
|
||||
Section("Row2"),
|
||||
layout.Row(
|
||||
heading: Some("row 1"),
|
||||
style: Style(dimensions: Percent(width: 100, height: 50)),
|
||||
style: Style(
|
||||
dimensions: Percent(width: 100, height: 50),
|
||||
border: Some(style.BorderSingle),
|
||||
),
|
||||
children: [],
|
||||
),
|
||||
),
|
||||
@@ -58,8 +71,8 @@ pub fn percent_layout_test() {
|
||||
let expected =
|
||||
"
|
||||
┌──────────────────────────────────────────────────────────────────────────────┐
|
||||
│row 1────────────────────────────────────────────────────────────────────────┐│
|
||||
││cell 1───────────────────────────────┐cell 2───────────────────────────────┐││
|
||||
│┌row 1───────────────────────────────────────────────────────────────────────┐│
|
||||
││┌cell 1──────────────────────────────┐┌cell 2──────────────────────────────┐││
|
||||
│││ ││ │││
|
||||
│││ ││ │││
|
||||
│││ ││ │││
|
||||
@@ -67,7 +80,7 @@ pub fn percent_layout_test() {
|
||||
│││ ││ │││
|
||||
││└────────────────────────────────────┘└────────────────────────────────────┘││
|
||||
│└────────────────────────────────────────────────────────────────────────────┘│
|
||||
│row 1────────────────────────────────────────────────────────────────────────┐│
|
||||
│┌row 1───────────────────────────────────────────────────────────────────────┐│
|
||||
││ ││
|
||||
││ ││
|
||||
││ ││
|
||||
|
||||
Reference in New Issue
Block a user