Skip to content

Commit 14aa936

Browse files
committed
feat: change buttons
1 parent a2b84c1 commit 14aa936

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

src/app.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ impl ObamifyApp {
267267
get_presets()
268268
};
269269

270+
let has_obamified_once = if let Some(storage) = cc.storage {
271+
eframe::get_value::<bool>(storage, "has_obamified_once").unwrap_or(false)
272+
} else {
273+
false
274+
};
275+
270276
#[cfg(target_arch = "wasm32")]
271277
let random_preset = (js_sys::Math::random() * (presets.len() as f64)) as usize;
272278

@@ -792,7 +798,7 @@ impl ObamifyApp {
792798
preview_image: None,
793799
#[cfg(not(target_arch = "wasm32"))]
794800
stroke_count: 0,
795-
gui: gui::GuiState::default(presets, random_preset),
801+
gui: gui::GuiState::default(presets, random_preset, has_obamified_once),
796802
frame_count: 0,
797803
#[cfg(not(target_arch = "wasm32"))]
798804
current_drawing_id: Arc::new(AtomicU32::new(0)),

src/app/gui.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,16 @@ pub(crate) struct GuiState {
5454
configuring_generation: Option<(SourceImg, GenerationSettings, GuiImageCache)>,
5555
pub current_preset: usize,
5656
error_message: Option<String>,
57+
58+
has_obamified_once: bool,
5759
}
5860

5961
impl GuiState {
60-
pub fn default(presets: Vec<Preset>, current_preset: usize) -> GuiState {
62+
pub fn default(
63+
presets: Vec<Preset>,
64+
current_preset: usize,
65+
has_obamified_once: bool,
66+
) -> GuiState {
6167
GuiState {
6268
animate: true,
6369
//fps_text: String::new(),
@@ -75,6 +81,7 @@ impl GuiState {
7581
configuring_generation: None,
7682
current_preset,
7783
error_message: None,
84+
has_obamified_once,
7885
}
7986
}
8087

@@ -128,6 +135,7 @@ fn hide_icons() {
128135
impl App for ObamifyApp {
129136
fn save(&mut self, storage: &mut dyn eframe::Storage) {
130137
eframe::set_value(storage, "presets", &self.gui.presets);
138+
eframe::set_value(storage, "has_obamified_once", &self.gui.has_obamified_once);
131139
}
132140
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame) {
133141
let Some(rs) = frame.wgpu_render_state() else {
@@ -331,7 +339,14 @@ impl App for ObamifyApp {
331339
});
332340
ui.separator();
333341

334-
if ui.button("save gif").clicked() {
342+
if ui
343+
.button(if self.reverse {
344+
"save reverse gif"
345+
} else {
346+
"save gif"
347+
})
348+
.clicked()
349+
{
335350
self.gif_recorder.status = GifStatus::Recording;
336351
self.gif_recorder.encoder = None;
337352
if let Err(err) = self
@@ -460,7 +475,25 @@ impl App for ObamifyApp {
460475
}
461476
});
462477

463-
if ui.button("obamify new image").clicked() {
478+
// Make button glow if user hasn't obamified once
479+
let button_response = if !self.gui.has_obamified_once {
480+
// Create a glowing effect by animating the button outline
481+
let time = ui.input(|i| i.time);
482+
let pulse = ((time * 2.0).sin() * 0.5 + 0.5) as f32;
483+
let glow_color = egui::Color32::from_rgb(
484+
(30.0 + pulse * 100.0) as u8,
485+
(120.0 + pulse * 135.0) as u8,
486+
(200.0 + pulse * 55.0) as u8,
487+
);
488+
489+
let button = egui::Button::new("obamify new image")
490+
.stroke(egui::Stroke::new(1.0, glow_color));
491+
ui.add(button)
492+
} else {
493+
ui.button("obamify new image")
494+
};
495+
496+
if button_response.clicked() {
464497
// open file select
465498
prompt_image(
466499
"choose image to obamify",
@@ -793,6 +826,7 @@ impl App for ObamifyApp {
793826
self.gui.presets.len() - 1,
794827
);
795828
self.gui.animate = true;
829+
self.gui.has_obamified_once = true;
796830
self.gui.hide_progress_modal();
797831
ui.close();
798832
break;

0 commit comments

Comments
 (0)