From 04f76e38e06707a9bb6b0af414c3361423d71372 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Thu, 16 Mar 2023 11:41:51 +0100 Subject: [PATCH] feat(dtmm): Improve error dialog window Druid doesn't yet implement options necessary to create a "standard" message dialog. So for now, we'll have to approximate that with what we've got. Fixes #70. --- crates/dtmm/src/ui/window/dialog.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/crates/dtmm/src/ui/window/dialog.rs b/crates/dtmm/src/ui/window/dialog.rs index 64ce88d..0c2bc18 100644 --- a/crates/dtmm/src/ui/window/dialog.rs +++ b/crates/dtmm/src/ui/window/dialog.rs @@ -1,18 +1,22 @@ use color_eyre::Report; -use druid::widget::{Button, CrossAxisAlignment, Flex, Label, LineBreaking, MainAxisAlignment}; -use druid::{Data, WidgetExt, WindowDesc, WindowHandle, WindowLevel, WindowSizePolicy}; +use druid::widget::{CrossAxisAlignment, Flex, Label, LineBreaking, MainAxisAlignment}; +use druid::{Data, WidgetExt, WindowDesc, WindowHandle, WindowSizePolicy}; -const ERROR_DIALOG_SIZE: (f64, f64) = (750., 400.); +use crate::ui::widget::button::Button; -pub fn error(err: Report, parent: WindowHandle) -> WindowDesc { - let msg = format!("A critical error ocurred: {:?}", err); - let stripped = - strip_ansi_escapes::strip(msg.as_bytes()).expect("failed to strip ANSI in error"); - let msg = String::from_utf8_lossy(&stripped); +pub fn error(err: Report, _parent: WindowHandle) -> WindowDesc { + let msg = { + let msg = format!("A critical error ocurred: {:?}", err); + if let Ok(stripped) = strip_ansi_escapes::strip(msg.as_bytes()) { + String::from_utf8_lossy(&stripped).to_string() + } else { + msg + } + }; - let text = Label::new(msg.to_string()).with_line_break_mode(LineBreaking::WordWrap); + let text = Label::new(msg).with_line_break_mode(LineBreaking::WordWrap); - let button = Button::new("Ok") + let button = Button::with_label("Ok") .on_click(|ctx, _, _| { ctx.window().close(); }) @@ -29,9 +33,8 @@ pub fn error(err: Report, parent: WindowHandle) -> WindowDesc { WindowDesc::new(widget) .title("Error") - .with_min_size(ERROR_DIALOG_SIZE) - .resizable(false) + .show_titlebar(true) .window_size_policy(WindowSizePolicy::Content) .set_always_on_top(true) - .set_level(WindowLevel::Modal(parent)) + .resizable(false) } -- 2.45.3