Skip to content

Commit 420e23a

Browse files
authored
Boosted egui-taost to 0.7.0 (#55)
1 parent 0752bc3 commit 420e23a

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ time = "0.3"
3333
serde = { version = "1.0", features = ["derive"] }
3434
serde_json = "1.0"
3535
itertools = "0.10.5"
36-
egui-toast = "0.6.0"
36+
egui-toast = "0.7.0"

src/main.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use arboard::Clipboard;
3131
use constants::{FONT_ID, TEXT_COLOR, VALUE_PADDING};
3232
use eframe::{egui, IconData};
3333

34-
use egui::{gui_zoom, vec2, Context, Response, Sense, Ui};
34+
use egui::{gui_zoom, vec2, Align2, Context, Response, Sense, Ui};
3535
use env_gui::insert_to_env;
3636
use num_rational::Rational64;
3737
use std::collections::HashMap;
@@ -45,7 +45,7 @@ use crate::fourier::Fourier;
4545
use crate::fractal_clock::FractalClock;
4646
use clap::builder::TypedValueParser;
4747
use clap::Parser;
48-
use egui_toast::Toasts;
48+
use egui_toast::{Toast, ToastKind, ToastOptions, Toasts};
4949

5050
/// Field for matrices.
5151
type F = Rational64;
@@ -156,11 +156,9 @@ impl<K: MatrixNumber> eframe::App for MatrixApp<K> {
156156
gui_zoom::zoom_with_keyboard_shortcuts(ctx, frame.info().native_pixels_per_point);
157157
}
158158

159-
let window_size = frame.info().window_info.size;
160159
self.state.toasts = Toasts::default()
161-
.anchor((window_size.x - 10., window_size.y - 40.))
162-
.direction(egui::Direction::BottomUp)
163-
.align_to_end(true);
160+
.anchor(Align2::RIGHT_BOTTOM, (-10.0, -40.0))
161+
.direction(egui::Direction::BottomUp);
164162

165163
let (_top_menu, new_locale) = display_menu_bar(ctx, &mut self.state, &self.locale);
166164
display_editor::<K>(ctx, &mut self.state, &self.locale);
@@ -443,13 +441,15 @@ fn set_clipboard(
443441
match message {
444442
Ok(latex) => match clipboard.set_text(latex) {
445443
Ok(_) => {
446-
toasts.info(
444+
toasts_info(
445+
toasts,
447446
locale.get_translated("LaTeX copied to clipboard"),
448447
CLIPBOARD_TOAST_DURATION,
449448
);
450449
}
451450
Err(e) => {
452-
toasts.error(
451+
toasts_error(
452+
toasts,
453453
locale.get_translated("Failed to copy LaTeX to clipboard")
454454
+ "\n"
455455
+ e.to_string().as_str(),
@@ -458,7 +458,8 @@ fn set_clipboard(
458458
}
459459
},
460460
Err(e) => {
461-
toasts.error(
461+
toasts_error(
462+
toasts,
462463
locale.get_translated("Failed to generate LaTeX") + "\n" + e.to_string().as_str(),
463464
CLIPBOARD_TOAST_DURATION,
464465
);
@@ -484,7 +485,7 @@ fn display_shell<K: MatrixNumber>(
484485
}
485486
Err(error) => {
486487
println!("{error}");
487-
toasts.error(error.to_string(), Duration::from_secs(5));
488+
toasts_error(toasts, error.to_string(), Duration::from_secs(5));
488489
}
489490
};
490491

@@ -521,3 +522,21 @@ fn display_shell<K: MatrixNumber>(
521522
});
522523
});
523524
}
525+
526+
fn toasts_add_kind(toasts: &mut Toasts, text: String, duration: Duration, kind: ToastKind) {
527+
toasts.add(Toast {
528+
text: text.into(),
529+
kind,
530+
options: ToastOptions::default()
531+
.duration(duration)
532+
.show_progress(true),
533+
});
534+
}
535+
536+
fn toasts_info(toasts: &mut Toasts, text: String, duration: Duration) {
537+
toasts_add_kind(toasts, text, duration, ToastKind::Info);
538+
}
539+
540+
fn toasts_error(toasts: &mut Toasts, text: String, duration: Duration) {
541+
toasts_add_kind(toasts, text, duration, ToastKind::Error);
542+
}

0 commit comments

Comments
 (0)