mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-03 21:08:18 +00:00
[wip]feat: attempt implementing CheckboxInputData struct
This commit is contained in:
parent
ca48604991
commit
2a481887fc
5 changed files with 43 additions and 15 deletions
|
@ -1,7 +1,6 @@
|
|||
use crate::messages::input_mapper::utility_types::misc::ActionKeys;
|
||||
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::WidgetLayout;
|
||||
use crate::messages::portfolio::document::node_graph::FrontendGraphDataType;
|
||||
|
||||
use graphite_proc_macros::WidgetBuilder;
|
||||
|
|
|
@ -12,6 +12,9 @@ use serde::{Deserialize, Serialize};
|
|||
#[derive(Clone, Derivative, Serialize, Deserialize, WidgetBuilder, specta::Type)]
|
||||
#[derivative(Debug, PartialEq)]
|
||||
pub struct CheckboxInput {
|
||||
#[widget_builder(constructor)]
|
||||
pub entries: CheckboxInputEntries,
|
||||
|
||||
#[widget_builder(constructor)]
|
||||
pub checked: bool,
|
||||
|
||||
|
@ -33,6 +36,7 @@ pub struct CheckboxInput {
|
|||
impl Default for CheckboxInput {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
entries: Vec::new(),
|
||||
checked: false,
|
||||
disabled: false,
|
||||
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)]
|
||||
#[derivative(Debug, PartialEq, Default)]
|
||||
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::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::widget_prelude::{CheckboxEntryData, CheckboxInput};
|
||||
use crate::messages::layout::utility_types::widgets::button_widgets::{IconButton, PopoverButton};
|
||||
use crate::messages::layout::utility_types::widgets::input_widgets::{
|
||||
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()),
|
||||
..Default::default()
|
||||
})),
|
||||
// this isn't working, why?
|
||||
WidgetHolder::new(Widget::PopoverButton(PopoverButton {
|
||||
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 {
|
||||
widgets: vec![WidgetHolder::new(Widget::DropdownInput(DropdownInput {
|
||||
widgets: vec![WidgetHolder::new(Widget::CheckboxInput(CheckboxInput {
|
||||
entries: vec![vec![
|
||||
DropdownEntryData {
|
||||
CheckboxEntryData {
|
||||
// TODO: perform the requisite operations instead of NoOp
|
||||
checked: self.snapping_enabled,
|
||||
label: SnappingOptions::BoundingBoxes.to_string(),
|
||||
on_update: WidgetCallback::new(|_| {
|
||||
info!("Bouding boxes");
|
||||
info!("Bounding Boxes");
|
||||
// Message::Tool(ToolMessage)
|
||||
Message::NoOp
|
||||
}),
|
||||
..DropdownEntryData::default()
|
||||
..CheckboxInput::default()
|
||||
},
|
||||
DropdownEntryData {
|
||||
CheckboxEntryData {
|
||||
checked: self.snapping_enabled,
|
||||
label: SnappingOptions::Nodes.to_string(),
|
||||
on_update: WidgetCallback::new(|_| {
|
||||
info!("Nodes");
|
||||
Message::NoOp
|
||||
}),
|
||||
..DropdownEntryData::default()
|
||||
..CheckboxInput::default()
|
||||
},
|
||||
]],
|
||||
selected_index: Some(0_u32),
|
||||
draw_icon: false,
|
||||
interactive: true,
|
||||
..Default::default()
|
||||
}))],
|
||||
}],
|
||||
|
|
|
@ -141,8 +141,8 @@
|
|||
{#if popoverButton}
|
||||
<PopoverButton {...exclude(popoverButton, ["header", "text", "optionsWidget"])}>
|
||||
<TextLabel bold={true}>{popoverButton.header}</TextLabel>
|
||||
{#if popoverButton.optionsWidget}
|
||||
<WidgetLayout layout={ { layout: popoverButton.optionsWidget, layoutTarget: layoutTarget} } />
|
||||
{#if popoverButton.optionsWidget}
|
||||
<WidgetLayout layout={{ layout: popoverButton.optionsWidget, layoutTarget: layoutTarget }} />
|
||||
{:else}
|
||||
<TextLabel multiline={true}>{popoverButton.text}</TextLabel>
|
||||
{/if}
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
<LayoutRow class="popover-button">
|
||||
<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">
|
||||
<slot />
|
||||
</FloatingMenu>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue