@@ -31,7 +31,7 @@ use arboard::Clipboard;
31
31
use constants:: { FONT_ID , TEXT_COLOR , VALUE_PADDING } ;
32
32
use eframe:: { egui, IconData } ;
33
33
34
- use egui:: { gui_zoom, vec2, Context , Response , Sense , Ui } ;
34
+ use egui:: { gui_zoom, vec2, Align2 , Context , Response , Sense , Ui } ;
35
35
use env_gui:: insert_to_env;
36
36
use num_rational:: Rational64 ;
37
37
use std:: collections:: HashMap ;
@@ -45,7 +45,7 @@ use crate::fourier::Fourier;
45
45
use crate :: fractal_clock:: FractalClock ;
46
46
use clap:: builder:: TypedValueParser ;
47
47
use clap:: Parser ;
48
- use egui_toast:: Toasts ;
48
+ use egui_toast:: { Toast , ToastKind , ToastOptions , Toasts } ;
49
49
50
50
/// Field for matrices.
51
51
type F = Rational64 ;
@@ -156,11 +156,9 @@ impl<K: MatrixNumber> eframe::App for MatrixApp<K> {
156
156
gui_zoom:: zoom_with_keyboard_shortcuts ( ctx, frame. info ( ) . native_pixels_per_point ) ;
157
157
}
158
158
159
- let window_size = frame. info ( ) . window_info . size ;
160
159
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 ) ;
164
162
165
163
let ( _top_menu, new_locale) = display_menu_bar ( ctx, & mut self . state , & self . locale ) ;
166
164
display_editor :: < K > ( ctx, & mut self . state , & self . locale ) ;
@@ -443,13 +441,15 @@ fn set_clipboard(
443
441
match message {
444
442
Ok ( latex) => match clipboard. set_text ( latex) {
445
443
Ok ( _) => {
446
- toasts. info (
444
+ toasts_info (
445
+ toasts,
447
446
locale. get_translated ( "LaTeX copied to clipboard" ) ,
448
447
CLIPBOARD_TOAST_DURATION ,
449
448
) ;
450
449
}
451
450
Err ( e) => {
452
- toasts. error (
451
+ toasts_error (
452
+ toasts,
453
453
locale. get_translated ( "Failed to copy LaTeX to clipboard" )
454
454
+ "\n "
455
455
+ e. to_string ( ) . as_str ( ) ,
@@ -458,7 +458,8 @@ fn set_clipboard(
458
458
}
459
459
} ,
460
460
Err ( e) => {
461
- toasts. error (
461
+ toasts_error (
462
+ toasts,
462
463
locale. get_translated ( "Failed to generate LaTeX" ) + "\n " + e. to_string ( ) . as_str ( ) ,
463
464
CLIPBOARD_TOAST_DURATION ,
464
465
) ;
@@ -484,7 +485,7 @@ fn display_shell<K: MatrixNumber>(
484
485
}
485
486
Err ( error) => {
486
487
println ! ( "{error}" ) ;
487
- toasts . error ( error. to_string ( ) , Duration :: from_secs ( 5 ) ) ;
488
+ toasts_error ( toasts , error. to_string ( ) , Duration :: from_secs ( 5 ) ) ;
488
489
}
489
490
} ;
490
491
@@ -521,3 +522,21 @@ fn display_shell<K: MatrixNumber>(
521
522
} ) ;
522
523
} ) ;
523
524
}
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