Files
OneCAD-Draft/src/ui/style_list.rs
T
Hakan SevenandClaude Opus 4.8 b3ba3a53d1 feat(styles): green ✓ for current style + resolve it from DWG files
- The current-style marker is now a green ✓ in its own fixed-width column
  so names stay aligned; rendered as a separate coloured glyph rather than
  baked into the label string.
- Resolve the current text / dimension / multiline style from the handle
  the DWG header stores into the name the app reads (fix_current_style_names
  on load). DXF already provides these as names ($TEXTSTYLE / $DIMSTYLE /
  $CMLSTYLE); DWG only stores handles, so the marker previously always fell
  back to "Standard". Only overrides when the handle resolves.

Note: table and multileader current styles are not surfaced by the file
reader (no header name/handle exposed), so those markers still default to
the app's active selection until acadrust exposes them.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 15:56:13 +03:00

85 lines
2.7 KiB
Rust

//! Shared style-manager list row.
//!
//! Every style manager renders the same left-hand list of style names where a
//! single click selects and a double click renames inline.
//!
//! The whole row is a `mouse_area` (not a `button`): an inner interactive
//! widget would capture the press and the parent `mouse_area` would never see
//! the second click, so `on_double_click` would never fire. `mouse_area`
//! carries both `on_press` (select) and `on_double_click` (rename) itself.
use crate::app::{Message, StyleKind};
use iced::widget::{container, mouse_area, row, text, text_input};
use iced::{Background, Color, Element, Fill, Theme};
/// Shared id for the inline rename field, so the rename-start handler can focus
/// it the moment the row turns editable.
pub fn rename_input_id() -> iced::widget::Id {
iced::widget::Id::new("style-rename-input")
}
const TEXT: Color = Color {
r: 0.88,
g: 0.88,
b: 0.88,
a: 1.0,
};
const ACTIVE: Color = Color {
r: 0.20,
g: 0.40,
b: 0.70,
a: 1.0,
};
const CURRENT_CHECK: Color = Color {
r: 0.30,
g: 0.82,
b: 0.36,
a: 1.0,
};
/// One row of the style list. Renders an editable `text_input` when `name` is
/// the style being renamed (`rename_active`), otherwise a selectable row whose
/// double click starts the rename. The current style gets a green ✓.
pub fn item<'a>(
name: &str,
is_current: bool,
is_selected: bool,
kind: StyleKind,
on_select: Message,
rename_active: Option<&str>,
rename_buf: &'a str,
) -> Element<'a, Message> {
if rename_active == Some(name) {
text_input("", rename_buf)
.id(iced::widget::Id::new("style-rename-input"))
.on_input(Message::StyleRenameEdit)
.on_submit(Message::StyleRenameCommit(kind))
.size(11)
.padding([4, 8])
.width(Fill)
.into()
} else {
// Fixed-width ✓ column keeps every name left-aligned whether or not the
// row is current.
let check = if is_current {
text("✓").size(11).color(CURRENT_CHECK)
} else {
text("").size(11)
};
let label = row![check.width(14), text(name.to_string()).size(11).color(TEXT)]
.align_y(iced::Center);
let cell = container(label)
.padding([4, 8])
.width(Fill)
.style(move |_: &Theme| container::Style {
background: is_selected.then_some(Background::Color(ACTIVE)),
text_color: Some(TEXT),
..Default::default()
});
mouse_area(cell)
.on_press(on_select)
.on_double_click(Message::StyleRenameStart(kind, name.to_string()))
.into()
}
}