From 86f29e989de8419cb89fa507b434c76106750324 Mon Sep 17 00:00:00 2001 From: Sky Leite Date: Sun, 15 Sep 2024 10:39:05 -0300 Subject: [PATCH] Make system cursor optional Fixes an issue where running the program in a platform without a mouse cursor (like an embedded device) would crash with the following error: `called `Result::unwrap()` on an `Err` value: "CreateSystemCursor is not currently supported"` --- src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f1740fc..08ea8d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,14 +41,14 @@ impl RepaintSignal for Signal { } pub struct FusedCursor { - pub cursor: Cursor, + pub cursor: Option, pub icon: SystemCursor, } impl FusedCursor { pub fn new() -> Self { Self { - cursor: Cursor::from_system(SystemCursor::Arrow).unwrap(), + cursor: Cursor::from_system(SystemCursor::Arrow).ok(), icon: SystemCursor::Arrow, } } @@ -422,8 +422,10 @@ pub fn translate_cursor(fused: &mut FusedCursor, cursor_icon: egui::CursorIcon) }; if tmp_icon != fused.icon { - fused.cursor = Cursor::from_system(tmp_icon).unwrap(); + fused.cursor = Cursor::from_system(tmp_icon).ok(); fused.icon = tmp_icon; - fused.cursor.set(); + if let Some(cursor) = &fused.cursor { + cursor.set(); + } } }