rename Widget to Render and CustomWidget to Widget

This commit is contained in:
🪞👃🪞 2024-12-04 21:24:38 +01:00
parent f018988567
commit bf3c7630a4
20 changed files with 144 additions and 144 deletions

View file

@ -75,8 +75,8 @@ impl TuiTheme {
}
pub trait FocusWrap<T> {
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: T, content: &'a W)
-> impl Widget<Engine = Tui> + 'a;
fn wrap <'a, W: Render<Engine = Tui>> (self, focus: T, content: &'a W)
-> impl Render<Engine = Tui> + 'a;
}
pub fn to_focus_command (input: &TuiInput) -> Option<FocusCommand> {
@ -139,12 +139,12 @@ pub fn to_focus_command (input: &TuiInput) -> Option<FocusCommand> {
}
}
pub trait StatusBar: Widget<Engine = Tui> {
pub trait StatusBar: Render<Engine = Tui> {
type State;
fn hotkey_fg () -> Color where Self: Sized;
fn update (&mut self, state: &Self::State) where Self: Sized;
fn command (commands: &[[impl Widget<Engine = Tui>;3]])
-> impl Widget<Engine = Tui> + '_
fn command (commands: &[[impl Render<Engine = Tui>;3]])
-> impl Render<Engine = Tui> + '_
where
Self: Sized
{
@ -161,7 +161,7 @@ pub trait StatusBar: Widget<Engine = Tui> {
})
}
fn with <'a> (state: &'a Self::State, content: impl Widget<Engine=Tui>) -> impl Widget<Engine=Tui>
fn with <'a> (state: &'a Self::State, content: impl Render<Engine=Tui>) -> impl Render<Engine=Tui>
where Self: Sized, &'a Self::State: Into<Self>
{
Split::up(1, state.into(), content)
@ -172,9 +172,9 @@ fn content_with_menu_and_status <'a, A, S, C> (
content: &'a A,
menu_bar: &'a Option<MenuBar<Tui, S, C>>,
status_bar: &'a Option<impl StatusBar>
) -> impl Widget<Engine = Tui> + 'a
) -> impl Render<Engine = Tui> + 'a
where
A: Widget<Engine = Tui>,
A: Render<Engine = Tui>,
S: Send + Sync + 'a,
C: Command<S>
{

View file

@ -95,7 +95,7 @@ pub struct TrackView<'a, E: Engine> {
pub entered: bool,
}
impl<'a> Widget for TrackView<'a, Tui> {
impl<'a> Render for TrackView<'a, Tui> {
type Engine = Tui;
fn min_size (&self, area: [u16;2]) -> Perhaps<[u16;2]> {
todo!()
@ -132,7 +132,7 @@ impl<'a> Widget for TrackView<'a, Tui> {
impl Content for Mixer<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
Stack::right(|add| {
for channel in self.tracks.iter() {
add(channel)?;
@ -144,7 +144,7 @@ impl Content for Mixer<Tui> {
impl Content for Track<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
TrackView {
chain: Some(&self),
direction: tek_core::Direction::Right,

View file

@ -31,7 +31,7 @@ impl<E> Plugin<E> {
})
}
}
impl Widget for Plugin<Tui> {
impl Render for Plugin<Tui> {
type Engine = Tui;
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
Ok(Some(to))

View file

@ -316,7 +316,7 @@ impl Sample {
}
}
impl Widget for SamplerView<Tui> {
impl Render for SamplerView<Tui> {
type Engine = Tui;
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
todo!()
@ -371,7 +371,7 @@ fn draw_sample (
Ok(label1.len() + label2.len() + 4)
}
impl Widget for AddSampleModal {
impl Render for AddSampleModal {
type Engine = Tui;
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
todo!()

View file

@ -154,7 +154,7 @@ impl StatusBar for ArrangerStatus {
impl Content for ArrangerStatus {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
let label = match self {
Self::Transport => "TRANSPORT",
Self::ArrangerMix => "PROJECT",

View file

@ -50,8 +50,8 @@ pub enum TransportFocus {
}
impl FocusWrap<TransportFocus> for TransportFocus {
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
-> impl Widget<Engine = Tui> + 'a
fn wrap <'a, W: Render<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
-> impl Render<Engine = Tui> + 'a
{
let focused = focus == self;
let corners = focused.then_some(CORNERS);
@ -61,8 +61,8 @@ impl FocusWrap<TransportFocus> for TransportFocus {
}
impl FocusWrap<TransportFocus> for Option<TransportFocus> {
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
-> impl Widget<Engine = Tui> + 'a
fn wrap <'a, W: Render<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
-> impl Render<Engine = Tui> + 'a
{
let focused = Some(focus) == self;
let corners = focused.then_some(CORNERS);
@ -97,7 +97,7 @@ impl StatusBar for TransportStatusBar {
impl Content for TransportStatusBar {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
todo!();
""
}

View file

@ -3,7 +3,7 @@ use crate::*;
/// Layout for standalone arranger app.
impl Content for ArrangerTui {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
let arranger_focused = self.arranger_focused();
Split::down(
1,
@ -90,7 +90,7 @@ fn track_widths (tracks: &[ArrangerTrack]) -> Vec<(usize, usize)> {
pub fn arranger_content_vertical (
view: &ArrangerTui,
factor: usize
) -> impl Widget<Engine = Tui> + use<'_> {
) -> impl Render<Engine = Tui> + use<'_> {
let timebase = view.clock().timebase();
let current = &view.clock().playhead;
let tracks = view.tracks();
@ -107,7 +107,7 @@ pub fn arranger_content_vertical (
let cols: &[(usize, usize)] = cols.as_ref();
let any_size = |_|Ok(Some([0,0]));
// column separators
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
add(&Widget::new(any_size, move|to: &mut TuiOutput|{
let style = Some(Style::default().fg(sep_fg));
Ok(for x in cols.iter().map(|col|col.1) {
let x = scenes_w + to.area().x() + x as u16;
@ -115,7 +115,7 @@ pub fn arranger_content_vertical (
})
}))?;
// row separators
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
add(&Widget::new(any_size, move|to: &mut TuiOutput|{
Ok(for y in rows.iter().map(|row|row.1) {
let y = to.area().y() + (y / PPQ) as u16 + 1;
if y >= to.buffer.area.height { break }
@ -213,7 +213,7 @@ pub fn arranger_content_vertical (
// full grid with header and footer
add(&col!(header, content))?;
// cursor
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
add(&Widget::new(any_size, move|to: &mut TuiOutput|{
let area = to.area();
let focused = view.arranger_focused();
let selected = view.selected;
@ -276,14 +276,14 @@ pub fn arranger_content_vertical (
pub fn arranger_content_horizontal (
view: &ArrangerTui,
) -> impl Widget<Engine = Tui> + use<'_> {
) -> impl Render<Engine = Tui> + use<'_> {
let focused = view.arranger_focused();
let _tracks = view.tracks();
lay!(
focused.then_some(Background(TuiTheme::border_bg())),
row!(
// name
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{
Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!()
//let Self(tracks, selected) = self;
//let yellow = Some(Style::default().yellow().bold().not_dim());
@ -307,7 +307,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area))
}),
// monitor
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{
Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!()
//let Self(tracks) = self;
//let mut area = to.area();
@ -332,7 +332,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area))
}),
// record
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{
Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!()
//let Self(tracks) = self;
//let mut area = to.area();
@ -357,7 +357,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area))
}),
// overdub
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{
Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!()
//let Self(tracks) = self;
//let mut area = to.area();
@ -385,7 +385,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area))
}),
// erase
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{
Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!()
//let Self(tracks) = self;
//let mut area = to.area();
@ -408,7 +408,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area))
}),
// gain
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{
Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!()
//let Self(tracks) = self;
//let mut area = to.area();
@ -431,7 +431,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area))
}),
// scenes
CustomWidget::new(|_|{todo!()}, |to: &mut TuiOutput|{
Widget::new(|_|{todo!()}, |to: &mut TuiOutput|{
let [x, y, _, height] = to.area();
let mut x2 = 0;
Ok(for (scene_index, scene) in view.scenes().iter().enumerate() {

View file

@ -2,7 +2,7 @@ use crate::*;
impl Content for FileBrowser {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
Stack::down(|add|{
let mut i = 0;
for (_, name) in self.dirs.iter() {

View file

@ -54,7 +54,7 @@ impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> {
impl<'a> Content for PhraseView<'a> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
let Self {
focused,
entered,
@ -104,13 +104,13 @@ impl<'a> Content for PhraseView<'a> {
lay!(
row!(
CustomWidget::new(|to:[u16;2]|Ok(Some(to.clip_w(2))), move|to: &mut TuiOutput|{
Widget::new(|to:[u16;2]|Ok(Some(to.clip_w(2))), move|to: &mut TuiOutput|{
Ok(if to.area().h() >= 2 {
view_mode.render_keys(to, *note_hi, *note_lo)
})
}).fill_y(),
lay!(
CustomWidget::new(|to|Ok(Some(to)), |to: &mut TuiOutput|{
Widget::new(|to|Ok(Some(to)), |to: &mut TuiOutput|{
size.set_wh(to.area.w(), to.area.h() as usize - 1);
let draw = to.area().h() >= 2;
Ok(if draw {
@ -119,7 +119,7 @@ impl<'a> Content for PhraseView<'a> {
)
})
}).fill_x(),
CustomWidget::new(|to|Ok(Some(to)), move|to: &mut TuiOutput|{
Widget::new(|to|Ok(Some(to)), move|to: &mut TuiOutput|{
Ok(if *focused && *entered {
view_mode.render_cursor(
to,
@ -137,7 +137,7 @@ impl<'a> Content for PhraseView<'a> {
//} else {
//Color::Rgb(70, 80, 50)
//}))),
CustomWidget::new(|to:[u16;2]|Ok(Some(to.clip_h(1))), move|to: &mut TuiOutput|{
Widget::new(|to:[u16;2]|Ok(Some(to.clip_h(1))), move|to: &mut TuiOutput|{
//let playhead_inactive = Style::default().fg(Color::Rgb(255,255,255)).bg(Color::Rgb(40,50,30));
//let playhead_active = playhead_inactive.clone().yellow().bold().not_dim();
//if let Some(_) = phrase {

View file

@ -2,7 +2,7 @@ use crate::*;
impl Content for PhraseLength {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
Layers::new(move|add|{
match self.focus {
None => add(&row!(

View file

@ -25,7 +25,7 @@ impl<'a, T: HasPhraseList> From<&'a T> for PhraseListView<'a> {
// TODO: Display phrases always in order of appearance
impl<'a> Content for PhraseListView<'a> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
let Self { title, focused, entered, phrases, index, mode } = self;
let content = Stack::down(move|add|match mode {
Some(PhrasesMode::Import(_, ref browser)) => {

View file

@ -37,7 +37,7 @@ impl<'a> PhraseSelector<'a> {
// TODO: Display phrases always in order of appearance
impl<'a> Content for PhraseSelector<'a> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
let Self { title, phrase, focused, entered } = self;
let content = Layers::new(move|add|{
if let Some((instant, Some(phrase))) = phrase {

View file

@ -2,7 +2,7 @@ use crate::*;
impl Content for SequencerTui {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
lay!(self.size, SequencerStatusBar::with(self, col!(
TransportView::from(self),
Split::right(20,
@ -27,7 +27,7 @@ impl Content for SequencerTui {
impl Content for SequencerStatusBar {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
let orange = Color::Rgb(255,128,0);
let yellow = Color::Rgb(255,255,0);
let black = Color::Rgb(0,0,0);

View file

@ -1,6 +1,6 @@
use crate::*;
impl Widget for TransportTui {
impl Render for TransportTui {
type Engine = Tui;
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
TransportView::from(self).min_size(to)
@ -23,7 +23,7 @@ pub struct TransportView {
impl Content for TransportView {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
fn content (&self) -> impl Render<Engine = Tui> {
let Self { state, selected, focused, bpm, sync, quant, beat, msu, } = self;
row!(
selected.wrap(TransportFocus::PlayPause, &Styled(