wip: big flat pt.9: down to 141, looking good!

This commit is contained in:
🪞👃🪞 2024-12-30 20:43:22 +01:00
parent e958b4a2d2
commit d01aa7481b
7 changed files with 39 additions and 12 deletions

View file

@ -21,6 +21,14 @@ pub trait Output<E: Engine> {
Some($cb)
}
}
impl<E: Engine, $($($L),*$($T $(: $U)?),*)?> Render<E> for $Struct $(<$($L,)* E, $($T),*>)? {
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
self.content().map(|content|content.min_size(to)).unwrap_or(Ok(None))
}
fn render (&self, to: &mut E::Output) -> Usually<()> {
self.content().map(|content|content.render(to)).unwrap_or(Ok(()))
}
}
};
// Implement for a specific engine
@ -39,6 +47,20 @@ pub trait Output<E: Engine> {
Some($cb)
}
}
impl $(<
$($($L),+)?
$($($T$(:$U)?),+)?
>)? Render<$E> for $Struct $(<
$($($L),+)?
$($($T),+)?
>)? {
fn min_size (&self, to: <$E as Engine>::Size) -> Perhaps<<$E as Engine>::Size> {
self.content().map(|content|content.min_size(to)).unwrap_or(Ok(None))
}
fn render (&self, to: &mut <$E as Engine>::Output) -> Usually<()> {
self.content().map(|content|content.render(to)).unwrap_or(Ok(()))
}
}
}
}

View file

@ -367,7 +367,6 @@ pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut C
}
}
/*
/// Define a key
pub const fn key (code: KeyCode) -> KeyEvent {
let modifiers = KeyModifiers::NONE;
@ -391,6 +390,7 @@ pub const fn shift (key: KeyEvent) -> KeyEvent {
KeyEvent { modifiers: key.modifiers.union(KeyModifiers::SHIFT), ..key }
}
/*
/// Define a keymap
#[macro_export] macro_rules! keymap {
($T:ty { $([$k:ident $(($char:literal))?, $m:ident, $n: literal, $d: literal, $f: expr]),* $(,)? }) => {

View file

@ -152,7 +152,7 @@ border! {
"" ""
"" "" "" fn style (&self) -> Option<Style> { Some(self.0) }
},
Tab {
TabLike {
"" "" ""
"" ""
"" " " "" fn style (&self) -> Option<Style> { Some(self.0) }

View file

@ -15,7 +15,7 @@ pub(crate) use ::tek_layout::{
crossterm::{
self,
event::{
KeyEvent, KeyEventKind, KeyEventState, KeyModifiers,
Event, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers,
KeyCode::{self, *},
}
},

View file

@ -30,8 +30,11 @@ pub enum PhraseCommand {
}
event_map_input_to_command!(Tui: MidiEditor: PhraseCommand: MidiEditor::KEYS);
pub(crate) type KeyMapping<const N: usize, E, T, U> = [(E, &'static dyn Fn(&T)->U);N];
impl MidiEditor {
const KEYS: KeyMapping<31, Self> = [
const KEYS: KeyMapping<31, Event, Self, PhraseCommand> = [
(kexp!(Ctrl-Alt-Up), &|s: &Self|SetNoteScroll(s.note_point() + 3)),
(kexp!(Ctrl-Alt-Down), &|s: &Self|SetNoteScroll(s.note_point().saturating_sub(3))),
(kexp!(Ctrl-Alt-Left), &|s: &Self|SetTimeScroll(s.time_point().saturating_sub(s.time_zoom().get()))),

View file

@ -166,7 +166,7 @@ impl<'a> Render<Tui> for TrackView<'a> {
//}
handle!(<Tui>|self: Mixer, engine|{
if let TuiEvent::Input(crossterm::event::Event::Key(event)) = engine.event() {
if let crossterm::event::Event::Key(event) = engine.event() {
match event.code {
//KeyCode::Char('c') => {

View file

@ -1,23 +1,25 @@
use crate::*;
impl Tui {
pub(crate) fn fg <W: Render<Tui>> (color: Color, w: W) -> Foreground<W> {
pub trait TuiStyle {
fn fg <W: Render<Tui>> (color: Color, w: W) -> Foreground<W> {
Foreground(color, w)
}
pub(crate) fn bg <W: Render<Tui>> (color: Color, w: W) -> Background<W> {
fn bg <W: Render<Tui>> (color: Color, w: W) -> Background<W> {
Background(color, w)
}
pub(crate) fn fg_bg <W: Render<Tui>> (fg: Color, bg: Color, w: W) -> Background<Foreground<W>> {
fn fg_bg <W: Render<Tui>> (fg: Color, bg: Color, w: W) -> Background<Foreground<W>> {
Background(bg, Foreground(fg, w))
}
pub(crate) fn bold <W: Render<Tui>> (on: bool, w: W) -> Bold<W> {
fn bold <W: Render<Tui>> (on: bool, w: W) -> Bold<W> {
Bold(on, w)
}
pub(crate) fn border <W: Render<Tui>, S: BorderStyle> (style: S, w: W) -> Bordered<S, W> {
fn border <W: Render<Tui>, S: BorderStyle> (style: S, w: W) -> Bordered<S, W> {
Bordered(style, w)
}
}
impl TuiStyle for Tui {}
pub struct Bold<W: Render<Tui>>(pub bool, W);
impl<W: Render<Tui>> Render<Tui> for Bold<W> {