Skip to content

Commit

Permalink
externalize render_border
Browse files Browse the repository at this point in the history
  • Loading branch information
junkdog committed Oct 20, 2024
1 parent d3f5edc commit e9a85d5
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 98 deletions.
14 changes: 14 additions & 0 deletions effect_timeline. txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parallel  *  ██████████████████████████████████████████████████████████████████████████████████████████
├ sequential  *  █████████████████████████████████████████████████████████████████ ▏ ▕
│ ├ sleep  *  █████████████████████████████████████████████████████████████████ ▏ ▕
│ └ parallel  *  ▏ ▏ ▏ ▐ ▏ ▕
│  ├ shader_fn cf-01 r#1 ▏ ▏ ▏ ▐ ▏ ▕
│  └ shader_fn_buf cf-01 r#1 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▐▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
└ sequential  *  ██████████████████████████████████████████████████████████████████████████████████████████
 ├ prolong_start  * r#1 ███████████████████████████████████████████████████████████████████▌ ▕
 │ └ fade_to  * r#1 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▐█▌▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
 └ fade_from  * r#1 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██████████████████████
 0ms 512ms 1025ms 1537ms 2050ms
 
  * all r#1 6x3+17+7 
 cf-01 outer(1:1) 
16 changes: 16 additions & 0 deletions key-press-fx.ansi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sequential  *  ██████████████████████████████████████████████████████████████████████████████████████████
└ parallel  *  ██████████████████████████████████████████████████████████████████████████████████████████
 ├ sequential  *  █████████████████████████████████████████████████████████████████ ▏ ▕
 │ ├ sleep  *  █████████████████████████████████████████████████████████████████ ▏ ▕
 │ └ shader_fn cf-01 r#1 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▐▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
 ├ sequential  *  █████████████████████████████████████████████████████████████████ ▏ ▕
 │ ├ sleep  *  █████████████████████████████████████████████████████████████████ ▏ ▕
 │ └ shader_fn_buf  * r#1 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▐▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
 └ sequential  *  ██████████████████████████████████████████████████████████████████████████████████████████
  ├ prolong_start  * r#1 ███████████████████████████████████████████████████████████████████▌ ▕
  │ └ fade_to  * r#1 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▐█▌▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
  └ fade_from  * r#1 ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██████████████████████
 0ms 512ms 1025ms 1537ms 2050ms
 
  * all r#1 6x3+17+7 
 cf-01 outer(1:1) 
51 changes: 35 additions & 16 deletions src/effect.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,55 @@
use ratatui::layout::Margin;
use ratatui::prelude::Widget;
use ratatui::style::{Color, Style};
use tachyonfx::{CellFilter, Duration, Effect, Interpolation};
use crate::styling::Catppuccin;
use crate::widget::{render_border, KeyCap, KeyCapWidget};

pub fn key_press<C: Into<Color>>(
key_press_delay: Duration,
key: KeyCap,
color: C
) -> Effect {
use tachyonfx::fx::*;

pub fn key_press<C: Into<Color>>(key_press_delay: Duration, color: C) -> Effect {
// border
let key_borders = CellFilter::Outer(Margin::new(1, 1));
let key_pad = CellFilter::Inner(Margin::new(0, 0));

let c = color.into();
let bg = Catppuccin::new().crust;

use tachyonfx::fx::*;
sequence(&[
prolong_start(key_press_delay,
fade_to(c, bg, (50, Interpolation::Linear))),
fade_from(c, bg, (500, Interpolation::CubicOut)),
])
parallel(&[
// redraw singular border around key
delay(key_press_delay, parallel(&[
clear_cells(Duration::from_millis(550)),
draw_single_border(key.clone(), Duration::from_millis(550)),
])).with_cell_selection(key_borders),
// "click" fade out
sequence(&[
prolong_start(key_press_delay,
fade_to(c, bg, (50, Interpolation::Linear))),
fade_from(c, bg, (500, Interpolation::SineOut)),
]),
]).with_area(key.area)
}

fn draw_single_border() -> Effect {
fn draw_single_border(key_cap: KeyCap, duration: Duration) -> Effect {
use tachyonfx::fx::*;
effect_fn_buf((), 1, |_state, ctx, cells| {
let a = ctx.area;
// draw nw corner
// draw ne corner
// draw sw corner
// draw se corner
// draw horizontal
// draw vertical
let border_style = Style::default().fg(Catppuccin::new().base);

effect_fn_buf((), duration, move |_state, ctx, buf| {
render_border(key_cap.clone(), border_style, buf)
})
}

fn clear_cells(duration: Duration) -> Effect {
use tachyonfx::fx::*;
effect_fn((), duration, |_state, _ctx, cells| {
cells.for_each(|(_, cell)| {
cell.set_char(' ');
});
})
}

mod shader {
Expand Down
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use ratatui::layout::Layout;
use ratatui::prelude::{Color, Frame, Line, Style, Stylize, Text, Widget};
use ratatui::widgets::{Block, Clear};
use tachyonfx::{fx, CenteredShrink, Duration, Effect, Shader};
use tachyonfx::widget::EffectTimeline;
use crate::event_handler::EventHandler;
use crate::styling::Catppuccin;
use crate::tui::Tui;
Expand All @@ -30,12 +31,12 @@ fn main() -> io::Result<()> {
let mut app = ExabindApp::new(events.sender());
let mut tui = Tui::new(ratatui::init(), events);

"exabind".char_indices().enumerate().for_each(|(i, c)| {
"exabind".char_indices().enumerate().for_each(|(i, (_, c))| {
let kbd = AnsiKeyboardTklLayout::default();
// let e = effect::key_press(Duration::from_millis(i as u32 * 150), Color::LightCyan)
// let e = effect::key_press(Duration::from_millis(i as u32 * 150), Color::from_u32(0xaaff55))
let e = effect::key_press(Duration::from_millis(i as u32 * 250), Catppuccin::new().sapphire)
.with_area(kbd.key_area(KeyCode::Char(c.1)));
let e = effect::key_press(Duration::from_millis(i as u32 * 250), kbd.key_cap(c), Catppuccin::new().sapphire);

let timeline = EffectTimeline::builder().effect(&e).build();
timeline.save_to_file("effect_timeline. txt", 120).unwrap();

app.register_effect(e);
});
Expand Down
62 changes: 31 additions & 31 deletions src/styling/Catpuccin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,6 @@ pub struct Catppuccin {
}

impl Catppuccin {
pub fn named_colors(&self) -> Vec<(&str, Color)> {
vec![
("rosewater", self.rosewater),
("flamingo", self.flamingo),
("pink", self.pink),
("mauve", self.mauve),
("red", self.red),
("maroon", self.maroon),
("peach", self.peach),
("yellow", self.yellow),
("green", self.green),
("teal", self.teal),
("sky", self.sky),
("sapphire", self.sapphire),
("blue", self.blue),
("lavender", self.lavender),
("text", self.text),
("subtext1", self.subtext1),
("subtext0", self.subtext0),
("overlay2", self.overlay2),
("overlay1", self.overlay1),
("overlay0", self.overlay0),
("surface2", self.surface2),
("surface1", self.surface1),
("surface0", self.surface0),
("base", self.base),
("mantle", self.mantle),
("crust", self.crust),
]
}

pub const fn new() -> Self {
Self {
rosewater: Color::from_u32(0xf5e0dc),
Expand Down Expand Up @@ -91,4 +60,35 @@ impl Catppuccin {
crust: Color::from_u32(0x11111b),
}
}

pub fn named_colors(&self) -> Vec<(&str, Color)> {
vec![
("rosewater", self.rosewater),
("flamingo", self.flamingo),
("pink", self.pink),
("mauve", self.mauve),
("red", self.red),
("maroon", self.maroon),
("peach", self.peach),
("yellow", self.yellow),
("green", self.green),
("teal", self.teal),
("sky", self.sky),
("sapphire", self.sapphire),
("blue", self.blue),
("lavender", self.lavender),
("text", self.text),
("subtext1", self.subtext1),
("subtext0", self.subtext0),
("overlay2", self.overlay2),
("overlay1", self.overlay1),
("overlay0", self.overlay0),
("surface2", self.surface2),
("surface1", self.surface1),
("surface0", self.surface0),
("base", self.base),
("mantle", self.mantle),
("crust", self.crust),
]
}
}
Loading

0 comments on commit e9a85d5

Please sign in to comment.