mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 19:18:12 +08:00
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:
co-authored by
Keavon Chambers
parent
40f9a7d051
commit
de27f2c006
@@ -1,5 +1,6 @@
|
||||
use crate::messages::layout::utility_types::layout_widget::WidgetCallback;
|
||||
use crate::messages::layout::utility_types::widget_prelude::{ColorInput, IconButton, RadioEntryData, RadioInput, TextLabel, WidgetHolder};
|
||||
use crate::messages::prelude::Message;
|
||||
|
||||
use graphene_core::Color;
|
||||
|
||||
@@ -12,6 +13,7 @@ pub enum ToolColorType {
|
||||
Custom,
|
||||
}
|
||||
|
||||
/// Color selector widgets seen in [`LayoutTarget::ToolOptions`] bar.
|
||||
pub struct ToolColorOptions {
|
||||
pub custom_color: Option<Color>,
|
||||
pub primary_working_color: Option<Color>,
|
||||
@@ -62,19 +64,19 @@ impl ToolColorOptions {
|
||||
&self,
|
||||
label_text: impl Into<String>,
|
||||
color_allow_none: bool,
|
||||
reset_callback: WidgetCallback<IconButton>,
|
||||
reset_callback: impl Fn(&IconButton) -> Message + 'static + Send + Sync,
|
||||
radio_callback: fn(ToolColorType) -> WidgetCallback<()>,
|
||||
color_callback: WidgetCallback<ColorInput>,
|
||||
color_callback: impl Fn(&ColorInput) -> Message + 'static + Send + Sync,
|
||||
) -> Vec<WidgetHolder> {
|
||||
let mut widgets = vec![TextLabel::new(label_text).widget_holder()];
|
||||
|
||||
if !color_allow_none {
|
||||
widgets.push(WidgetHolder::unrelated_separator());
|
||||
} else {
|
||||
let mut reset = IconButton::new("CloseX", 12)
|
||||
let reset = IconButton::new("CloseX", 12)
|
||||
.disabled(self.custom_color.is_none() && self.color_type == ToolColorType::Custom)
|
||||
.tooltip("Clear Color");
|
||||
reset.on_update = reset_callback;
|
||||
.tooltip("Clear Color")
|
||||
.on_update(reset_callback);
|
||||
|
||||
widgets.push(WidgetHolder::related_separator());
|
||||
widgets.push(reset.widget_holder());
|
||||
@@ -97,8 +99,7 @@ impl ToolColorOptions {
|
||||
widgets.push(radio);
|
||||
widgets.push(WidgetHolder::related_separator());
|
||||
|
||||
let mut color_input = ColorInput::new(self.active_color()).allow_none(color_allow_none);
|
||||
color_input.on_update = color_callback;
|
||||
let color_input = ColorInput::new(self.active_color()).allow_none(color_allow_none).on_update(color_callback);
|
||||
widgets.push(color_input.widget_holder());
|
||||
|
||||
widgets
|
||||
|
||||
Reference in New Issue
Block a user