mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-07 04:48:11 +08:00
[wip]feat: attempt implementing CheckboxInputData struct
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
use crate::messages::input_mapper::utility_types::misc::ActionKeys;
|
use crate::messages::input_mapper::utility_types::misc::ActionKeys;
|
||||||
use crate::messages::layout::utility_types::layout_widget::WidgetCallback;
|
use crate::messages::layout::utility_types::layout_widget::WidgetCallback;
|
||||||
use crate::messages::layout::utility_types::widget_prelude::SubLayout;
|
use crate::messages::layout::utility_types::widget_prelude::SubLayout;
|
||||||
use crate::messages::layout::utility_types::widget_prelude::WidgetLayout;
|
|
||||||
use crate::messages::portfolio::document::node_graph::FrontendGraphDataType;
|
use crate::messages::portfolio::document::node_graph::FrontendGraphDataType;
|
||||||
|
|
||||||
use graphite_proc_macros::WidgetBuilder;
|
use graphite_proc_macros::WidgetBuilder;
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Clone, Derivative, Serialize, Deserialize, WidgetBuilder, specta::Type)]
|
#[derive(Clone, Derivative, Serialize, Deserialize, WidgetBuilder, specta::Type)]
|
||||||
#[derivative(Debug, PartialEq)]
|
#[derivative(Debug, PartialEq)]
|
||||||
pub struct CheckboxInput {
|
pub struct CheckboxInput {
|
||||||
|
#[widget_builder(constructor)]
|
||||||
|
pub entries: CheckboxInputEntries,
|
||||||
|
|
||||||
#[widget_builder(constructor)]
|
#[widget_builder(constructor)]
|
||||||
pub checked: bool,
|
pub checked: bool,
|
||||||
|
|
||||||
@@ -33,6 +36,7 @@ pub struct CheckboxInput {
|
|||||||
impl Default for CheckboxInput {
|
impl Default for CheckboxInput {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
entries: Vec::new(),
|
||||||
checked: false,
|
checked: false,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
icon: "Checkmark".into(),
|
icon: "Checkmark".into(),
|
||||||
@@ -43,6 +47,31 @@ impl Default for CheckboxInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type CheckboxInputEntries = Vec<Vec<CheckboxEntryData>>;
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize, Deserialize, Derivative, Default, WidgetBuilder, specta::Type)]
|
||||||
|
#[derivative(Debug, PartialEq)]
|
||||||
|
#[widget_builder(not_widget_holder)]
|
||||||
|
pub struct CheckboxEntryData {
|
||||||
|
pub value: String,
|
||||||
|
|
||||||
|
#[widget_builder(constructor)]
|
||||||
|
pub label: String,
|
||||||
|
|
||||||
|
pub icon: String,
|
||||||
|
|
||||||
|
pub shortcut: Vec<String>,
|
||||||
|
|
||||||
|
pub disabled: bool,
|
||||||
|
|
||||||
|
pub checked: bool,
|
||||||
|
|
||||||
|
// Callbacks
|
||||||
|
#[serde(skip)]
|
||||||
|
#[derivative(Debug = "ignore", PartialEq = "ignore")]
|
||||||
|
pub on_update: WidgetCallback<()>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Derivative, Serialize, Deserialize, WidgetBuilder, specta::Type)]
|
#[derive(Clone, Derivative, Serialize, Deserialize, WidgetBuilder, specta::Type)]
|
||||||
#[derivative(Debug, PartialEq, Default)]
|
#[derivative(Debug, PartialEq, Default)]
|
||||||
pub struct ColorInput {
|
pub struct ColorInput {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::messages::frontend::utility_types::FileType;
|
|||||||
use crate::messages::input_mapper::utility_types::macros::action_keys;
|
use crate::messages::input_mapper::utility_types::macros::action_keys;
|
||||||
use crate::messages::layout::utility_types::layout_widget::{Layout, LayoutGroup, Widget, WidgetCallback, WidgetHolder, WidgetLayout};
|
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::misc::LayoutTarget;
|
||||||
|
use crate::messages::layout::utility_types::widget_prelude::{CheckboxEntryData, CheckboxInput};
|
||||||
use crate::messages::layout::utility_types::widgets::button_widgets::{IconButton, PopoverButton};
|
use crate::messages::layout::utility_types::widgets::button_widgets::{IconButton, PopoverButton};
|
||||||
use crate::messages::layout::utility_types::widgets::input_widgets::{
|
use crate::messages::layout::utility_types::widgets::input_widgets::{
|
||||||
DropdownEntryData, DropdownInput, NumberInput, NumberInputIncrementBehavior, NumberInputMode, OptionalInput, RadioEntryData, RadioInput,
|
DropdownEntryData, DropdownInput, NumberInput, NumberInputIncrementBehavior, NumberInputMode, OptionalInput, RadioEntryData, RadioInput,
|
||||||
@@ -1561,33 +1562,33 @@ impl DocumentMessageHandler {
|
|||||||
on_update: WidgetCallback::new(|optional_input: &OptionalInput| DocumentMessage::SetSnapping { snap: optional_input.checked }.into()),
|
on_update: WidgetCallback::new(|optional_input: &OptionalInput| DocumentMessage::SetSnapping { snap: optional_input.checked }.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})),
|
})),
|
||||||
// this isn't working, why?
|
|
||||||
WidgetHolder::new(Widget::PopoverButton(PopoverButton {
|
WidgetHolder::new(Widget::PopoverButton(PopoverButton {
|
||||||
header: "Snapping".into(),
|
header: "Snapping".into(),
|
||||||
text: "Select the vector to snap to.".into(), // TODO: check whether this is an apt description
|
text: "Select the vector to snap to.".into(),
|
||||||
options_widget: vec![LayoutGroup::Row {
|
options_widget: vec![LayoutGroup::Row {
|
||||||
widgets: vec![WidgetHolder::new(Widget::DropdownInput(DropdownInput {
|
widgets: vec![WidgetHolder::new(Widget::CheckboxInput(CheckboxInput {
|
||||||
entries: vec![vec![
|
entries: vec![vec![
|
||||||
DropdownEntryData {
|
CheckboxEntryData {
|
||||||
|
// TODO: perform the requisite operations instead of NoOp
|
||||||
|
checked: self.snapping_enabled,
|
||||||
label: SnappingOptions::BoundingBoxes.to_string(),
|
label: SnappingOptions::BoundingBoxes.to_string(),
|
||||||
on_update: WidgetCallback::new(|_| {
|
on_update: WidgetCallback::new(|_| {
|
||||||
info!("Bouding boxes");
|
info!("Bounding Boxes");
|
||||||
|
// Message::Tool(ToolMessage)
|
||||||
Message::NoOp
|
Message::NoOp
|
||||||
}),
|
}),
|
||||||
..DropdownEntryData::default()
|
..CheckboxInput::default()
|
||||||
},
|
},
|
||||||
DropdownEntryData {
|
CheckboxEntryData {
|
||||||
|
checked: self.snapping_enabled,
|
||||||
label: SnappingOptions::Nodes.to_string(),
|
label: SnappingOptions::Nodes.to_string(),
|
||||||
on_update: WidgetCallback::new(|_| {
|
on_update: WidgetCallback::new(|_| {
|
||||||
info!("Nodes");
|
info!("Nodes");
|
||||||
Message::NoOp
|
Message::NoOp
|
||||||
}),
|
}),
|
||||||
..DropdownEntryData::default()
|
..CheckboxInput::default()
|
||||||
},
|
},
|
||||||
]],
|
]],
|
||||||
selected_index: Some(0_u32),
|
|
||||||
draw_icon: false,
|
|
||||||
interactive: true,
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}))],
|
}))],
|
||||||
}],
|
}],
|
||||||
|
|||||||
@@ -141,8 +141,8 @@
|
|||||||
{#if popoverButton}
|
{#if popoverButton}
|
||||||
<PopoverButton {...exclude(popoverButton, ["header", "text", "optionsWidget"])}>
|
<PopoverButton {...exclude(popoverButton, ["header", "text", "optionsWidget"])}>
|
||||||
<TextLabel bold={true}>{popoverButton.header}</TextLabel>
|
<TextLabel bold={true}>{popoverButton.header}</TextLabel>
|
||||||
{#if popoverButton.optionsWidget}
|
{#if popoverButton.optionsWidget}
|
||||||
<WidgetLayout layout={ { layout: popoverButton.optionsWidget, layoutTarget: layoutTarget} } />
|
<WidgetLayout layout={{ layout: popoverButton.optionsWidget, layoutTarget: layoutTarget }} />
|
||||||
{:else}
|
{:else}
|
||||||
<TextLabel multiline={true}>{popoverButton.text}</TextLabel>
|
<TextLabel multiline={true}>{popoverButton.text}</TextLabel>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
<LayoutRow class="popover-button">
|
<LayoutRow class="popover-button">
|
||||||
<IconButton classes={{ open }} {disabled} action={() => onClick()} icon={icon || "DropdownArrow"} size={16} {tooltip} data-floating-menu-spawner />
|
<IconButton classes={{ open }} {disabled} action={() => onClick()} icon={icon || "DropdownArrow"} size={16} {tooltip} data-floating-menu-spawner />
|
||||||
|
|
||||||
<FloatingMenu {open} on:open={({ detail }) => (open = detail)} type="Popover" direction="Bottom">
|
<FloatingMenu {open} on:open={({ detail }) => (open = detail)} type="Popover" direction="Bottom">
|
||||||
<slot />
|
<slot />
|
||||||
</FloatingMenu>
|
</FloatingMenu>
|
||||||
|
|||||||
Reference in New Issue
Block a user