Feat: add tachyonFX animations
This commit is contained in:
54
src/state/effects.rs
Normal file
54
src/state/effects.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use tachyonfx::{fx, Interpolation, Motion};
|
||||
|
||||
use crate::page::Page;
|
||||
use crate::state::ui::UiState;
|
||||
use crate::state::Modal;
|
||||
use crate::theme;
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum FxId {
|
||||
#[default]
|
||||
PageTransition,
|
||||
}
|
||||
|
||||
pub fn tick_effects(ui: &mut UiState, page: Page) {
|
||||
if !ui.show_title && ui.prev_show_title {
|
||||
ui.effects.borrow_mut().add_unique_effect(
|
||||
FxId::PageTransition,
|
||||
fx::coalesce((200, Interpolation::QuadOut)),
|
||||
);
|
||||
}
|
||||
ui.prev_show_title = ui.show_title;
|
||||
|
||||
let modal_open = !matches!(ui.modal, Modal::None);
|
||||
|
||||
if modal_open && !ui.prev_modal_open {
|
||||
let bg = theme::get().ui.bg;
|
||||
*ui.modal_fx.borrow_mut() = Some(fx::fade_from_fg(bg, (50, Interpolation::QuadOut)));
|
||||
}
|
||||
ui.prev_modal_open = modal_open;
|
||||
|
||||
if page != ui.prev_page {
|
||||
let direction = page_direction(ui.prev_page, page);
|
||||
let bg = theme::get().ui.bg;
|
||||
ui.effects.borrow_mut().add_unique_effect(
|
||||
FxId::PageTransition,
|
||||
fx::sweep_in(direction, 10, 0, bg, (200, Interpolation::QuadOut)),
|
||||
);
|
||||
ui.prev_page = page;
|
||||
}
|
||||
}
|
||||
|
||||
fn page_direction(from: Page, to: Page) -> Motion {
|
||||
let (fc, fr) = from.grid_pos();
|
||||
let (tc, tr) = to.grid_pos();
|
||||
if tc > fc {
|
||||
Motion::LeftToRight
|
||||
} else if tc < fc {
|
||||
Motion::RightToLeft
|
||||
} else if tr > fr {
|
||||
Motion::UpToDown
|
||||
} else {
|
||||
Motion::DownToUp
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ pub trait CyclicEnum: Sized + Copy + PartialEq + 'static {
|
||||
pub mod audio;
|
||||
pub mod color_scheme;
|
||||
pub mod editor;
|
||||
pub mod effects;
|
||||
pub mod file_browser;
|
||||
pub mod live_keys;
|
||||
pub mod modal;
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
use std::cell::RefCell;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use cagire_ratatui::Sparkles;
|
||||
use tachyonfx::{fx, Effect, EffectManager, Interpolation};
|
||||
|
||||
use crate::page::Page;
|
||||
use crate::state::effects::FxId;
|
||||
use crate::state::{ColorScheme, Modal};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||
@@ -48,6 +52,12 @@ pub struct UiState {
|
||||
pub minimap_until: Option<Instant>,
|
||||
pub color_scheme: ColorScheme,
|
||||
pub hue_rotation: f32,
|
||||
pub effects: RefCell<EffectManager<FxId>>,
|
||||
pub modal_fx: RefCell<Option<Effect>>,
|
||||
pub title_fx: RefCell<Option<Effect>>,
|
||||
pub prev_modal_open: bool,
|
||||
pub prev_page: Page,
|
||||
pub prev_show_title: bool,
|
||||
}
|
||||
|
||||
impl Default for UiState {
|
||||
@@ -74,6 +84,12 @@ impl Default for UiState {
|
||||
minimap_until: None,
|
||||
color_scheme: ColorScheme::default(),
|
||||
hue_rotation: 0.0,
|
||||
effects: RefCell::new(EffectManager::default()),
|
||||
modal_fx: RefCell::new(None),
|
||||
title_fx: RefCell::new(Some(fx::coalesce((400, Interpolation::QuadOut)))),
|
||||
prev_modal_open: false,
|
||||
prev_page: Page::default(),
|
||||
prev_show_title: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user