wip: reworking phat cell overlap

This commit is contained in:
🪞👃🪞 2025-01-24 23:07:43 +01:00
parent 854f198e36
commit 77809ca289
2 changed files with 57 additions and 64 deletions

View file

@ -295,39 +295,43 @@ impl Tek {
let size_h = self.size.h(); let size_h = self.size.h();
let editing = self.is_editing(); let editing = self.is_editing();
let tracks = move||self.tracks_sizes(editing, self.editor_w()); 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_track = self.selected().track();
let selected_scene = self.selected().scene(); let selected_scene = self.selected().scene();
let header = move||{ let header = move||{
let last_color = Arc::new(RwLock::new(ItemPalette::G[0]));
let cell = { let cell = {
let last_color = last_color.clone(); move|i, color: &ItemPalette, last: Option<ItemPalette>, name: Arc<str>|Phat {
move|i, color: &ItemPalette, name: Arc<str>|phat_sel_3( width: 0,
self.selected().scene() == Some(i), height: 0,
Tui::bold(true, Bsp::e("🭬", name.clone())), selected: self.selected().scene() == Some(i),
Tui::bold(true, Bsp::e("🭬", name)), content: Tui::bold(true, Bsp::e("🭬", name.clone())),
if i == 0 { Some(Reset) } fg: color.lightest.rgb,
else if self.selected().scene() == Some(i) { None } top: if self.selected().scene() == Some(i) { last.map(|last|last.light.rgb) } else { last.map(|last|last.base.rgb) },
else { Some(last_color.read().unwrap().base.rgb) }, mid: if self.selected().scene() == Some(i+1) { color.light } else { color.base }.rgb,
if self.selected().scene() == Some(i+1) { color.light } else { color.base }.rgb, low: Some(Reset)
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; let height = (1 + y2 - y1) as u16;
*last_color.write().unwrap() = scene.color;
Either(y2 > size_h, (), map_south(y1 as u16, height, Either(y2 > size_h, (), map_south(y1 as u16, height,
Fixed::y(height, Outer(false, bstyle) Fixed::y(height, Outer(false, bstyle)
.enclose(cell(s, &scene.color, scene.name.clone()))))) .enclose(cell(s, &scene.color, last, scene.name.clone())))))
})).boxed() })).boxed()
}; };
let content: ThunkBox<_> = per_track!(self.size.w(); |self, track, t|{ let content: ThunkBox<_> = per_track!(self.size.w(); |self, track, t|{
let tab = " Tab "; let tab = " Tab ";
let last_color = self.fmtd.read().unwrap().last_color.clone();
let same_track = selected_track == Some(t+1); 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 height = (1 + y2 - y1) as u16;
let last_color = last_color.clone();
Thunk::new(move||{ Thunk::new(move||{
let mut fg = Tui::g(64); let mut fg = Tui::g(64);
let mut bg = ItemPalette::G[32]; let mut bg = ItemPalette::G[32];
@ -340,14 +344,11 @@ impl Tek {
let selected = same_track && selected_scene == Some(s+1); let selected = same_track && selected_scene == Some(s+1);
let neighbor = same_track && selected_scene == Some(s); let neighbor = same_track && selected_scene == Some(s);
let active = editing && selected; let active = editing && selected;
let top = if s == 0 { let top = if neighbor {
Some(Reset) last.map(|last|last.light.rgb)
} else if neighbor {
Some(last_color.read().unwrap().light.rgb)
} else { } else {
Some(last_color.read().unwrap().base.rgb) last.map(|last|last.base.rgb)
}; };
*last_color.write().unwrap() = bg;
let label = move||{ let label = move||{
let clip = scene.clips[t].clone(); let clip = scene.clips[t].clone();
let icon = ""; let icon = "";
@ -363,14 +364,21 @@ impl Tek {
&self.editor)), &self.editor)),
Thunk::new(move||Bsp::a( Thunk::new(move||Bsp::a(
When::new(selected, Fill::y(Align::n(button(tab, "edit")))), When::new(selected, Fill::y(Align::n(button(tab, "edit")))),
phat_sel_3( Phat {
width: 0,
height: 3,
selected, selected,
label(), content: {
label(), 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, top,
if selected { bg.light } else { bg.base }.rgb, mid: if selected { bg.light } else { bg.base }.rgb,
Some(Reset) low: Some(Reset)
)))))))) })))))))
}) })
}) })
}); });

View file

@ -110,13 +110,15 @@ impl Content<TuiOut> for RepeatH<'_> {
/// A cell that takes up 3 rows on its own, /// A cell that takes up 3 rows on its own,
/// but stacks, giving (N+1)*2 rows per N cells. /// but stacks, giving (N+1)*2 rows per N cells.
pub struct Phat<T: Content<T>> { pub struct Phat<T> {
pub width: u16, pub width: u16,
pub height: u16, pub height: u16,
pub content: T, pub content: T,
pub fg: Color,
pub top: Option<Color>, pub top: Option<Color>,
pub mid: Option<Color>, pub mid: Color,
pub low: Option<Color>, pub low: Option<Color>,
pub selected: bool
} }
impl<T> Phat<T> { impl<T> Phat<T> {
/// A phat line /// A phat line
@ -128,32 +130,15 @@ impl<T> Phat<T> {
Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(&""))) Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(&"")))
} }
} }
impl<T: Content<T>> for Phat<T> { impl<T: Content<TuiOut>> Content<TuiOut> for Phat<T> {
fn content () -> impl Render<T> { fn content (&self) -> impl Render<TuiOut> {
Bsp::s(Self::lo(color.base.rgb, last.base.rgb), let top = self.top.map(|top|Self::lo(self.mid, top));
Bsp::n(Self::hi(color.base.rgb, last.base.rgb), let low = self.low.map(|low|Self::hi(self.mid, low));
Fixed::y(1, Fill::x(Tui::fg_bg(color.lightest.rgb, color.base.rgb, field))), 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 <T: Content<TuiOut>> (
selected: bool, field_1: T, field_2: T,
top: Option<Color>,
mid: Color,
low: Option<Color>,
) -> impl Content<TuiOut> {
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<T: Content<T>, I: Iterator<Item=T>> {
items: I,
color: Color
}
pub trait TuiStyle { pub trait TuiStyle {
fn fg <R: Content<TuiOut>> (color: Color, w: R) -> Foreground<R> { fn fg <R: Content<TuiOut>> (color: Color, w: R) -> Foreground<R> {
@ -423,7 +408,7 @@ border! {
const S0: &'static str = ""; const S0: &'static str = "";
fn style (&self) -> Option<Style> { Some(self.1) } fn style (&self) -> Option<Style> { Some(self.1) }
}, },
Phat { Thick {
"" "" "" "" "" ""
"" "" "" ""
"" "" "" "" "" ""