Switch to the widget builder pattern on all remaining layouts (#1346)

* Prefer widget builder pattern

* Nits

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2023-07-31 23:21:42 -07:00
committed by GitHub
co-authored by Keavon Chambers
parent 40f9a7d051
commit de27f2c006
30 changed files with 714 additions and 1365 deletions
@@ -1,8 +1,5 @@
use crate::messages::layout::utility_types::layout_widget::{Layout, LayoutGroup, Widget, WidgetCallback, WidgetHolder, WidgetLayout};
use crate::messages::layout::utility_types::misc::LayoutTarget;
use crate::messages::layout::utility_types::widgets::button_widgets::TextButton;
use crate::messages::layout::utility_types::widgets::input_widgets::{CheckboxInput, NumberInput, TextInput};
use crate::messages::layout::utility_types::widgets::label_widgets::{Separator, SeparatorDirection, SeparatorType, TextLabel};
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::prelude::*;
/// A dialog to allow users to customize Graphite editor options
@@ -31,107 +28,62 @@ impl PreferencesDialogMessageHandler {
fn properties(&self, preferences: &PreferencesMessageHandler) -> Layout {
let zoom_with_scroll = vec![
WidgetHolder::new(Widget::TextLabel(TextLabel {
value: "Input".into(),
min_width: 60,
italic: true,
..Default::default()
})),
WidgetHolder::new(Widget::TextLabel(TextLabel {
value: "Zoom with Scroll".into(),
table_align: true,
..Default::default()
})),
WidgetHolder::new(Widget::Separator(Separator {
separator_type: SeparatorType::Unrelated,
direction: SeparatorDirection::Horizontal,
})),
WidgetHolder::new(Widget::CheckboxInput(CheckboxInput {
checked: preferences.zoom_with_scroll,
tooltip: "Use the scroll wheel for zooming instead of vertically panning (not recommended for trackpads)".into(),
on_update: WidgetCallback::new(|checkbox_input: &CheckboxInput| {
TextLabel::new("Input").min_width(60).italic(true).widget_holder(),
TextLabel::new("Zoom with Scroll").table_align(true).widget_holder(),
WidgetHolder::unrelated_separator(),
CheckboxInput::new(preferences.zoom_with_scroll)
.tooltip("Use the scroll wheel for zooming instead of vertically panning (not recommended for trackpads)")
.on_update(|checkbox_input: &CheckboxInput| {
PreferencesMessage::ModifyLayout {
zoom_with_scroll: checkbox_input.checked,
}
.into()
}),
..Default::default()
})),
})
.widget_holder(),
];
let imaginate_server_hostname = vec![
WidgetHolder::new(Widget::TextLabel(TextLabel {
value: "Imaginate".into(),
min_width: 60,
italic: true,
..Default::default()
})),
WidgetHolder::new(Widget::TextLabel(TextLabel {
value: "Server Hostname".into(),
table_align: true,
..Default::default()
})),
WidgetHolder::new(Widget::Separator(Separator {
separator_type: SeparatorType::Unrelated,
direction: SeparatorDirection::Horizontal,
})),
WidgetHolder::new(Widget::TextInput(TextInput {
value: preferences.imaginate_server_hostname.clone(),
min_width: 200,
on_update: WidgetCallback::new(|text_input: &TextInput| PreferencesMessage::ImaginateServerHostname { hostname: text_input.value.clone() }.into()),
..Default::default()
})),
TextLabel::new("Imaginate").min_width(60).italic(true).widget_holder(),
TextLabel::new("Server Hostname").table_align(true).widget_holder(),
WidgetHolder::unrelated_separator(),
TextInput::new(&preferences.imaginate_server_hostname)
.min_width(200)
.on_update(|text_input: &TextInput| PreferencesMessage::ImaginateServerHostname { hostname: text_input.value.clone() }.into())
.widget_holder(),
];
let imaginate_refresh_frequency = vec![
WidgetHolder::new(Widget::TextLabel(TextLabel { min_width: 60, ..Default::default() })),
WidgetHolder::new(Widget::TextLabel(TextLabel {
value: "Refresh Frequency".into(),
table_align: true,
..Default::default()
})),
WidgetHolder::new(Widget::Separator(Separator {
separator_type: SeparatorType::Unrelated,
direction: SeparatorDirection::Horizontal,
})),
WidgetHolder::new(Widget::NumberInput(NumberInput {
unit: " seconds".into(),
value: Some(preferences.imaginate_refresh_frequency),
min: Some(0.),
min_width: 200,
on_update: WidgetCallback::new(|number_input: &NumberInput| PreferencesMessage::ImaginateRefreshFrequency { seconds: number_input.value.unwrap() }.into()),
..Default::default()
})),
TextLabel::new("").min_width(60).widget_holder(),
TextLabel::new("Refresh Frequency").table_align(true).widget_holder(),
WidgetHolder::unrelated_separator(),
NumberInput::new(Some(preferences.imaginate_refresh_frequency))
.unit(" seconds")
.min(0.)
.min_width(200)
.on_update(|number_input: &NumberInput| PreferencesMessage::ImaginateRefreshFrequency { seconds: number_input.value.unwrap() }.into())
.widget_holder(),
];
let button_widgets = vec![
WidgetHolder::new(Widget::TextButton(TextButton {
label: "Ok".to_string(),
min_width: 96,
emphasized: true,
on_update: WidgetCallback::new(|_| {
TextButton::new("Ok")
.min_width(96)
.emphasized(true)
.on_update(|_| {
DialogMessage::CloseDialogAndThen {
followups: vec![PreferencesDialogMessage::Confirm.into()],
}
.into()
}),
..Default::default()
})),
WidgetHolder::new(Widget::TextButton(TextButton {
label: "Reset to Defaults".to_string(),
min_width: 96,
on_update: WidgetCallback::new(|_| PreferencesMessage::ResetToDefaults.into()),
..Default::default()
})),
})
.widget_holder(),
TextButton::new("Reset to Defaults")
.min_width(96)
.on_update(|_| PreferencesMessage::ResetToDefaults.into())
.widget_holder(),
];
Layout::WidgetLayout(WidgetLayout::new(vec![
LayoutGroup::Row {
widgets: vec![WidgetHolder::new(Widget::TextLabel(TextLabel {
value: "Editor Preferences".to_string(),
bold: true,
..Default::default()
}))],
widgets: vec![TextLabel::new("Editor Preferences").bold(true).widget_holder()],
},
LayoutGroup::Row { widgets: zoom_with_scroll },
LayoutGroup::Row { widgets: imaginate_server_hostname },