commit a4ec0982d2f4b6094b3972d9f480142fd76d5e75
parent a29277d263aaefb8f711495bb5832f73422ee445
Author: kernelkind <kernelkind@gmail.com>
Date: Tue, 29 Apr 2025 00:34:31 -0400
`ImagePulseTint` -> `PulseAlpha`
make it more generic to pulse alpha values, not necessarily image
tints
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
3 files changed, 23 insertions(+), 30 deletions(-)
diff --git a/crates/notedeck_ui/src/anim.rs b/crates/notedeck_ui/src/anim.rs
@@ -137,33 +137,24 @@ impl AnimationHelper {
}
}
-pub struct ImagePulseTint<'a> {
+pub struct PulseAlpha<'a> {
ctx: &'a egui::Context,
id: egui::Id,
- image: egui::Image<'a>,
- color_unmultiplied: &'a [u8; 3],
alpha_min: u8,
alpha_max: u8,
animation_speed: f32,
+ start_max_alpha: bool,
}
-impl<'a> ImagePulseTint<'a> {
- pub fn new(
- ctx: &'a egui::Context,
- id: egui::Id,
- image: egui::Image<'a>,
- color_unmultiplied: &'a [u8; 3],
- alpha_min: u8,
- alpha_max: u8,
- ) -> Self {
+impl<'a> PulseAlpha<'a> {
+ pub fn new(ctx: &'a egui::Context, id: egui::Id, alpha_min: u8, alpha_max: u8) -> Self {
Self {
ctx,
id,
- image,
- color_unmultiplied,
alpha_min,
alpha_max,
animation_speed: ANIM_SPEED,
+ start_max_alpha: false,
}
}
@@ -172,12 +163,19 @@ impl<'a> ImagePulseTint<'a> {
self
}
- pub fn animate(self) -> egui::Image<'a> {
+ pub fn start_max_alpha(mut self) -> Self {
+ self.start_max_alpha = true;
+ self
+ }
+
+ // returns the current alpha value for the frame
+ pub fn animate(self) -> u8 {
let pulse_direction = if let Some(pulse_dir) = self.ctx.data(|d| d.get_temp(self.id)) {
pulse_dir
} else {
- self.ctx.data_mut(|d| d.insert_temp(self.id, false));
- false
+ self.ctx
+ .data_mut(|d| d.insert_temp(self.id, self.start_max_alpha));
+ self.start_max_alpha
};
let alpha_min_f32 = self.alpha_min as f32;
@@ -196,14 +194,6 @@ impl<'a> ImagePulseTint<'a> {
.data_mut(|d| d.insert_temp(self.id, !pulse_direction));
}
- let alpha =
- (cur_val + alpha_min_f32).clamp(self.alpha_min as f32, self.alpha_max as f32) as u8;
-
- self.image.tint(egui::Color32::from_rgba_unmultiplied(
- self.color_unmultiplied[0],
- self.color_unmultiplied[1],
- self.color_unmultiplied[2],
- alpha,
- ))
+ (cur_val + alpha_min_f32).clamp(self.alpha_min as f32, self.alpha_max as f32) as u8
}
}
diff --git a/crates/notedeck_ui/src/lib.rs b/crates/notedeck_ui/src/lib.rs
@@ -13,7 +13,7 @@ pub mod profile;
mod username;
pub mod widgets;
-pub use anim::{AnimationHelper, ImagePulseTint};
+pub use anim::{AnimationHelper, PulseAlpha};
pub use mention::Mention;
pub use note::{NoteContents, NoteOptions, NoteView};
pub use profile::{ProfilePic, ProfilePreview};
diff --git a/crates/notedeck_ui/src/note/mod.rs b/crates/notedeck_ui/src/note/mod.rs
@@ -5,8 +5,8 @@ pub mod reply_description;
use crate::jobs::JobsCache;
use crate::{
- profile::name::one_line_display_name_widget, widgets::x_button, ImagePulseTint, ProfilePic,
- ProfilePreview, Username,
+ profile::name::one_line_display_name_widget, widgets::x_button, ProfilePic, ProfilePreview,
+ PulseAlpha, Username,
};
pub use contents::{render_note_contents, render_note_preview, NoteContents};
@@ -807,9 +807,12 @@ fn zap_button(state: AnyZapState, noteid: &[u8; 32]) -> impl egui::Widget + use<
}
AnyZapState::Pending => {
let alpha_min = if ui.visuals().dark_mode { 50 } else { 180 };
- img = ImagePulseTint::new(&ctx, id, img, &[0xFF, 0xB7, 0x57], alpha_min, 255)
+ let cur_alpha = PulseAlpha::new(&ctx, id, alpha_min, 255)
.with_speed(0.35)
.animate();
+
+ let cur_color = egui::Color32::from_rgba_unmultiplied(0xFF, 0xB7, 0x57, cur_alpha);
+ img = img.tint(cur_color);
}
AnyZapState::LocalOnly => {
img = img.tint(egui::Color32::from_rgb(0xFF, 0xB7, 0x57));