Files
OneCAD-Draft/src/ui/style_list.rs
T
Hakan SevenandClaude Opus 4.8 f2dfd01795 feat(styles): unify the five style managers behind a shared frame
The text/dimension/table/multileader/multiline managers were hand-copied,
so their list CRUD kept drifting and breaking: Dimension's New created
nothing (#73), new text styles never reached the ribbon dropdown (#74),
and several were added with a NULL handle (dropped on DWG save, #67).

Collapse the duplicated parts into three shared pieces and leave only the
per-manager property editor bespoke:

- app/style_ops.rs: one StyleKind-dispatched CRUD layer (new / copy /
  delete / rename) handling handle allocation, ribbon sync, Table re-key
  and name-reference rewrites in a single place.
- ui/style_manager.rs: the window scaffold — uniform toolbar (New / Copy /
  Delete on the left, Set Current + Apply on the right), style list and
  chrome. Each manager now only builds its editor.
- ui/style_list.rs: the list row — single click selects, double click
  starts an inline rename.

New capabilities, now consistent across all five:
- Copy duplicates the selected style.
- Double-click a name to rename it inline.
- Right side is always Set Current + Apply (added Table set-current;
  MLine apply is a documented placeholder until its editor is editable).

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

44 lines
1.4 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. Only the row's
//! button style differs per manager, so it is passed in.
use crate::app::{Message, StyleKind};
use iced::widget::button::{Status, Style};
use iced::widget::{button, mouse_area, text, text_input};
use iced::{Element, Fill, Theme};
/// One row of the style list. Renders an editable `text_input` when `name` is
/// the style being renamed (`rename_active`), otherwise a selectable button
/// wrapped in a `mouse_area` whose double click starts the rename.
pub fn item<'a>(
name: &str,
label: String,
kind: StyleKind,
on_select: Message,
rename_active: Option<&str>,
rename_buf: &'a str,
style: impl Fn(&Theme, Status) -> Style + 'a,
) -> Element<'a, Message> {
if rename_active == Some(name) {
text_input("", rename_buf)
.on_input(Message::StyleRenameEdit)
.on_submit(Message::StyleRenameCommit(kind))
.size(11)
.padding([4, 8])
.width(Fill)
.into()
} else {
mouse_area(
button(text(label).size(11))
.on_press(on_select)
.style(style)
.padding([4, 8])
.width(Fill),
)
.on_double_click(Message::StyleRenameStart(kind, name.to_string()))
.into()
}
}