mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
wip: focus refactor, e10
This commit is contained in:
parent
6127aa4b30
commit
6a25a3b858
3 changed files with 60 additions and 27 deletions
|
|
@ -40,6 +40,33 @@ pub enum ArrangerFocus {
|
|||
PhraseEditor,
|
||||
}
|
||||
|
||||
pub trait FocusWrap<T> {
|
||||
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: T, content: &'a W)
|
||||
-> impl Widget<Engine = Tui> + 'a;
|
||||
}
|
||||
|
||||
impl FocusWrap<TransportFocus> for TransportFocus {
|
||||
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
|
||||
-> impl Widget<Engine = Tui> + 'a
|
||||
{
|
||||
let focused = focus == self;
|
||||
let corners = focused.then_some(CORNERS);
|
||||
let highlight = focused.then_some(Background(Color::Rgb(60, 70, 50)));
|
||||
lay!(corners, highlight, *content)
|
||||
}
|
||||
}
|
||||
|
||||
impl FocusWrap<TransportFocus> for Option<TransportFocus> {
|
||||
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
|
||||
-> impl Widget<Engine = Tui> + 'a
|
||||
{
|
||||
let focused = Some(focus) == self;
|
||||
let corners = focused.then_some(CORNERS);
|
||||
let highlight = focused.then_some(Background(Color::Rgb(60, 70, 50)));
|
||||
lay!(corners, highlight, *content)
|
||||
}
|
||||
}
|
||||
|
||||
impl TransportFocus {
|
||||
pub fn next (&mut self) {
|
||||
*self = match self {
|
||||
|
|
@ -59,14 +86,6 @@ impl TransportFocus {
|
|||
Self::Clock => Self::Sync,
|
||||
}
|
||||
}
|
||||
pub fn wrap <'a, W: Widget<Engine = Tui>> (
|
||||
self, parent_focus: bool, focus: Self, widget: &'a W
|
||||
) -> impl Widget<Engine = Tui> + 'a {
|
||||
let focused = parent_focus && focus == self;
|
||||
let corners = focused.then_some(CORNERS);
|
||||
let highlight = focused.then_some(Background(Color::Rgb(60, 70, 50)));
|
||||
lay!(corners, highlight, *widget)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_focus {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue