diff --git a/tek/src/view.rs b/tek/src/view.rs index a90b5a20..16e17bd8 100644 --- a/tek/src/view.rs +++ b/tek/src/view.rs @@ -295,39 +295,43 @@ impl Tek { let size_h = self.size.h(); let editing = self.is_editing(); let tracks = move||self.tracks_sizes(editing, self.editor_w()); - let scenes = move||self.scenes_sizes(editing, 2, 15); let selected_track = self.selected().track(); let selected_scene = self.selected().scene(); - let header = move||{ - let last_color = Arc::new(RwLock::new(ItemPalette::G[0])); + let header = move||{ let cell = { - let last_color = last_color.clone(); - move|i, color: &ItemPalette, name: Arc|phat_sel_3( - self.selected().scene() == Some(i), - Tui::bold(true, Bsp::e("🭬", name.clone())), - Tui::bold(true, Bsp::e("🭬", name)), - if i == 0 { Some(Reset) } - else if self.selected().scene() == Some(i) { None } - else { Some(last_color.read().unwrap().base.rgb) }, - if self.selected().scene() == Some(i+1) { color.light } else { color.base }.rgb, - Some(Reset) - ) + move|i, color: &ItemPalette, last: Option, name: Arc|Phat { + width: 0, + height: 0, + selected: self.selected().scene() == Some(i), + content: Tui::bold(true, Bsp::e("🭬", name.clone())), + fg: color.lightest.rgb, + top: if self.selected().scene() == Some(i) { last.map(|last|last.light.rgb) } else { last.map(|last|last.base.rgb) }, + mid: if self.selected().scene() == Some(i+1) { color.light } else { color.base }.rgb, + low: Some(Reset) + } }; - Align::y(Map::new(scenes, move|(_, scene, y1, y2), s| { + Align::y(Map::new(move||self.scenes_sizes(editing, 2, 15) + .map(|(s, scene, y1, y2)|(s, scene, y1, y2, if s == 0 { + None + } else { + Some(self.scenes[s-1].color) + })), move|(_, scene, y1, y2, last), s| { let height = (1 + y2 - y1) as u16; - *last_color.write().unwrap() = scene.color; Either(y2 > size_h, (), map_south(y1 as u16, height, Fixed::y(height, Outer(false, bstyle) - .enclose(cell(s, &scene.color, scene.name.clone()))))) + .enclose(cell(s, &scene.color, last, scene.name.clone()))))) })).boxed() }; let content: ThunkBox<_> = per_track!(self.size.w(); |self, track, t|{ let tab = " Tab "; - let last_color = self.fmtd.read().unwrap().last_color.clone(); let same_track = selected_track == Some(t+1); - Map::new(scenes, move|(_, scene, y1, y2), s| { + Map::new(move||self.scenes_sizes(editing, 2, 15) + .map(|(s, scene, y1, y2)|(s, scene, y1, y2, if s == 0 { + None + } else { + Some(self.scenes[s-1].color) + })), move|(_, scene, y1, y2, last), s| { let height = (1 + y2 - y1) as u16; - let last_color = last_color.clone(); Thunk::new(move||{ let mut fg = Tui::g(64); let mut bg = ItemPalette::G[32]; @@ -340,14 +344,11 @@ impl Tek { let selected = same_track && selected_scene == Some(s+1); let neighbor = same_track && selected_scene == Some(s); let active = editing && selected; - let top = if s == 0 { - Some(Reset) - } else if neighbor { - Some(last_color.read().unwrap().light.rgb) + let top = if neighbor { + last.map(|last|last.light.rgb) } else { - Some(last_color.read().unwrap().base.rgb) + last.map(|last|last.base.rgb) }; - *last_color.write().unwrap() = bg; let label = move||{ let clip = scene.clips[t].clone(); let icon = " ⏹ "; @@ -363,14 +364,21 @@ impl Tek { &self.editor)), Thunk::new(move||Bsp::a( When::new(selected, Fill::y(Align::n(button(tab, "edit")))), - phat_sel_3( + Phat { + width: 0, + height: 3, selected, - label(), - label(), + content: { + let clip = scene.clips[t].clone(); + let icon = " ⏹ "; + let name = clip.map(|c|c.read().unwrap().name.clone()); + Align::nw(Tui::fg(fg, Bsp::e(icon, Bsp::e(Tui::bold(true, name), " ")))) + }, + fg, top, - if selected { bg.light } else { bg.base }.rgb, - Some(Reset) - )))))))) + mid: if selected { bg.light } else { bg.base }.rgb, + low: Some(Reset) + }))))))) }) }) }); diff --git a/tui/src/tui_content.rs b/tui/src/tui_content.rs index 043a5b66..3bd87895 100644 --- a/tui/src/tui_content.rs +++ b/tui/src/tui_content.rs @@ -110,13 +110,15 @@ impl Content for RepeatH<'_> { /// A cell that takes up 3 rows on its own, /// but stacks, giving (N+1)*2 rows per N cells. -pub struct Phat> { - pub width: u16, - pub height: u16, - pub content: T, - pub top: Option, - pub mid: Option, - pub low: Option, +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 } impl Phat { /// A phat line @@ -128,32 +130,15 @@ impl Phat { Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(&"▀"))) } } -impl> for Phat { - fn content () -> impl Render { - Bsp::s(Self::lo(color.base.rgb, last.base.rgb), - Bsp::n(Self::hi(color.base.rgb, last.base.rgb), - Fixed::y(1, Fill::x(Tui::fg_bg(color.lightest.rgb, color.base.rgb, field))), - ) - ) +impl> Content for Phat { + fn content (&self) -> impl Render { + let top = self.top.map(|top|Self::lo(self.mid, top)); + let low = 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) } } -pub fn phat_sel_3 > ( - selected: bool, field_1: T, field_2: T, - top: Option, - mid: Color, - low: Option, -) -> impl Content { - let border = Style::default().fg(Color::Rgb(255,255,255)).bg(mid); - let top = top.map(|top|phat_lo(mid, top)); - let low = low.map(|low|phat_hi(mid, low)); - let a = Tui::bg(mid, Outer(true, border).enclose(Align::w(Bsp::s("", Bsp::n("", Fill::y(field_1)))))); - let b = Bsp::s(Fixed::y(1, top), Bsp::n(Fixed::y(1, low), Fill::xy(Tui::bg(mid, field_2)))); - Either::new(selected, a, b) -} -pub struct PhatOverlapIterator, I: Iterator> { - items: I, - color: Color -} pub trait TuiStyle { fn fg > (color: Color, w: R) -> Foreground { @@ -423,7 +408,7 @@ border! { const S0: &'static str = "⎵"; fn style (&self) -> Option