Skip to content

Commit

Permalink
add fx::translate_buf
Browse files Browse the repository at this point in the history
  • Loading branch information
junkdog committed Aug 15, 2024
1 parent e54ac7b commit 20b508d
Show file tree
Hide file tree
Showing 5 changed files with 438 additions and 5 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ The effect timeline widget visualizes the composition of effects. It also suppor
widget as an ansi-escaped string, suitable for saving to a file or straight to `println!()`.

### Added
- `widget::EffectTimeline`: a widget for visualizing the composition of effects.
- `EffectTimeline::save_to_file()`: saves the effect timeline to a file.
- `fx::offscreen_buffer()`: wraps an existing effect and redirects its rendering
to a separate buffer. This allows for more complex effect compositions and can
improve performance for certain types of effects.
- `fx::translate_buf()`: translates the contents of an auxiliary buffer onto the main buffer.
- `widget::EffectTimeline`: a widget for visualizing the composition of effects.
- `EffectTimeline::save_to_file()`: saves the effect timeline to a file.
- `BufferRenderer` trait: enables rendering of one buffer onto another with offset support.
This allows for more complex composition of UI elements and effects.
- fn `blit_buffer()`: copies the contents of a source buffer onto a destination buffer with a specified offset.
Expand Down
29 changes: 28 additions & 1 deletion src/fx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cell::RefCell;
use std::rc::Rc;
use std::time::Duration;
use ratatui::buffer::Buffer;
use ratatui::layout::Size;
use ratatui::layout::{Offset, Size};
use ratatui::style::Color;

pub use glitch::Glitch;
Expand All @@ -26,6 +26,7 @@ use crate::fx::resize::ResizeArea;
use crate::fx::sleep::Sleep;
use crate::fx::sweep_in::SweepIn;
use crate::fx::temporary::{IntoTemporaryEffect, TemporaryEffect};
use crate::fx::translate_buffer::TranslateBuffer;

mod ansi256;
mod consume_tick;
Expand All @@ -41,6 +42,7 @@ mod sleep;
mod sweep_in;
mod temporary;
mod translate;
mod translate_buffer;
mod hsl_shift;
mod shader_fn;
mod slide;
Expand Down Expand Up @@ -345,6 +347,31 @@ pub fn translate<T: Into<EffectTimer>>(
translate::Translate::new(fx, translate_by, timer.into()).into_effect()
}

/// Creates an effect that translates the contents of an auxiliary buffer onto the main buffer.
///
/// This function creates a `TranslateBuffer` shader, which efficiently translates pre-rendered
/// content without re-rendering it on every frame. It's particularly useful for large or complex
/// content that doesn't change frequently.
///
/// # Arguments
///
/// * `translate_by` - An `Offset` specifying the final translation amount.
/// * `timer` - Specifies the duration and interpolation of the translation effect. Can be any type
/// that implements `Into<EffectTimer>`.
/// * `aux_buffer` - A shared reference to the auxiliary buffer containing the pre-rendered content
/// to be translated.
///
/// # Returns
///
/// Returns an `Effect` that can be used with other effects or applied directly to a buffer.
pub fn translate_buffer<T: Into<EffectTimer>>(
translate_by: Offset,
timer: T,
aux_buffer: Rc<RefCell<Buffer>>,
) -> Effect {
TranslateBuffer::new(aux_buffer, translate_by, timer.into()).into_effect()
}

/// Resizes the area of the wrapped effect to the specified dimensions over a specified duration.
///
/// This function creates a resizing effect that changes the dimensions of an existing effect's
Expand Down
Loading

0 comments on commit 20b508d

Please sign in to comment.