cargo fmt

This commit is contained in:
Hakan committed 2026-05-12 10:36:15 +03:00
1 parent 468cbde5e1
commit ca07268c7c
204 files changed
+13997 -5525

No files matched your search

+363 -95
View File
@@ -4,42 +4,122 @@ use crate::app::{DsField, Message};
use iced::widget::{button, checkbox, column, container, row, scrollable, text, text_input, Space};
use iced::{Background, Border, Color, Element, Fill, Theme};
const TB: Color = Color { r: 0.13, g: 0.13, b: 0.13, a: 1.0 };
const BG: Color = Color { r: 0.15, g: 0.15, b: 0.15, a: 1.0 };
const BORDER: Color = Color { r: 0.35, g: 0.35, b: 0.35, a: 1.0 };
const TEXT: Color = Color { r: 0.88, g: 0.88, b: 0.88, a: 1.0 };
const DIM: Color = Color { r: 0.55, g: 0.55, b: 0.55, a: 1.0 };
const ACCENT: Color = Color { r: 0.25, g: 0.50, b: 0.85, a: 1.0 };
const ACTIVE: Color = Color { r: 0.20, g: 0.40, b: 0.70, a: 1.0 };
const FIELD: Color = Color { r: 0.10, g: 0.10, b: 0.10, a: 1.0 };
const LIST: Color = Color { r: 0.12, g: 0.12, b: 0.12, a: 1.0 };
const TB: Color = Color {
r: 0.13,
g: 0.13,
b: 0.13,
a: 1.0,
};
const BG: Color = Color {
r: 0.15,
g: 0.15,
b: 0.15,
a: 1.0,
};
const BORDER: Color = Color {
r: 0.35,
g: 0.35,
b: 0.35,
a: 1.0,
};
const TEXT: Color = Color {
r: 0.88,
g: 0.88,
b: 0.88,
a: 1.0,
};
const DIM: Color = Color {
r: 0.55,
g: 0.55,
b: 0.55,
a: 1.0,
};
const ACCENT: Color = Color {
r: 0.25,
g: 0.50,
b: 0.85,
a: 1.0,
};
const ACTIVE: Color = Color {
r: 0.20,
g: 0.40,
b: 0.70,
a: 1.0,
};
const FIELD: Color = Color {
r: 0.10,
g: 0.10,
b: 0.10,
a: 1.0,
};
const LIST: Color = Color {
r: 0.12,
g: 0.12,
b: 0.12,
a: 1.0,
};
/// All DimStyle field values needed by the view.
pub struct DimStyleValues<'a> {
pub dimdle: &'a str, pub dimdli: &'a str, pub dimgap: &'a str,
pub dimexe: &'a str, pub dimexo: &'a str,
pub dimsd1: bool, pub dimsd2: bool,
pub dimse1: bool, pub dimse2: bool,
pub dimasz: &'a str, pub dimcen: &'a str, pub dimtsz: &'a str,
pub dimtxt: &'a str, pub dimtxsty: &'a str, pub dimtad: &'a str,
pub dimtih: bool, pub dimtoh: bool,
pub dimscale: &'a str, pub dimlfac: &'a str,
pub dimlunit: &'a str, pub dimdec: &'a str, pub dimpost: &'a str,
pub dimtol: bool, pub dimlim: bool,
pub dimtp: &'a str, pub dimtm: &'a str,
pub dimtdec: &'a str, pub dimtfac: &'a str,
pub dimdle: &'a str,
pub dimdli: &'a str,
pub dimgap: &'a str,
pub dimexe: &'a str,
pub dimexo: &'a str,
pub dimsd1: bool,
pub dimsd2: bool,
pub dimse1: bool,
pub dimse2: bool,
pub dimasz: &'a str,
pub dimcen: &'a str,
pub dimtsz: &'a str,
pub dimtxt: &'a str,
pub dimtxsty: &'a str,
pub dimtad: &'a str,
pub dimtih: bool,
pub dimtoh: bool,
pub dimscale: &'a str,
pub dimlfac: &'a str,
pub dimlunit: &'a str,
pub dimdec: &'a str,
pub dimpost: &'a str,
pub dimtol: bool,
pub dimlim: bool,
pub dimtp: &'a str,
pub dimtm: &'a str,
pub dimtdec: &'a str,
pub dimtfac: &'a str,
}
fn btn_s(accent: bool) -> impl Fn(&Theme, button::Status) -> button::Style {
move |_: &Theme, st| button::Style {
background: Some(Background::Color(match (accent, st) {
(true, button::Status::Hovered | button::Status::Pressed) => Color { r: 0.20, g: 0.42, b: 0.72, a: 1.0 },
(false, button::Status::Hovered | button::Status::Pressed) => Color { r: 0.28, g: 0.28, b: 0.28, a: 1.0 },
(true, _) => ACCENT,
_ => Color { r: 0.22, g: 0.22, b: 0.22, a: 1.0 },
(true, button::Status::Hovered | button::Status::Pressed) => Color {
r: 0.20,
g: 0.42,
b: 0.72,
a: 1.0,
},
(false, button::Status::Hovered | button::Status::Pressed) => Color {
r: 0.28,
g: 0.28,
b: 0.28,
a: 1.0,
},
(true, _) => ACCENT,
_ => Color {
r: 0.22,
g: 0.22,
b: 0.22,
a: 1.0,
},
})),
text_color: TEXT,
border: Border { color: BORDER, width: 1.0, radius: 4.0.into() },
border: Border {
color: BORDER,
width: 1.0,
radius: 4.0.into(),
},
..Default::default()
}
}
@@ -47,12 +127,26 @@ fn btn_s(accent: bool) -> impl Fn(&Theme, button::Status) -> button::Style {
fn tab_btn_style(active: bool) -> impl Fn(&Theme, button::Status) -> button::Style {
move |_: &Theme, st| button::Style {
background: Some(Background::Color(match (active, st) {
(true, _) => ACTIVE,
(false, button::Status::Hovered | button::Status::Pressed) => Color { r: 0.28, g: 0.28, b: 0.28, a: 1.0 },
_ => Color { r: 0.20, g: 0.20, b: 0.20, a: 1.0 },
(true, _) => ACTIVE,
(false, button::Status::Hovered | button::Status::Pressed) => Color {
r: 0.28,
g: 0.28,
b: 0.28,
a: 1.0,
},
_ => Color {
r: 0.20,
g: 0.20,
b: 0.20,
a: 1.0,
},
})),
text_color: TEXT,
border: Border { color: BORDER, width: 1.0, radius: 3.0.into() },
border: Border {
color: BORDER,
width: 1.0,
radius: 3.0.into(),
},
..Default::default()
}
}
@@ -60,12 +154,26 @@ fn tab_btn_style(active: bool) -> impl Fn(&Theme, button::Status) -> button::Sty
fn list_item_style(active: bool) -> impl Fn(&Theme, button::Status) -> button::Style {
move |_: &Theme, st| button::Style {
background: Some(Background::Color(match (active, st) {
(true, _) => ACTIVE,
(false, button::Status::Hovered | button::Status::Pressed) => Color { r: 0.28, g: 0.28, b: 0.28, a: 1.0 },
_ => Color { r: 0.18, g: 0.18, b: 0.18, a: 1.0 },
(true, _) => ACTIVE,
(false, button::Status::Hovered | button::Status::Pressed) => Color {
r: 0.28,
g: 0.28,
b: 0.28,
a: 1.0,
},
_ => Color {
r: 0.18,
g: 0.18,
b: 0.18,
a: 1.0,
},
})),
text_color: TEXT,
border: Border { color: BORDER, width: 0.0, radius: 3.0.into() },
border: Border {
color: BORDER,
width: 0.0,
radius: 3.0.into(),
},
..Default::default()
}
}
@@ -73,14 +181,22 @@ fn list_item_style(active: bool) -> impl Fn(&Theme, button::Status) -> button::S
fn field_style(_: &Theme, _: text_input::Status) -> text_input::Style {
text_input::Style {
background: Background::Color(FIELD),
border: Border { color: BORDER, width: 1.0, radius: 3.0.into() },
icon: TEXT, placeholder: DIM, value: TEXT, selection: ACCENT,
border: Border {
color: BORDER,
width: 1.0,
radius: 3.0.into(),
},
icon: TEXT,
placeholder: DIM,
value: TEXT,
selection: ACCENT,
}
}
fn hdivider<'a>() -> Element<'a, Message> {
container(Space::new().width(Fill).height(1))
.width(Fill).height(1)
.width(Fill)
.height(1)
.style(|_: &Theme| container::Style {
background: Some(Background::Color(BORDER)),
..Default::default()
@@ -97,15 +213,30 @@ pub fn view_window<'a>(
// ── Toolbar ───────────────────────────────────────────────────────────
let toolbar = container(
row![
button(text("New").size(11)).on_press(Message::DimStyleDialogNew).style(btn_s(false)).padding([4, 10]),
button(text("Delete").size(11)).on_press(Message::DimStyleDialogDelete).style(btn_s(false)).padding([4, 10]),
button(text("Set Current").size(11)).on_press(Message::DimStyleDialogSetCurrent).style(btn_s(false)).padding([4, 10]),
button(text("New").size(11))
.on_press(Message::DimStyleDialogNew)
.style(btn_s(false))
.padding([4, 10]),
button(text("Delete").size(11))
.on_press(Message::DimStyleDialogDelete)
.style(btn_s(false))
.padding([4, 10]),
button(text("Set Current").size(11))
.on_press(Message::DimStyleDialogSetCurrent)
.style(btn_s(false))
.padding([4, 10]),
Space::new().width(Fill),
button(text("Apply").size(11)).on_press(Message::DimStyleDialogApply).style(btn_s(true)).padding([4, 14]),
button(text("Close").size(11)).on_press(Message::DimStyleDialogClose).style(btn_s(false)).padding([4, 10]),
button(text("Apply").size(11))
.on_press(Message::DimStyleDialogApply)
.style(btn_s(true))
.padding([4, 14]),
button(text("Close").size(11))
.on_press(Message::DimStyleDialogClose)
.style(btn_s(false))
.padding([4, 10]),
]
.spacing(4)
.align_y(iced::Center)
.align_y(iced::Center),
)
.style(|_: &Theme| container::Style {
background: Some(Background::Color(TB)),
@@ -123,7 +254,7 @@ pub fn view_window<'a>(
.on_press(Message::DimStyleDialogSelect(name.clone()))
.style(list_item_style(active))
.padding([4, 8])
.width(Fill)
.width(Fill),
);
}
let style_list = container(
@@ -132,7 +263,11 @@ pub fn view_window<'a>(
container(scrollable(list_col).height(Fill))
.style(|_: &Theme| container::Style {
background: Some(Background::Color(LIST)),
border: Border { color: BORDER, width: 1.0, radius: 3.0.into() },
border: Border {
color: BORDER,
width: 1.0,
radius: 3.0.into()
},
..Default::default()
})
.width(180)
@@ -140,20 +275,41 @@ pub fn view_window<'a>(
.padding(2),
]
.spacing(4)
.height(Fill)
.height(Fill),
)
.width(180)
.height(Fill)
.padding(iced::Padding { top: 12.0, right: 8.0, bottom: 12.0, left: 12.0 });
.padding(iced::Padding {
top: 12.0,
right: 8.0,
bottom: 12.0,
left: 12.0,
});
// ── Tab bar ───────────────────────────────────────────────────────────
let tabs = row![
button(text("Lines").size(11)).on_press(Message::DimStyleDialogTab(0)).style(tab_btn_style(tab == 0)).padding([4, 10]),
button(text("Arrows").size(11)).on_press(Message::DimStyleDialogTab(1)).style(tab_btn_style(tab == 1)).padding([4, 10]),
button(text("Text").size(11)).on_press(Message::DimStyleDialogTab(2)).style(tab_btn_style(tab == 2)).padding([4, 10]),
button(text("Scale/Units").size(11)).on_press(Message::DimStyleDialogTab(3)).style(tab_btn_style(tab == 3)).padding([4, 10]),
button(text("Tolerances").size(11)).on_press(Message::DimStyleDialogTab(4)).style(tab_btn_style(tab == 4)).padding([4, 10]),
].spacing(2);
button(text("Lines").size(11))
.on_press(Message::DimStyleDialogTab(0))
.style(tab_btn_style(tab == 0))
.padding([4, 10]),
button(text("Arrows").size(11))
.on_press(Message::DimStyleDialogTab(1))
.style(tab_btn_style(tab == 1))
.padding([4, 10]),
button(text("Text").size(11))
.on_press(Message::DimStyleDialogTab(2))
.style(tab_btn_style(tab == 2))
.padding([4, 10]),
button(text("Scale/Units").size(11))
.on_press(Message::DimStyleDialogTab(3))
.style(tab_btn_style(tab == 3))
.padding([4, 10]),
button(text("Tolerances").size(11))
.on_press(Message::DimStyleDialogTab(4))
.style(tab_btn_style(tab == 4))
.padding([4, 10]),
]
.spacing(2);
let lbl = |s: &'static str| text(s).size(11).color(DIM).width(180);
@@ -178,49 +334,159 @@ pub fn view_window<'a>(
let tab_content: Element<'_, Message> = match tab {
0 => column![
text("Dimension Line").size(11).color(ACCENT),
row![lbl("Extension (DIMDLE)"), mk_field(DsField::Dimdle, vals.dimdle)].spacing(8).align_y(iced::Center),
row![lbl("Spacing (DIMDLI)"), mk_field(DsField::Dimdli, vals.dimdli)].spacing(8).align_y(iced::Center),
row![lbl("Text gap (DIMGAP)"), mk_field(DsField::Dimgap, vals.dimgap)].spacing(8).align_y(iced::Center),
row![
lbl("Extension (DIMDLE)"),
mk_field(DsField::Dimdle, vals.dimdle)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Spacing (DIMDLI)"),
mk_field(DsField::Dimdli, vals.dimdli)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Text gap (DIMGAP)"),
mk_field(DsField::Dimgap, vals.dimgap)
]
.spacing(8)
.align_y(iced::Center),
chk("Suppress 1st line (DIMSD1)", vals.dimsd1, DsField::Dimsd1),
chk("Suppress 2nd line (DIMSD2)", vals.dimsd2, DsField::Dimsd2),
text("Extension Line").size(11).color(ACCENT),
row![lbl("Extension (DIMEXE)"), mk_field(DsField::Dimexe, vals.dimexe)].spacing(8).align_y(iced::Center),
row![lbl("Offset (DIMEXO)"), mk_field(DsField::Dimexo, vals.dimexo)].spacing(8).align_y(iced::Center),
row![
lbl("Extension (DIMEXE)"),
mk_field(DsField::Dimexe, vals.dimexe)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Offset (DIMEXO)"),
mk_field(DsField::Dimexo, vals.dimexo)
]
.spacing(8)
.align_y(iced::Center),
chk("Suppress 1st line (DIMSE1)", vals.dimse1, DsField::Dimse1),
chk("Suppress 2nd line (DIMSE2)", vals.dimse2, DsField::Dimse2),
].spacing(7).into(),
]
.spacing(7)
.into(),
1 => column![
text("Arrows").size(11).color(ACCENT),
row![lbl("Arrow size (DIMASZ)"), mk_field(DsField::Dimasz, vals.dimasz)].spacing(8).align_y(iced::Center),
row![lbl("Center mark (DIMCEN)"), mk_field(DsField::Dimcen, vals.dimcen)].spacing(8).align_y(iced::Center),
row![lbl("Tick size (DIMTSZ)"), mk_field(DsField::Dimtsz, vals.dimtsz)].spacing(8).align_y(iced::Center),
].spacing(7).into(),
row![
lbl("Arrow size (DIMASZ)"),
mk_field(DsField::Dimasz, vals.dimasz)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Center mark (DIMCEN)"),
mk_field(DsField::Dimcen, vals.dimcen)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Tick size (DIMTSZ)"),
mk_field(DsField::Dimtsz, vals.dimtsz)
]
.spacing(8)
.align_y(iced::Center),
]
.spacing(7)
.into(),
2 => column![
text("Text").size(11).color(ACCENT),
row![lbl("Height (DIMTXT)"), mk_field(DsField::Dimtxt, vals.dimtxt)].spacing(8).align_y(iced::Center),
row![lbl("Style (DIMTXSTY)"), mk_field(DsField::Dimtxsty, vals.dimtxsty)].spacing(8).align_y(iced::Center),
row![lbl("Vertical pos (DIMTAD)"), mk_field(DsField::Dimtad, vals.dimtad)].spacing(8).align_y(iced::Center),
row![
lbl("Height (DIMTXT)"),
mk_field(DsField::Dimtxt, vals.dimtxt)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Style (DIMTXSTY)"),
mk_field(DsField::Dimtxsty, vals.dimtxsty)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Vertical pos (DIMTAD)"),
mk_field(DsField::Dimtad, vals.dimtad)
]
.spacing(8)
.align_y(iced::Center),
chk("Horizontal inside (DIMTIH)", vals.dimtih, DsField::Dimtih),
chk("Horizontal outside (DIMTOH)", vals.dimtoh, DsField::Dimtoh),
].spacing(7).into(),
]
.spacing(7)
.into(),
3 => column![
text("Scale").size(11).color(ACCENT),
row![lbl("Overall scale (DIMSCALE)"), mk_field(DsField::Dimscale, vals.dimscale)].spacing(8).align_y(iced::Center),
row![lbl("Linear factor (DIMLFAC)"), mk_field(DsField::Dimlfac, vals.dimlfac)].spacing(8).align_y(iced::Center),
row![
lbl("Overall scale (DIMSCALE)"),
mk_field(DsField::Dimscale, vals.dimscale)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Linear factor (DIMLFAC)"),
mk_field(DsField::Dimlfac, vals.dimlfac)
]
.spacing(8)
.align_y(iced::Center),
text("Units").size(11).color(ACCENT),
row![lbl("Format (DIMLUNIT)"), mk_field(DsField::Dimlunit, vals.dimlunit)].spacing(8).align_y(iced::Center),
row![lbl("Decimals (DIMDEC)"), mk_field(DsField::Dimdec, vals.dimdec)].spacing(8).align_y(iced::Center),
row![lbl("Suffix (DIMPOST)"), mk_field(DsField::Dimpost, vals.dimpost)].spacing(8).align_y(iced::Center),
].spacing(7).into(),
row![
lbl("Format (DIMLUNIT)"),
mk_field(DsField::Dimlunit, vals.dimlunit)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Decimals (DIMDEC)"),
mk_field(DsField::Dimdec, vals.dimdec)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Suffix (DIMPOST)"),
mk_field(DsField::Dimpost, vals.dimpost)
]
.spacing(8)
.align_y(iced::Center),
]
.spacing(7)
.into(),
_ => column![
text("Tolerances").size(11).color(ACCENT),
chk("Generate tolerances (DIMTOL)", vals.dimtol, DsField::Dimtol),
chk("Limits generation (DIMLIM)", vals.dimlim, DsField::Dimlim),
row![lbl("Plus tolerance (DIMTP)"), mk_field(DsField::Dimtp, vals.dimtp)].spacing(8).align_y(iced::Center),
row![lbl("Minus tolerance (DIMTM)"), mk_field(DsField::Dimtm, vals.dimtm)].spacing(8).align_y(iced::Center),
row![lbl("Tol. decimals (DIMTDEC)"), mk_field(DsField::Dimtdec, vals.dimtdec)].spacing(8).align_y(iced::Center),
row![lbl("Tol. scale (DIMTFAC)"), mk_field(DsField::Dimtfac, vals.dimtfac)].spacing(8).align_y(iced::Center),
].spacing(7).into(),
chk("Limits generation (DIMLIM)", vals.dimlim, DsField::Dimlim),
row![
lbl("Plus tolerance (DIMTP)"),
mk_field(DsField::Dimtp, vals.dimtp)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Minus tolerance (DIMTM)"),
mk_field(DsField::Dimtm, vals.dimtm)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Tol. decimals (DIMTDEC)"),
mk_field(DsField::Dimtdec, vals.dimtdec)
]
.spacing(8)
.align_y(iced::Center),
row![
lbl("Tol. scale (DIMTFAC)"),
mk_field(DsField::Dimtfac, vals.dimtfac)
]
.spacing(8)
.align_y(iced::Center),
]
.spacing(7)
.into(),
};
// ── Right panel: tabs + scrollable content ────────────────────────────
@@ -229,20 +495,24 @@ pub fn view_window<'a>(
text(format!("Editing: {selected}")).size(11).color(DIM),
tabs,
hdivider(),
scrollable(
container(tab_content).padding([12, 12])
).height(Fill),
scrollable(container(tab_content).padding([12, 12])).height(Fill),
]
.spacing(6)
.height(Fill)
.height(Fill),
)
.height(Fill)
.width(Fill)
.padding(iced::Padding { top: 12.0, right: 12.0, bottom: 12.0, left: 0.0 });
.padding(iced::Padding {
top: 12.0,
right: 12.0,
bottom: 12.0,
left: 0.0,
});
// ── Vertical separator ────────────────────────────────────────────────
let vsep = container(Space::new().width(1).height(Fill))
.width(1).height(Fill)
.width(1)
.height(Fill)
.style(|_: &Theme| container::Style {
background: Some(Background::Color(BORDER)),
..Default::default()
@@ -250,14 +520,12 @@ pub fn view_window<'a>(
let body = row![style_list, vsep, right_panel].height(Fill);
container(
column![toolbar, hdivider(), body].spacing(0)
)
.style(|_: &Theme| container::Style {
background: Some(Background::Color(BG)),
..Default::default()
})
.width(Fill)
.height(Fill)
.into()
container(column![toolbar, hdivider(), body].spacing(0))
.style(|_: &Theme| container::Style {
background: Some(Background::Color(BG)),
..Default::default()
})
.width(Fill)
.height(Fill)
.into()
}