forked from 1b-agent/opencadstudio-upstream
Clean up Graphic Attributes palette
- Revert formatting, import/module reordering and unrelated rewrites outside the feature (command.rs, style.rs, paper.rs, view/mod.rs, properties.rs, dialog.rs, ValuePromptCommand); the new SVG icons stay. - Move the palette logic out of dialog.rs into update/graphic_attributes.rs. - Replace 14 loose app fields and ~50 Message variants by GraphicAttributesState (one Menu enum for the open drop-down) and a nested GraphicAttributesMsg / GradientMsg, like BlockPaletteMsg. - Share the selection -> line/fill handles -> unlocked edit path, reuse valid_block_name, the ribbon lineweight handler and fill_handles, and drop the unused GradientColorToggle, color_open and LineLinetypeScaleInput. - Linetype scale accepts any positive value (e.g. ISO pen widths 0.13, 0.18, 0.25, 0.35) instead of rounding to 0.1 with a 0.1 minimum. - Closing open boundaries and creating the fill is one undo step. - The close prompt also answers typed Y/N + Enter, a bare Enter (Yes) and Escape (cancel), not only the option buttons. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VgkJN8DEojuPTumAXLHotu
This commit is contained in:
17 files changed
+3478
-3992
No files matched your search
+5
-2
@@ -273,7 +273,10 @@ mod tests {
|
||||
fn default_docks_each_known_panel_on_an_edge() {
|
||||
let state = DockState::default();
|
||||
assert_eq!(state.location(PanelId::Properties), Some((DockSide::Left, 0)));
|
||||
assert_eq!(state.location(PanelId::GraphicAttributes), Some((DockSide::Left, 1)));
|
||||
assert_eq!(
|
||||
state.location(PanelId::GraphicAttributes),
|
||||
Some((DockSide::Left, 1))
|
||||
);
|
||||
assert_eq!(
|
||||
state.location(PanelId::BlockPalette),
|
||||
Some((DockSide::Right, 0))
|
||||
@@ -373,4 +376,4 @@ mod tests {
|
||||
assert_eq!(drop_index(10.0, 2, 900.0), 0);
|
||||
assert_eq!(drop_index(890.0, 2, 900.0), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
+69
-70
@@ -10,7 +10,6 @@
|
||||
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};
|
||||
use std::{fmt, sync::Arc};
|
||||
|
||||
use crate::t;
|
||||
use crate::ui::ROW_H;
|
||||
use acadrust::types::{Color as AcadColor, LineWeight};
|
||||
use acadrust::Handle;
|
||||
@@ -21,6 +20,7 @@ use iced::widget::{
|
||||
use iced::{
|
||||
mouse, Background, Border, Color, Element, Length, Padding, Point, Rectangle, Size, Theme,
|
||||
};
|
||||
use crate::t;
|
||||
|
||||
// ── Row-height-derived constants ─────────────────────────────────────────
|
||||
const FONT_SZ: f32 = ROW_H * 0.42; // ≈11 px
|
||||
@@ -205,7 +205,7 @@ fn hatch_preview_scale(pattern: &crate::scene::model::hatch_model::HatchPattern)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn hatch_pattern_preview(
|
||||
fn hatch_pattern_preview(
|
||||
pattern: crate::scene::model::hatch_model::HatchPattern,
|
||||
height: f32,
|
||||
) -> Element<'static, Message> {
|
||||
@@ -213,9 +213,9 @@ pub(crate) fn hatch_pattern_preview(
|
||||
pattern,
|
||||
padding: 4.0,
|
||||
})
|
||||
.width(Length::Fill)
|
||||
.height(height)
|
||||
.into()
|
||||
.width(Length::Fill)
|
||||
.height(height)
|
||||
.into()
|
||||
}
|
||||
|
||||
pub(crate) fn compact_hatch_pattern_preview(
|
||||
@@ -237,8 +237,7 @@ fn hatch_pattern_matches(
|
||||
let query = search.trim();
|
||||
query.is_empty()
|
||||
|| entry.name.to_lowercase().contains(&query.to_lowercase())
|
||||
|| entry.description.to_lowercase()
|
||||
.contains(&query.to_lowercase())
|
||||
|| entry.description.to_lowercase().contains(&query.to_lowercase())
|
||||
}
|
||||
|
||||
pub(crate) fn filtered_hatch_patterns(
|
||||
@@ -412,7 +411,7 @@ impl FieldKey {
|
||||
}
|
||||
|
||||
/// Text-input widget id for one column of a named-parameter row.
|
||||
pub fn prop_param_field_id(index: usize, field: crate::ui::window::named_parameters::ParamField,) -> iced::widget::Id {
|
||||
pub fn prop_param_field_id(index: usize, field: crate::ui::window::named_parameters::ParamField) -> iced::widget::Id {
|
||||
use crate::ui::window::named_parameters::ParamField;
|
||||
let suffix = match field {
|
||||
ParamField::Name => "name",
|
||||
@@ -461,7 +460,7 @@ pub fn active_key_focused(
|
||||
/// its field key in O(1) instead of re-scanning the sections, enabling
|
||||
/// select-all-on-focus for both text inputs and edit-choices (e.g. transparency).
|
||||
pub fn build_field_key_map(
|
||||
sections: &[PropSection]
|
||||
sections: &[PropSection],
|
||||
) -> HashMap<iced::widget::Id, FieldKey> {
|
||||
let mut map = HashMap::default();
|
||||
for section in sections {
|
||||
@@ -675,7 +674,7 @@ impl PropertiesPanel {
|
||||
crate::ui::icons::themed_secondary(crate::ui::icons::PIN, 12.0)
|
||||
};
|
||||
let pin = button(pin_icon)
|
||||
.on_press(Message::Dock(DockMsg::AutoCollapseToggle(PanelId::Properties,)))
|
||||
.on_press(Message::Dock(DockMsg::AutoCollapseToggle(PanelId::Properties)))
|
||||
.style(move |theme: &Theme, status| {
|
||||
let mut style = button::subtle(theme, status);
|
||||
if auto_collapse {
|
||||
@@ -700,7 +699,9 @@ impl PropertiesPanel {
|
||||
let close = tooltip(
|
||||
close,
|
||||
text(t!("Close")).size(10),
|
||||
tooltip::Position::Bottom).gap(4);
|
||||
tooltip::Position::Bottom,
|
||||
)
|
||||
.gap(4);
|
||||
|
||||
let header = mouse_area(
|
||||
container(
|
||||
@@ -715,7 +716,7 @@ impl PropertiesPanel {
|
||||
)
|
||||
.style(|theme: &Theme| container::Style {
|
||||
background: Some(Background::Color(
|
||||
theme.palette().background.weak.color
|
||||
theme.palette().background.weak.color,
|
||||
)),
|
||||
..Default::default()
|
||||
})
|
||||
@@ -882,7 +883,9 @@ impl PropertiesPanel {
|
||||
let hdr = container(
|
||||
row![
|
||||
title,
|
||||
toggle,].align_y(iced::Center)
|
||||
toggle,
|
||||
]
|
||||
.align_y(iced::Center),
|
||||
)
|
||||
.style(|theme: &Theme| {
|
||||
let palette = theme.palette();
|
||||
@@ -946,8 +949,9 @@ impl PropertiesPanel {
|
||||
label: &'a str,
|
||||
) -> Element<'a, Message> {
|
||||
match &prop.value {
|
||||
PropValue::ColorChoice(color) =>
|
||||
self.render_color_row(label, prop.field, *color, None),
|
||||
PropValue::ColorChoice(color) => {
|
||||
self.render_color_row(label, prop.field, *color, None)
|
||||
}
|
||||
PropValue::NamedColorChoice { color, name } => {
|
||||
self.render_color_row(label, prop.field, *color, Some(name))
|
||||
}
|
||||
@@ -957,8 +961,9 @@ impl PropertiesPanel {
|
||||
PropValue::FieldLwChoice { field, value } => {
|
||||
self.render_field_lw_row(label, field, *value)
|
||||
}
|
||||
PropValue::FieldLwVaries { field } =>
|
||||
self.render_field_lw_varies_row(label, field),
|
||||
PropValue::FieldLwVaries { field } => {
|
||||
self.render_field_lw_varies_row(label, field)
|
||||
}
|
||||
PropValue::LwVaries => self.render_lw_varies_row(label),
|
||||
PropValue::LinetypeChoice(lt) => self.render_linetype_row(label, lt),
|
||||
PropValue::Choice { selected, options } => {
|
||||
@@ -980,13 +985,16 @@ impl PropertiesPanel {
|
||||
PropValue::ReadOnlyWithTooltip { value, tooltip } => {
|
||||
render_ro_with_tooltip_row(label, value, tooltip)
|
||||
}
|
||||
PropValue::HatchPatternChoice(current) =>
|
||||
self.render_hatch_pattern_row(label, current),
|
||||
PropValue::HatchPatternChoice(current) => {
|
||||
self.render_hatch_pattern_row(label, current)
|
||||
}
|
||||
PropValue::AttrText { tag, value } => self.render_attr_row(tag, value),
|
||||
PropValue::EntityLink { id, handles, conflicting, } =>
|
||||
render_entity_link_row(label, *id, handles.clone(), *conflicting),
|
||||
PropValue::ParamRow { index, name, formula, resolved, } =>
|
||||
self.render_param_row(*index, name, formula, resolved),
|
||||
PropValue::EntityLink { id, handles, conflicting } => {
|
||||
render_entity_link_row(label, *id, handles.clone(), *conflicting)
|
||||
}
|
||||
PropValue::ParamRow { index, name, formula, resolved } => {
|
||||
self.render_param_row(*index, name, formula, resolved)
|
||||
}
|
||||
PropValue::ParamAddRow => render_param_add_row(),
|
||||
PropValue::ParamsVisibilityToggle(value) => render_params_visibility_toggle_row(*value),
|
||||
}
|
||||
@@ -1047,7 +1055,7 @@ impl PropertiesPanel {
|
||||
// (#415).
|
||||
Message::OpenColorWindow(
|
||||
crate::app::ColorPickTarget::PropertiesBg,
|
||||
color
|
||||
color,
|
||||
),
|
||||
);
|
||||
return prop_row_widget(label, selector);
|
||||
@@ -1123,7 +1131,7 @@ impl PropertiesPanel {
|
||||
Message::PropColorPickerToggle,
|
||||
Message::OpenColorWindow(
|
||||
crate::app::ColorPickTarget::Properties,
|
||||
color
|
||||
color,
|
||||
),
|
||||
);
|
||||
prop_row_widget(label, selector)
|
||||
@@ -1141,7 +1149,7 @@ impl PropertiesPanel {
|
||||
Message::PropColorPickerToggle,
|
||||
Message::OpenColorWindow(
|
||||
crate::app::ColorPickTarget::Properties,
|
||||
AcadColor::ByLayer
|
||||
AcadColor::ByLayer,
|
||||
),
|
||||
);
|
||||
prop_row_widget(label, selector)
|
||||
@@ -1531,28 +1539,24 @@ impl PropertiesPanel {
|
||||
use crate::ui::window::named_parameters::ParamField;
|
||||
|
||||
let name_key = FieldKey::Param(index, ParamField::Name);
|
||||
let name_display = self.edit_buf.get(&name_key)
|
||||
.map(|s| s.as_str())
|
||||
.unwrap_or(name);
|
||||
let name_display = self.edit_buf.get(&name_key).map(|s| s.as_str()).unwrap_or(name);
|
||||
let name_active = self.active_field.as_ref() == Some(&name_key);
|
||||
let name_input = text_input("name", name_display)
|
||||
.id(name_key.widget_id())
|
||||
.on_input(move |v| Message::PropParamInput { index, field: ParamField::Name, value: v, })
|
||||
.on_submit(Message::PropParamCommit { index, field: ParamField::Name, })
|
||||
.on_input(move |v| Message::PropParamInput { index, field: ParamField::Name, value: v })
|
||||
.on_submit(Message::PropParamCommit { index, field: ParamField::Name })
|
||||
.size(FONT_SZ)
|
||||
.style(text_input_style)
|
||||
.padding([3, 6])
|
||||
.width(Length::FillPortion(3));
|
||||
|
||||
let formula_key = FieldKey::Param(index, ParamField::Formula);
|
||||
let formula_display = self.edit_buf.get(&formula_key)
|
||||
.map(|s| s.as_str())
|
||||
.unwrap_or(formula);
|
||||
let formula_display = self.edit_buf.get(&formula_key).map(|s| s.as_str()).unwrap_or(formula);
|
||||
let formula_active = self.active_field.as_ref() == Some(&formula_key);
|
||||
let formula_input = text_input("formula", formula_display)
|
||||
.id(formula_key.widget_id())
|
||||
.on_input(move |v| Message::PropParamInput { index, field: ParamField::Formula, value: v, })
|
||||
.on_submit(Message::PropParamCommit { index, field: ParamField::Formula, })
|
||||
.on_input(move |v| Message::PropParamInput { index, field: ParamField::Formula, value: v })
|
||||
.on_submit(Message::PropParamCommit { index, field: ParamField::Formula })
|
||||
.size(FONT_SZ)
|
||||
.style(text_input_style)
|
||||
.padding([3, 6])
|
||||
@@ -1563,10 +1567,9 @@ impl PropertiesPanel {
|
||||
Err(_) => ("—".to_string(), true),
|
||||
};
|
||||
let value_label = container(
|
||||
text(value_text).size(FONT_SZ).style(move |theme: &Theme| { iced::widget::text::Style {
|
||||
text(value_text).size(FONT_SZ).style(move |theme: &Theme| iced::widget::text::Style {
|
||||
color: is_error.then_some(theme.palette().danger.base.color),
|
||||
}
|
||||
})
|
||||
}),
|
||||
)
|
||||
.width(Length::FillPortion(2))
|
||||
.align_x(iced::Right);
|
||||
@@ -1584,15 +1587,13 @@ impl PropertiesPanel {
|
||||
Background::Color(theme.palette().background.base.color)
|
||||
}
|
||||
};
|
||||
let content = container(row![name_input, formula_input, value_label, delete_btn]
|
||||
.spacing(4)
|
||||
.align_y(iced::Center),)
|
||||
let content = container(row![name_input, formula_input, value_label, delete_btn].spacing(4).align_y(iced::Center))
|
||||
.style(move |theme: &Theme| container::Style { background: Some(bg(theme)), ..Default::default() })
|
||||
.padding([2, 6])
|
||||
.width(Length::Fill);
|
||||
|
||||
if let Err(err) = resolved {
|
||||
tooltip(content, text(err.as_str()).size(FONT_SZ), tooltip::Position::Top,)
|
||||
tooltip(content, text(err.as_str()).size(FONT_SZ), tooltip::Position::Top)
|
||||
.gap(4.0)
|
||||
.padding(6.0)
|
||||
.style(|theme: &Theme| {
|
||||
@@ -1600,7 +1601,7 @@ impl PropertiesPanel {
|
||||
container::Style {
|
||||
background: Some(Background::Color(palette.danger.weak.color)),
|
||||
text_color: Some(palette.danger.weak.text),
|
||||
border: Border { color: palette.danger.base.color, width: 1.0, radius: 4.0.into(), },
|
||||
border: Border { color: palette.danger.base.color, width: 1.0, radius: 4.0.into() },
|
||||
..Default::default()
|
||||
}
|
||||
})
|
||||
@@ -1658,16 +1659,22 @@ impl PropertiesPanel {
|
||||
return prop_row_widget(label, head.into());
|
||||
}
|
||||
|
||||
let popup = hatch_pattern_picker_content( &self.hatch_pattern_search,
|
||||
let popup = hatch_pattern_picker_content(
|
||||
&self.hatch_pattern_search,
|
||||
self.hatch_pattern_focus,
|
||||
current,"hatch-pattern-search",Message::PropHatchPatternSearchChanged,Message::PropHatchPatternConfirm,
|
||||
current,
|
||||
"hatch-pattern-search",
|
||||
Message::PropHatchPatternSearchChanged,
|
||||
Message::PropHatchPatternConfirm,
|
||||
Message::PropHatchPatternFocus,
|
||||
Message::PropHatchPatternChanged,
|
||||
);
|
||||
|
||||
prop_row_widget(
|
||||
label,crate::ui::color_select::drop_down_below(
|
||||
head.into(), popup,
|
||||
label,
|
||||
crate::ui::color_select::drop_down_below(
|
||||
head.into(),
|
||||
popup,
|
||||
Some(Length::Fixed(PATTERN_PICKER_W)),
|
||||
Length::Fixed(PATTERN_PICKER_H),
|
||||
Message::PropHatchPatternPickerToggle(current.to_string()),
|
||||
@@ -1723,10 +1730,11 @@ fn render_bool_row<'a>(label: &'a str, field: &'static str, value: bool) -> Elem
|
||||
};
|
||||
let btn =
|
||||
button(
|
||||
text(btn_label).size(FONT_SZ).style(move |theme: &Theme| { iced::widget::text::Style {
|
||||
text(btn_label)
|
||||
.size(FONT_SZ)
|
||||
.style(move |theme: &Theme| iced::widget::text::Style {
|
||||
color: value.then_some(theme.palette().warning.base.color),
|
||||
}
|
||||
})
|
||||
}),
|
||||
)
|
||||
.on_press(Message::PropBoolToggle(field))
|
||||
.style(move |theme: &Theme, status| {
|
||||
@@ -1869,7 +1877,7 @@ fn render_group_row(
|
||||
let label_col = container(label_btn)
|
||||
.style(|theme: &Theme| container::Style {
|
||||
background: Some(Background::Color(
|
||||
theme.palette().background.weakest.color
|
||||
theme.palette().background.weakest.color,
|
||||
)),
|
||||
..Default::default()
|
||||
})
|
||||
@@ -1882,7 +1890,7 @@ fn render_group_row(
|
||||
let value_col = container(value_field)
|
||||
.style(|theme: &Theme| container::Style {
|
||||
background: Some(Background::Color(
|
||||
theme.palette().background.base.color
|
||||
theme.palette().background.base.color,
|
||||
)),
|
||||
..Default::default()
|
||||
})
|
||||
@@ -1910,7 +1918,7 @@ fn render_group_row(
|
||||
}
|
||||
fn render_annotative_scale_row<'a>(
|
||||
label: &'a str,
|
||||
value: &'a str
|
||||
value: &'a str,
|
||||
) -> Element<'a, Message> {
|
||||
let field = crate::ui::read_only::field(value, FONT_SZ, Length::Fill);
|
||||
|
||||
@@ -1956,7 +1964,7 @@ fn render_ro_with_tooltip_row<'a>(
|
||||
tooltip_text: &'a str,
|
||||
) -> Element<'a, Message> {
|
||||
let field = crate::ui::read_only::field(value, FONT_SZ, Length::Fill);
|
||||
let wrapped = tooltip(field, text(tooltip_text).size(FONT_SZ), tooltip::Position::Top,)
|
||||
let wrapped = tooltip(field, text(tooltip_text).size(FONT_SZ), tooltip::Position::Top)
|
||||
.gap(4.0)
|
||||
.padding(6.0)
|
||||
.style(|theme: &Theme| {
|
||||
@@ -2004,7 +2012,7 @@ fn render_entity_link_row<'a>(
|
||||
};
|
||||
button::Style {
|
||||
background: Some(Background::Color(pair.color)),
|
||||
border: Border { color: palette.background.neutral.color, width: 1.0, radius: 2.0.into(), },
|
||||
border: Border { color: palette.background.neutral.color, width: 1.0, radius: 2.0.into() },
|
||||
text_color: pair.text,
|
||||
..Default::default()
|
||||
}
|
||||
@@ -2027,10 +2035,7 @@ fn render_entity_link_row<'a>(
|
||||
/// — avoids a separate "pending new row" concept, since every row always
|
||||
/// reflects a real committed table entry.
|
||||
fn render_param_add_row<'a>() -> Element<'a, Message> {
|
||||
let btn = button(row![text("+").size(FONT_SZ), text(t!("Add parameter").into_owned()).size(FONT_SZ)
|
||||
]
|
||||
.spacing(6)
|
||||
.align_y(iced::Center),)
|
||||
let btn = button(row![text("+").size(FONT_SZ), text(t!("Add parameter").into_owned()).size(FONT_SZ)].spacing(6).align_y(iced::Center))
|
||||
.on_press(Message::PropParamAddNew)
|
||||
.style(button::text)
|
||||
.padding([4, 8])
|
||||
@@ -2063,18 +2068,14 @@ fn render_params_visibility_toggle_row<'a>(value: bool) -> Element<'a, Message>
|
||||
};
|
||||
button::Style {
|
||||
background: Some(Background::Color(pair.color)),
|
||||
border: Border { color: palette.background.neutral.color, width: 1.0, radius: 2.0.into(), },
|
||||
border: Border { color: palette.background.neutral.color, width: 1.0, radius: 2.0.into() },
|
||||
text_color: pair.text,
|
||||
..Default::default()
|
||||
}
|
||||
})
|
||||
.padding([4, 8])
|
||||
.width(Length::Fill);
|
||||
container(row![text(t!("Values").into_owned())
|
||||
.size(FONT_SZ)
|
||||
.width(Length::Fill), btn
|
||||
]
|
||||
.align_y(iced::Center),)
|
||||
container(row![text(t!("Values").into_owned()).size(FONT_SZ).width(Length::Fill), btn].align_y(iced::Center))
|
||||
.width(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
@@ -2224,9 +2225,7 @@ fn text_input_style(theme: &Theme, status: text_input::Status) -> text_input::St
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate)
|
||||
|
||||
fn combo_input_style(theme: &Theme, status: text_input::Status) -> text_input::Style {
|
||||
pub(crate) fn combo_input_style(theme: &Theme, status: text_input::Status) -> text_input::Style {
|
||||
text_input_style(theme, status)
|
||||
}
|
||||
|
||||
@@ -2250,7 +2249,7 @@ mod tests {
|
||||
};
|
||||
|
||||
fn sample_sections() -> Vec<crate::scene::model::object::PropSection> {
|
||||
use crate::scene::model::object::{PropValue,Property};
|
||||
use crate::scene::model::object::{Property, PropValue};
|
||||
vec![
|
||||
crate::scene::model::object::PropSection {
|
||||
title: "Geometry".into(),
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
//! Gradient flyout of the Graphic Attributes palette.
|
||||
|
||||
use crate::app::Message;
|
||||
use crate::scene::model::hatch_model::GradientKind;
|
||||
use crate::ui::window::graphic_attributes::GraphicAttributesMsg;
|
||||
use acadrust::types::Color as AcadColor;
|
||||
use iced::widget::{
|
||||
button, checkbox, column, container, image, mouse_area, row, slider, text, text_input, tooltip,
|
||||
@@ -24,7 +27,26 @@ pub struct GradientEditorState {
|
||||
pub inverted: bool,
|
||||
pub angle: String,
|
||||
pub centered: bool,
|
||||
pub color_open: Option<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum GradientMsg {
|
||||
Open,
|
||||
Cancel,
|
||||
Apply,
|
||||
ColorMode(GradientColorMode),
|
||||
/// Stop colour 1 or 2.
|
||||
Color(u8, AcadColor),
|
||||
ShadeTint(f32),
|
||||
Kind(GradientKind),
|
||||
InvertToggled,
|
||||
Angle(String),
|
||||
AngleReset,
|
||||
Centered(bool),
|
||||
}
|
||||
|
||||
fn msg(message: GradientMsg) -> Message {
|
||||
Message::GraphicAttributes(GraphicAttributesMsg::Gradient(message))
|
||||
}
|
||||
|
||||
impl GradientEditorState {
|
||||
@@ -37,7 +59,7 @@ impl GradientEditorState {
|
||||
.gradient_color
|
||||
.colors
|
||||
.get(index)
|
||||
.map(|entry| entry.color.clone())
|
||||
.map(|entry| entry.color)
|
||||
.unwrap_or(AcadColor::Index(7))
|
||||
};
|
||||
let (kind, inverted) = GradientKind::from_name(&hatch.gradient_color.name);
|
||||
@@ -55,7 +77,30 @@ impl GradientEditorState {
|
||||
inverted,
|
||||
angle: format!("{:.1}°", hatch.gradient_color.angle.to_degrees()),
|
||||
centered: hatch.gradient_color.shift.abs() < 1e-9,
|
||||
color_open: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: GradientMsg) {
|
||||
match message {
|
||||
GradientMsg::ColorMode(mode) => self.color_mode = mode,
|
||||
GradientMsg::Color(1, color) => self.color_1 = color,
|
||||
GradientMsg::Color(_, color) => self.color_2 = color,
|
||||
GradientMsg::ShadeTint(value) => self.shade_tint = value.clamp(0.0, 1.0),
|
||||
GradientMsg::Kind(kind) => {
|
||||
self.kind = kind;
|
||||
if kind == GradientKind::Linear {
|
||||
self.inverted = false;
|
||||
}
|
||||
}
|
||||
GradientMsg::InvertToggled => {
|
||||
if self.kind != GradientKind::Linear {
|
||||
self.inverted ^= true;
|
||||
}
|
||||
}
|
||||
GradientMsg::Angle(value) => self.angle = value,
|
||||
GradientMsg::AngleReset => self.angle = "0.0°".into(),
|
||||
GradientMsg::Centered(value) => self.centered = value,
|
||||
GradientMsg::Open | GradientMsg::Cancel | GradientMsg::Apply => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +141,7 @@ fn preview_sized(
|
||||
state: &GradientEditorState,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> iced::widget::image::Handle {
|
||||
) -> Option<iced::widget::image::Handle> {
|
||||
let c1 = rgb(&state.color_1);
|
||||
let c2 = if state.color_mode == GradientColorMode::One {
|
||||
let c = crate::scene::gradient_tint_color(rgb_array(&state.color_1), state.shade_tint);
|
||||
@@ -110,8 +155,7 @@ fn preview_sized(
|
||||
angle,
|
||||
if state.centered { 0.0 } else { 1.0 },
|
||||
cadkernel::geom2d::Tolerance::default(),
|
||||
)
|
||||
.expect("the preview rectangle always defines a gradient frame");
|
||||
)?;
|
||||
let (sin, cos) = angle.sin_cos();
|
||||
let radial = state.kind.radial();
|
||||
let mut pixels = Vec::with_capacity((width * height * 4) as usize);
|
||||
@@ -143,17 +187,30 @@ fn preview_sized(
|
||||
});
|
||||
}
|
||||
}
|
||||
iced::widget::image::Handle::from_rgba(width, height, pixels)
|
||||
Some(iced::widget::image::Handle::from_rgba(width, height, pixels))
|
||||
}
|
||||
|
||||
fn preview(state: &GradientEditorState) -> iced::widget::image::Handle {
|
||||
preview_sized(state, 370, 80)
|
||||
fn preview(state: &GradientEditorState) -> Element<'static, Message> {
|
||||
preview_image(preview_sized(state, 370, 80))
|
||||
}
|
||||
|
||||
pub(crate) fn compact_preview(
|
||||
hatch: &acadrust::entities::Hatch,
|
||||
) -> iced::widget::image::Handle {
|
||||
preview_sized(&GradientEditorState::from_hatch(Vec::new(), hatch), 256, 26)
|
||||
pub(crate) fn compact_preview(hatch: &acadrust::entities::Hatch) -> Element<'static, Message> {
|
||||
preview_image(preview_sized(
|
||||
&GradientEditorState::from_hatch(Vec::new(), hatch),
|
||||
256,
|
||||
26,
|
||||
))
|
||||
}
|
||||
|
||||
fn preview_image(handle: Option<iced::widget::image::Handle>) -> Element<'static, Message> {
|
||||
match handle {
|
||||
Some(handle) => image(handle)
|
||||
.width(Fill)
|
||||
.height(Fill)
|
||||
.content_fit(iced::ContentFit::Fill)
|
||||
.into(),
|
||||
None => Space::new().width(Fill).height(Fill).into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn icon(kind: GradientKind, inverted: bool) -> &'static [u8] {
|
||||
@@ -192,7 +249,7 @@ pub fn view(state: &GradientEditorState, dimmed: bool) -> Element<'_, Message> {
|
||||
let segment = |label, mode| {
|
||||
let selected = state.color_mode == mode;
|
||||
button(text(label).size(11))
|
||||
.on_press(Message::GradientColorModeChanged(mode))
|
||||
.on_press(msg(GradientMsg::ColorMode(mode)))
|
||||
.width(Fill)
|
||||
.style(move |theme: &Theme, status| {
|
||||
if selected {
|
||||
@@ -203,8 +260,8 @@ pub fn view(state: &GradientEditorState, dimmed: bool) -> Element<'_, Message> {
|
||||
})
|
||||
};
|
||||
let color_field = |label: &'static str, index, color: AcadColor| {
|
||||
let (background, _) = crate::ui::properties::acad_color_display(color.clone());
|
||||
let value = crate::ui::color_select::color_display_name(color.clone());
|
||||
let (background, _) = crate::ui::properties::acad_color_display(color);
|
||||
let value = crate::ui::color_select::color_display_name(color);
|
||||
let picker = button(
|
||||
row![
|
||||
crate::ui::color_select::swatch(background),
|
||||
@@ -265,7 +322,7 @@ pub fn view(state: &GradientEditorState, dimmed: bool) -> Element<'_, Message> {
|
||||
]
|
||||
.align_x(iced::Center),
|
||||
)
|
||||
.on_press(Message::GradientTypeChanged(kind))
|
||||
.on_press(msg(GradientMsg::Kind(kind)))
|
||||
.width(48)
|
||||
.height(48)
|
||||
.style(move |theme: &Theme, status| {
|
||||
@@ -285,7 +342,7 @@ pub fn view(state: &GradientEditorState, dimmed: bool) -> Element<'_, Message> {
|
||||
let invert_selected = state.inverted && state.kind != GradientKind::Linear;
|
||||
let invert = button(column![text("⇄").size(18), text("Invert").size(9)].align_x(iced::Center))
|
||||
.on_press_maybe(
|
||||
(state.kind != GradientKind::Linear).then_some(Message::GradientInvertToggled),
|
||||
(state.kind != GradientKind::Linear).then(|| msg(GradientMsg::InvertToggled)),
|
||||
)
|
||||
.width(42)
|
||||
.height(48)
|
||||
@@ -309,18 +366,18 @@ pub fn view(state: &GradientEditorState, dimmed: bool) -> Element<'_, Message> {
|
||||
));
|
||||
let colors: Element<'_, Message> = if state.color_mode == GradientColorMode::Two {
|
||||
row![
|
||||
color_field("Color 1", 1, state.color_1.clone()),
|
||||
color_field("Color 2", 2, state.color_2.clone())
|
||||
color_field("Color 1", 1, state.color_1),
|
||||
color_field("Color 2", 2, state.color_2)
|
||||
]
|
||||
.spacing(6)
|
||||
.into()
|
||||
} else {
|
||||
row![
|
||||
color_field("Color 1", 1, state.color_1.clone()),
|
||||
color_field("Color 1", 1, state.color_1),
|
||||
row![
|
||||
text("Tone").size(11).width(43),
|
||||
slider(0..=100, (state.shade_tint * 100.0) as i32, |v| {
|
||||
Message::GradientShadeTintChanged(v as f32 / 100.0)
|
||||
msg(GradientMsg::ShadeTint(v as f32 / 100.0))
|
||||
})
|
||||
.width(Fill)
|
||||
]
|
||||
@@ -336,12 +393,12 @@ pub fn view(state: &GradientEditorState, dimmed: bool) -> Element<'_, Message> {
|
||||
let angle = row![
|
||||
text("Angle").size(11).width(43),
|
||||
text_input("0.0°", &state.angle)
|
||||
.on_input(Message::GradientAngleChanged)
|
||||
.on_input(|value| msg(GradientMsg::Angle(value)))
|
||||
.size(11)
|
||||
.width(Length::Fixed(92.0)),
|
||||
tooltip(
|
||||
button(crate::ui::icons::themed_undo(11.0, true))
|
||||
.on_press(Message::GradientAngleReset)
|
||||
.on_press(msg(GradientMsg::AngleReset))
|
||||
.style(button::subtle)
|
||||
.padding(3)
|
||||
.width(24)
|
||||
@@ -352,7 +409,7 @@ pub fn view(state: &GradientEditorState, dimmed: bool) -> Element<'_, Message> {
|
||||
Space::new().width(Fill),
|
||||
checkbox(state.centered)
|
||||
.label("Centered")
|
||||
.on_toggle(Message::GradientCenteredChanged)
|
||||
.on_toggle(|value| msg(GradientMsg::Centered(value)))
|
||||
.size(14)
|
||||
.text_size(11)
|
||||
]
|
||||
@@ -364,11 +421,11 @@ pub fn view(state: &GradientEditorState, dimmed: bool) -> Element<'_, Message> {
|
||||
let actions = container(
|
||||
row![
|
||||
button(text(crate::t!("Cancel")).size(11))
|
||||
.on_press(Message::GradientCancel)
|
||||
.on_press(msg(GradientMsg::Cancel))
|
||||
.style(button::secondary)
|
||||
.padding([5, 14]),
|
||||
button(text(crate::t!("OK")).size(11))
|
||||
.on_press(Message::GradientApply)
|
||||
.on_press(msg(GradientMsg::Apply))
|
||||
.style(button::primary)
|
||||
.padding([5, 18]),
|
||||
]
|
||||
@@ -377,7 +434,7 @@ pub fn view(state: &GradientEditorState, dimmed: bool) -> Element<'_, Message> {
|
||||
.width(Fill)
|
||||
.align_x(iced::alignment::Horizontal::Right);
|
||||
let content = column![
|
||||
image(preview(state)).width(Fill).height(80),
|
||||
container(preview(state)).width(Fill).height(80),
|
||||
row![
|
||||
segment("One Color", GradientColorMode::One),
|
||||
segment("Two Colors", GradientColorMode::Two)
|
||||
|
||||
+900
-977
File diff suppressed because it is too large.
Load diff
+16
-16
@@ -1,32 +1,32 @@
|
||||
pub mod about;
|
||||
pub mod alias_editor;
|
||||
pub mod annotation_data;
|
||||
pub mod attribute_editor;
|
||||
pub mod auto_constrain_settings;
|
||||
pub mod block_definition;
|
||||
pub mod block_palette;
|
||||
pub mod browser;
|
||||
pub mod drafting_settings;
|
||||
pub mod layout_manager;
|
||||
pub mod layer_state_manager;
|
||||
pub mod drawing_units;
|
||||
pub mod find_replace;
|
||||
pub mod geometric_tolerance;
|
||||
pub mod gradient_editor;
|
||||
pub mod graphic_attributes;
|
||||
pub mod layer_state_manager;
|
||||
pub mod drafting_settings;
|
||||
pub mod auto_constrain_settings;
|
||||
pub mod layer_translator;
|
||||
pub mod layers;
|
||||
pub mod layout_manager;
|
||||
pub mod missing_fonts;
|
||||
pub mod named_parameters;
|
||||
pub mod open_progress;
|
||||
pub mod options;
|
||||
pub mod plot;
|
||||
pub mod plugin_manager;
|
||||
pub mod print_all;
|
||||
pub mod recovery;
|
||||
pub mod plugin_manager;
|
||||
pub mod shortcuts;
|
||||
pub mod layers;
|
||||
pub mod update_notice;
|
||||
pub mod wblock;
|
||||
pub mod open_progress;
|
||||
pub mod missing_fonts;
|
||||
pub mod recovery;
|
||||
pub mod options;
|
||||
pub mod attribute_editor;
|
||||
pub mod annotation_data;
|
||||
pub mod alias_editor;
|
||||
pub mod find_replace;
|
||||
pub mod named_parameters;
|
||||
pub mod xref_attach;
|
||||
pub mod xref_help;
|
||||
pub mod xref_manager;
|
||||
pub mod wblock;
|
||||
Reference in new issue
Block a user