diff --git a/Cargo.lock b/Cargo.lock index d1135b6..d514711 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -928,7 +928,7 @@ dependencies = [ [[package]] name = "tengri" -version = "0.1.1" +version = "0.1.2" dependencies = [ "tengri_dsl", "tengri_input", @@ -938,7 +938,7 @@ dependencies = [ [[package]] name = "tengri_dsl" -version = "0.1.1" +version = "0.1.2" dependencies = [ "itertools 0.14.0", "konst", @@ -949,7 +949,7 @@ dependencies = [ [[package]] name = "tengri_input" -version = "0.1.1" +version = "0.1.2" dependencies = [ "tengri_dsl", "tengri_tui", @@ -957,7 +957,7 @@ dependencies = [ [[package]] name = "tengri_output" -version = "0.1.1" +version = "0.1.2" dependencies = [ "proptest", "proptest-derive", @@ -968,7 +968,7 @@ dependencies = [ [[package]] name = "tengri_tui" -version = "0.1.1" +version = "0.1.2" dependencies = [ "atomic_float", "better-panic", diff --git a/Cargo.toml b/Cargo.toml index 4b53fdc..0f8b521 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,6 @@ +[workspace.package] +version = "0.1.2" + [workspace] resolver = "2" members = [ @@ -14,6 +17,3 @@ lto = true [profile.coverage] inherits = "test" lto = false - -[workspace.package] -version = "0.1.1" diff --git a/tui/src/tui_content.rs b/tui/src/tui_content.rs index f793ede..bd319cb 100644 --- a/tui/src/tui_content.rs +++ b/tui/src/tui_content.rs @@ -1,9 +1,9 @@ use crate::*; -use crate::Color::*; use ratatui::prelude::Position; -mod tui_color; pub use self::tui_color::*; -mod tui_file; pub use self::tui_file::*; +mod tui_color; pub use self::tui_color::*; +mod tui_file; pub use self::tui_file::*; +mod tui_scroll; pub use self::tui_scroll::*; macro_rules! impl_content_layout_render { ($Output:ty: |$self:ident: $Struct:ty, $to:ident| layout = $layout:expr; render = $render:expr) => { @@ -112,79 +112,6 @@ impl Content for RepeatH<'_> { } } -pub struct ScrollbarV { - pub offset: usize, - pub length: usize, - pub total: usize, -} -impl ScrollbarV { - const ICON_DEC: &[char] = &['▲']; - const ICON_INC: &[char] = &['▼']; -} -impl Content for ScrollbarV { - fn render (&self, to: &mut TuiOut) { - let [x, y1, _w, h] = to.area().xywh(); - let y2 = y1 + h; - for (i, y) in (y1..=y2).enumerate() { - if let Some(cell) = to.buffer.cell_mut(Position::from((x, y))) { - if (i as usize) < (Self::ICON_DEC.len()) { - cell.set_fg(Rgb(255, 255, 255)); - cell.set_bg(Rgb(0, 0, 0)); - cell.set_char(Self::ICON_DEC[i as usize]); - } else if (i as usize) > (h as usize - Self::ICON_INC.len()) { - cell.set_fg(Rgb(255, 255, 255)); - cell.set_bg(Rgb(0, 0, 0)); - cell.set_char(Self::ICON_INC[h as usize - i]); - } else if false { - cell.set_fg(Rgb(255, 255, 255)); - cell.set_bg(Reset); - cell.set_char('‖'); // ━ - } else { - cell.set_fg(Rgb(0, 0, 0)); - cell.set_bg(Reset); - cell.set_char('╎'); // ━ - } - } - } - } -} - -pub struct ScrollbarH { - pub offset: usize, - pub length: usize, - pub total: usize, -} -impl ScrollbarH { - const ICON_DEC: &[char] = &[' ', '🞀', ' ']; - const ICON_INC: &[char] = &[' ', '🞂', ' ']; -} -impl Content for ScrollbarH { - fn render (&self, to: &mut TuiOut) { - let [x1, y, w, _h] = to.area().xywh(); - let x2 = x1 + w; - for (i, x) in (x1..=x2).enumerate() { - if let Some(cell) = to.buffer.cell_mut(Position::from((x, y))) { - if i < (Self::ICON_DEC.len()) { - cell.set_fg(Rgb(255, 255, 255)); - cell.set_bg(Rgb(0, 0, 0)); - cell.set_char(Self::ICON_DEC[i as usize]); - } else if i > (w as usize - Self::ICON_INC.len()) { - cell.set_fg(Rgb(255, 255, 255)); - cell.set_bg(Rgb(0, 0, 0)); - cell.set_char(Self::ICON_INC[w as usize - i]); - } else if false { - cell.set_fg(Rgb(255, 255, 255)); - cell.set_bg(Reset); - cell.set_char('━'); - } else { - cell.set_fg(Rgb(0, 0, 0)); - cell.set_bg(Reset); - cell.set_char('╌'); - } - } - } - } -} /// A cell that takes up 3 rows on its own, /// but stacks, giving (N+1)*2 rows per N cells. diff --git a/tui/src/tui_content/tui_scroll.rs b/tui/src/tui_content/tui_scroll.rs index e69de29..fe8bf3a 100644 --- a/tui/src/tui_content/tui_scroll.rs +++ b/tui/src/tui_content/tui_scroll.rs @@ -0,0 +1,80 @@ +use crate::*; +use ratatui::{prelude::Position, style::Color::*}; + +pub struct ScrollbarV { + pub offset: usize, + pub length: usize, + pub total: usize, +} + +pub struct ScrollbarH { + pub offset: usize, + pub length: usize, + pub total: usize, +} + +impl ScrollbarV { + const ICON_DEC: &[char] = &['▲']; + const ICON_INC: &[char] = &['▼']; +} + +impl ScrollbarH { + const ICON_DEC: &[char] = &[' ', '🞀', ' ']; + const ICON_INC: &[char] = &[' ', '🞂', ' ']; +} + +impl Content for ScrollbarV { + fn render (&self, to: &mut TuiOut) { + let [x, y1, _w, h] = to.area().xywh(); + let y2 = y1 + h; + for (i, y) in (y1..=y2).enumerate() { + if let Some(cell) = to.buffer.cell_mut(Position::from((x, y))) { + if (i as usize) < (Self::ICON_DEC.len()) { + cell.set_fg(Rgb(255, 255, 255)); + cell.set_bg(Rgb(0, 0, 0)); + cell.set_char(Self::ICON_DEC[i as usize]); + } else if (i as usize) > (h as usize - Self::ICON_INC.len()) { + cell.set_fg(Rgb(255, 255, 255)); + cell.set_bg(Rgb(0, 0, 0)); + cell.set_char(Self::ICON_INC[h as usize - i]); + } else if false { + cell.set_fg(Rgb(255, 255, 255)); + cell.set_bg(Reset); + cell.set_char('‖'); // ━ + } else { + cell.set_fg(Rgb(0, 0, 0)); + cell.set_bg(Reset); + cell.set_char('╎'); // ━ + } + } + } + } +} + +impl Content for ScrollbarH { + fn render (&self, to: &mut TuiOut) { + let [x1, y, w, _h] = to.area().xywh(); + let x2 = x1 + w; + for (i, x) in (x1..=x2).enumerate() { + if let Some(cell) = to.buffer.cell_mut(Position::from((x, y))) { + if i < (Self::ICON_DEC.len()) { + cell.set_fg(Rgb(255, 255, 255)); + cell.set_bg(Rgb(0, 0, 0)); + cell.set_char(Self::ICON_DEC[i as usize]); + } else if i > (w as usize - Self::ICON_INC.len()) { + cell.set_fg(Rgb(255, 255, 255)); + cell.set_bg(Rgb(0, 0, 0)); + cell.set_char(Self::ICON_INC[w as usize - i]); + } else if false { + cell.set_fg(Rgb(255, 255, 255)); + cell.set_bg(Reset); + cell.set_char('━'); + } else { + cell.set_fg(Rgb(0, 0, 0)); + cell.set_bg(Reset); + cell.set_char('╌'); + } + } + } + } +}