Skip to content

Commit

Permalink
style(ui): add a simple shader effect via tachyonfx
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Oct 3, 2024
1 parent f0dba6e commit d56861e
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 4 deletions.
95 changes: 95 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ vt100 = "0.15.2"
rust-embed = { version = "8.5.0", features = ["compression", "debug-embed"] }
color-eyre = "0.6.3"
clap = { version = "4.5.17", features = ["derive", "env", "wrap_help", "cargo"] }
tachyonfx = "0.7.0"

[profile.dev]
opt-level = 0
Expand Down
23 changes: 19 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use std::{
io::{BufReader, Cursor},
time::{Duration, Instant},
};
use tachyonfx::{
fx::{self},
Duration as FxDuration, Effect, EffectRenderer, Interpolation, Shader,
};
use vt100::Parser;

use crate::{
Expand Down Expand Up @@ -43,11 +47,14 @@ pub struct App {
pub frame_interval: Duration,
/// FPS counter widget.
pub fps: Fps,
/// Terminal effect.
pub effect: Effect,
}

impl App {
/// Construct a new instance of [`App`].
pub fn new(event_handler: EventHandler, args: Args) -> Self {
let effect = fx::coalesce((800, Interpolation::SineOut));
Self {
is_running: true,
is_toggled: true,
Expand All @@ -58,6 +65,7 @@ impl App {
animation_area: Rect::default(),
frame_interval: Duration::from_secs_f32(1.0 / args.fps),
fps: Fps::default(),
effect,
args,
}
}
Expand Down Expand Up @@ -203,6 +211,11 @@ impl App {
.position(Position::Bottom),
);

self.animation_area = area[1].inner(Margin {
vertical: 1,
horizontal: 1,
});

if !self.animation.is_rendered {
block = block.title(
Title::from(Line::from(vec![
Expand All @@ -218,11 +231,12 @@ impl App {
}

frame.render_widget(block, area[1]);
self.animation_area = area[1].inner(Margin {
vertical: 1,
horizontal: 1,
});
frame.render_widget(&mut self.animation, self.animation_area);
frame.render_effect(
&mut self.effect,
self.animation_area,
FxDuration::from_millis(100),
);
}

pub fn start_animation(&mut self) {
Expand All @@ -237,5 +251,6 @@ impl App {
parser: Parser::new(self.animation_area.height, self.animation_area.width, 0),
buffer: String::new(),
};
self.effect.reset();
}
}

0 comments on commit d56861e

Please sign in to comment.