From 76cefdca616451daa40c1813f2a6e8984430f9aa Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 25 Jan 2025 00:13:10 +0100 Subject: [PATCH] align scene cells at both edges --- tek/src/view.rs | 44 ++++++++++++++++++++++++++++-------------- tui/src/tui_content.rs | 18 ++++++++--------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/tek/src/view.rs b/tek/src/view.rs index ab38f05f..8ec348ef 100644 --- a/tek/src/view.rs +++ b/tek/src/view.rs @@ -298,31 +298,33 @@ impl Tek { let selected_track = self.selected().track(); let selected_scene = self.selected().scene(); let header = move||{ - let cell = move|s, bg: &ItemPalette, last: Option, name: Arc|{ - let selected = self.selected().scene() == Some(s+1); - let neighbor = self.selected().scene() == Some(s); + let cell = move|t, s, bg: &ItemPalette, last: Option, name: Arc|{ + let selected = t && self.selected().scene() == Some(s+1); + let neighbor = t && self.selected().scene() == Some(s); Phat { width: 0, height: 0, - selected: selected, + selected, content: Tui::bold(true, Bsp::e("🭬", name.clone())), - fg: bg.lightest.rgb, - top: if neighbor { last.map(|last|last.light.rgb) } else { last.map(|last|last.base.rgb) }, - mid: if selected { bg.light } else { bg.base }.rgb, - low: Some(Reset) + colors: [ + bg.lightest.rgb, + if selected { bg.light } else { bg.base }.rgb, + if neighbor { last.map(|last|last.light.rgb) } else { last.map(|last|last.base.rgb) }.unwrap_or(Reset), + Reset, + ] } }; Align::y(Map::new( move||self.scenes_sizes(editing, 2, 15).map_while( move|(s, scene, y1, y2)|if y2 > size_h { None } else { Some((s, scene, y1, y2, if s == 0 { - Some(self.scenes[s].color) + None } else { Some(self.scenes[s-1].color) })) }), move|(_, scene, y1, y2, last), s| { let height = (1 + y2 - y1) as u16; map_south(y1 as u16, height, Fixed::y(height, - cell(s, &scene.color, last, scene.name.clone()))) })).boxed() + cell(true, s, &scene.color, last, scene.name.clone()))) })).boxed() }; let content: ThunkBox<_> = per_track!(self.size.w(); |self, track, t|{ let tab = " Tab "; @@ -330,7 +332,7 @@ impl Tek { Map::new( move||self.scenes_sizes(editing, 2, 15).map_while( move|(s, scene, y1, y2)|if y2 > size_h { None } else { Some((s, scene, y1, y2, if s == 0 { - self.scenes[s].clips[t].as_ref().map(|c|c.read().unwrap().color) + None } else { self.scenes[s-1].clips[t].as_ref().map(|c|c.read().unwrap().color) })) }), @@ -364,10 +366,22 @@ impl Tek { height: 0, selected, content: content(), - fg, - top: if neighbor { last.map(|last|last.light.rgb) } else { last.map(|last|last.base.rgb) }, - mid: if selected { bg.light } else { bg.base }.rgb, - low: Some(Reset) + colors: [ + fg, + if selected { bg.light } else { bg.base }.rgb, + if neighbor { + last.map(|last|last.light.rgb) + } else { + last.map(|last|last.base.rgb) + }.unwrap_or(Reset), + if s == self.scenes.len().saturating_sub(1) { + Reset + } else if selected { + bg.light.rgb + } else { + bg.base.rgb + }, + ], }))))) }) }); diff --git a/tui/src/tui_content.rs b/tui/src/tui_content.rs index f83fea44..177f9398 100644 --- a/tui/src/tui_content.rs +++ b/tui/src/tui_content.rs @@ -1,4 +1,5 @@ use crate::*; +use crate::Color::*; macro_rules! impl_content_layout_render { ($Output:ty: |$self:ident: $Struct:ty, $to:ident| layout = $layout:expr; render = $render:expr) => { impl Content<$Output> for $Struct { @@ -114,11 +115,8 @@ pub struct Phat { pub width: u16, pub height: u16, pub content: T, - pub fg: Color, - pub top: Option, - pub mid: Color, - pub low: Option, - pub selected: bool + pub colors: [Color;4], + pub selected: bool, } impl Phat { /// A phat line @@ -132,11 +130,11 @@ impl Phat { } impl> Content for Phat { fn content (&self) -> impl Render { - let top = Fixed::y(1, self.top.map(|top|Self::lo(self.mid, top))); - let low = Fixed::y(1, self.low.map(|low|Self::hi(self.mid, low))); - let content = Tui::fg_bg(self.fg, self.mid, &self.content); - let phat = Bsp::s(top, Bsp::n(low, Fill::xy(content))); - Min::xy(self.width, self.height, phat) + let [fg, bg, hi, lo] = self.colors; + let top = Fixed::y(1, Self::lo(bg, hi)); + let low = Fixed::y(1, Self::hi(bg, lo)); + let content = Tui::fg_bg(fg, bg, &self.content); + Min::xy(self.width, self.height, Bsp::s(top, Bsp::n(low, Fill::xy(content)))) } }