feat(view): one list of visual styles behind every way of choosing one

The ribbon offered four styles and dispatched each one's id as a command.
Two of those ids were not visual-style commands: "Shaded" carried SOLID,
which draws a 2D filled polygon, so choosing it started a draw command;
"Hidden" carried HIDDEN, which matched nothing at all, so it did nothing.
The intent had been for the button to fire its tool's event, but the
dropdown never reads one -- it dispatches the id.

Behind that sat two generations of the same feature. The render-mode
picker offered the seven styles a viewport can actually be drawn in;
everything else -- the ribbon, VSCURRENT, SHADEMODE, VISUALSTYLES and a
handful of bare verbs -- went through a binary wireframe-or-shaded flag
that could only approximate them, reporting "Hidden (shown shaded)" and
"X-Ray (shown as wireframe)" when asked for something it had no way to
draw. Four descriptions of one choice, each drifting on its own.

There is one list now. Each style names itself once -- mode, label, icon,
and the command that applies it -- and the ribbon, the picker, the
VISUALSTYLES verb and the interactive prompt all read from it, down to
the line that lists the choices, so what is offered cannot disagree with
what works. Keywords are the render modes' own names, since there is one
set of styles left to name.

The binary path is gone rather than kept alongside: its message, its
module event, the tool definitions that produced it, the ribbon's
special-cased highlight arms, the bare style verbs and the older keyword
spellings. X-Ray goes with it -- no render mode draws one, and it was
already coming out as a plain wireframe. Three files that had been left
holding a single icon constant each fold into the list.

Note: ModuleEvent::SetWireframe leaves the plugin API with it.

Closes #621

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 5 committed 2026-08-07 14:15:59 +03:00
1 parent 5c5c7606a1
commit b5a1146966
18 files changed
+170 -187

No files matched your search

-10
View File
@@ -1,10 +0,0 @@
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub const ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/hidden.svg"));
pub fn tool() -> ToolDef {
ToolDef {
id: "HIDDENLINE",
label: "Hidden",
icon: ICON,
event: ModuleEvent::Command("HIDDENLINE".to_string()),
}
}
+7 -12
View File
@@ -2,7 +2,6 @@
mod cascade;
mod file_tabs;
mod hidden;
mod layout_tabs;
pub mod limits;
mod orbit;
@@ -13,9 +12,9 @@ pub mod plot_window;
pub mod quick_print;
mod properties_palette;
mod sheetset;
mod solid;
mod tile_horiz;
mod tile_vert;
pub mod visual_style;
mod tool_palettes;
pub mod ucs_cmd;
mod ucs_icon;
@@ -28,8 +27,6 @@ mod vports_config;
mod vports_join;
mod vports_named;
mod vports_restore;
mod wireframe;
mod xray;
mod zoom_ext;
mod zoom_in;
mod zoom_out;
@@ -89,14 +86,12 @@ impl CadModule for ViewModule {
tools: vec![RibbonItem::LargeDropdown {
id: "VISUAL_STYLE",
label: "Visual\nStyle",
icon: wireframe::tool().icon,
items: vec![
("WIREFRAME", "Wireframe", wireframe::tool().icon),
("SOLID", "Shaded", solid::tool().icon),
("HIDDEN", "Hidden", hidden::tool().icon),
("XRAY", "X-Ray", xray::tool().icon),
],
default: "WIREFRAME",
icon: visual_style::VISUAL_STYLES[0].icon,
items: visual_style::VISUAL_STYLES
.iter()
.map(|style| (style.command, style.label, style.icon))
.collect(),
default: visual_style::VISUAL_STYLES[0].command,
}],
},
// ── Projection ────────────────────────────────────────────────────
-13
View File
@@ -1,13 +0,0 @@
// Solid (Shaded) visual style toggle.
// id "SOLID" is special-cased in ribbon.rs for active-state highlighting.
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub const ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/solid.svg"));
pub fn tool() -> ToolDef {
ToolDef {
id: "SOLID",
label: "Solid",
icon: ICON,
event: ModuleEvent::SetWireframe(false),
}
}
+126
View File
@@ -0,0 +1,126 @@
// The visual styles a viewport can be drawn in, in one list.
//
// Three places offer the same choice and used to describe it separately: the
// Visual Style dropdown on the ribbon, the render-mode picker with its preview
// cube, and the VISUALSTYLES command. The ribbon's copy had drifted furthest —
// it named four styles, two of which reached nothing (its "Shaded" carried the
// id `SOLID`, which is the 2D solid *drawing* command, and `HIDDEN` matched no
// command at all). Naming each style once, next to the command that applies it,
// is what keeps the three in step. (#621)
use std::sync::OnceLock;
use acadrust::entities::ViewportRenderMode as Mode;
use crate::modules::IconKind;
const WIREFRAME_ICON: IconKind =
IconKind::Svg(include_bytes!("../../../assets/icons/wireframe.svg"));
const HIDDEN_ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/hidden.svg"));
const SHADED_ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/solid.svg"));
pub struct VisualStyle {
pub mode: Mode,
/// What the user sees, wherever the style is offered.
pub label: &'static str,
/// The command line that applies it. Ribbon items dispatch this verbatim,
/// so it doubles as the item's identity for the checkmark and the
/// last-used-tool memory. The keyword is the render mode's own name — there
/// is one set of styles now, so there is one set of names for them.
pub command: &'static str,
pub icon: IconKind,
}
/// Every style, in the order they are offered — wireframes, then hidden line,
/// then the shaded ones, each pair plain before with-edges.
pub const VISUAL_STYLES: &[VisualStyle] = &[
VisualStyle {
mode: Mode::Wireframe2D,
label: "Wireframe 2D",
command: "VISUALSTYLES WIREFRAME2D",
icon: WIREFRAME_ICON,
},
VisualStyle {
mode: Mode::Wireframe3D,
label: "Wireframe 3D",
command: "VISUALSTYLES WIREFRAME3D",
icon: WIREFRAME_ICON,
},
VisualStyle {
mode: Mode::HiddenLine,
label: "Hidden Line",
command: "VISUALSTYLES HIDDENLINE",
icon: HIDDEN_ICON,
},
VisualStyle {
mode: Mode::FlatShaded,
label: "Flat Shaded",
command: "VISUALSTYLES FLATSHADED",
icon: SHADED_ICON,
},
VisualStyle {
mode: Mode::GouraudShaded,
label: "Gouraud Shaded",
command: "VISUALSTYLES GOURAUDSHADED",
icon: SHADED_ICON,
},
VisualStyle {
mode: Mode::FlatShadedWithEdges,
label: "Flat Shaded + Edges",
command: "VISUALSTYLES FLATSHADEDWITHEDGES",
icon: SHADED_ICON,
},
VisualStyle {
mode: Mode::GouraudShadedWithEdges,
label: "Gouraud Shaded + Edges",
command: "VISUALSTYLES GOURAUDSHADEDWITHEDGES",
icon: SHADED_ICON,
},
];
impl VisualStyle {
/// The bare keyword, without the verb its `command` spells out.
pub fn keyword(&self) -> &'static str {
self.command
.strip_prefix("VISUALSTYLES ")
.unwrap_or(self.command)
}
}
/// The choices an interactive style prompt offers, in table order.
pub fn keyword_choices() -> Vec<(&'static str, &'static str, Option<&'static str>)> {
VISUAL_STYLES
.iter()
.map(|style| (style.label, style.keyword(), None))
.collect()
}
/// The prompt those choices are announced with. Built once from the table so
/// the line the user reads cannot list something the picker does not offer.
pub fn keyword_prompt() -> &'static str {
static PROMPT: OnceLock<String> = OnceLock::new();
PROMPT
.get_or_init(|| {
let listed: Vec<&str> = VISUAL_STYLES.iter().map(|style| style.label).collect();
format!("Visual style [{}]:", listed.join(" / "))
})
.as_str()
}
pub fn label_for(mode: Mode) -> &'static str {
VISUAL_STYLES
.iter()
.find(|style| style.mode == mode)
.map(|style| style.label)
.unwrap_or("Wireframe 2D")
}
/// The style a style keyword names. Only the seven exist; nothing maps onto a
/// nearest neighbour, because there is no longer anything else to map from.
pub fn mode_for_keyword(keyword: &str) -> Option<Mode> {
let keyword = keyword.trim().to_uppercase();
VISUAL_STYLES
.iter()
.find(|style| style.keyword() == keyword)
.map(|style| style.mode)
}
-13
View File
@@ -1,13 +0,0 @@
// Wireframe visual style toggle.
// id "WIREFRAME" is special-cased in ribbon.rs for active-state highlighting.
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub const ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/wireframe.svg"));
pub fn tool() -> ToolDef {
ToolDef {
id: "WIREFRAME",
label: "Wireframe",
icon: ICON,
event: ModuleEvent::SetWireframe(true),
}
}
-10
View File
@@ -1,10 +0,0 @@
use crate::modules::{IconKind, ModuleEvent, ToolDef};
pub const ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/xray.svg"));
pub fn tool() -> ToolDef {
ToolDef {
id: "XRAY",
label: "X-Ray",
icon: ICON,
event: ModuleEvent::Command("XRAY".to_string()),
}
}