Dialog Specification
此内容尚不支持你的语言。
lc_plugin::dialog provides a declarative model for import/export options dialogs. Rust plugins describe dialog groups and widgets; the LinkCAD host renders the actual Qt UI.
Python plugins use the same model through DialogSpec in linkcad.v1.plugin.
Key Public Items
| Item | Purpose |
|---|---|
DialogSpec | Top-level dialog descriptor. |
DialogGroup | Labeled group of widgets. |
UiWidget | One UI element in a group. |
WidgetKind | Widget type and configuration. |
ChoiceItem | Choice/list item with value, display text, and optional description. |
FieldKind | Backwards-compatible alias for WidgetKind. |
DialogField | Backwards-compatible alias for UiWidget. |
Data Model
pub struct DialogSpec { pub title: String, pub groups: Vec<DialogGroup>,}
pub struct DialogGroup { pub label: String, pub row: Option<u8>, pub widgets: Vec<UiWidget>,}
pub struct UiWidget { pub option_name: Option<String>, pub label: String, pub kind: WidgetKind,}
pub struct ChoiceItem { pub value: String, pub display: String, pub description: Option<String>,}Consecutive groups with the same row are rendered side-by-side. Groups with no row, or different row values, stack vertically.
ChoiceItem
| Constructor | Description |
|---|---|
ChoiceItem::simple(value: &str) -> ChoiceItem | Uses the same string for value and display. |
ChoiceItem::with_display(value: &str, display: &str) -> ChoiceItem | Uses separate stored value and display text. |
ChoiceItem::full(value: &str, display: &str, description: &str) -> ChoiceItem | Adds a tooltip/description. |
WidgetKind
| Variant | Option Type | Purpose |
|---|---|---|
CheckBox { default } | bool | Checkbox. |
SpinBox { min, max, step, default, suffix } | int | Integer spinner. |
RealSpinBox { min, max, step, decimals, default, suffix } | real | Floating-point spinner. |
TextLine { default, placeholder } | string | Single-line text input. |
ComboBox { choices, default } | string | Dropdown list. |
SingleSelectList { static_choices, inspection_key } | string | Single-select list, optionally populated by source inspection. |
MultiSelectList { static_choices, inspection_key, value_separator } | string | Multi-select list whose option value is separator-joined. |
Note { text } | None | Display-only note. |
Separator | None | Display-only separator line. |
Builder Methods
DialogSpec builder methods consume and return Self, so dialog definitions can be chained.
| Method | Description |
|---|---|
DialogSpec::new(title: &str) -> DialogSpec | Create an empty dialog. |
group(label: &str) -> Self | Start a vertically stacked group. |
group_in_row(label: &str, row: u8) -> Self | Start a group assigned to a horizontal row. |
bool_field(option_name, label, default) -> Self | Add a checkbox. |
int_field(option_name, label, min, max, default) -> Self | Add an integer spinner with step 1. |
real_field(option_name, label, min, max, default) -> Self | Add a floating-point spinner. |
string_field(option_name, label, default) -> Self | Add a text field. |
combo_field(option_name, label, choices, default) -> Self | Add a combo box from string choices. |
single_select_list(option_name, label, static_choices, inspection_key) -> Self | Add a single-select list. |
multi_select_list(option_name, label, static_choices, inspection_key, value_separator) -> Self | Add a multi-select list. |
note(text: &str) -> Self | Add a display-only note. |
separator() -> Self | Add a separator. |
to_json() -> String | Serialize the dialog for the host. |
register_options() | Register all option-backed widgets with the host option store. |
Example
use lc_plugin::dialog::{ChoiceItem, DialogSpec};
fn import_dialog_spec() -> DialogSpec { DialogSpec::new("Import Options") .group("Geometry") .bool_field("ExampleInMerge", "Merge polygons", true) .int_field("ExampleInFacets", "Minimum facets", 4, 256, 32) .combo_field("ExampleInUnits", "Units", &["nm", "um", "mm"], "um") .group("Layers") .single_select_list( "ExampleInLayer", "Layer", &[ChoiceItem::with_display("metal1", "Metal 1")], Some("layers"), )}Register a dialog with the register_format! macro:
lc_plugin::register_format! { name: "Example Format", extensions: "*.exa", license: 0, plugin_name: "Example Plugin", description: "Example native Rust plugin", reader: || Box::new(ExampleReader::default()), writer: || Box::new(ExampleWriter::default()), import_dialog: import_dialog_spec(), export_dialog: export_dialog_spec(),}The macro registers options declared in the dialog and passes the serialized JSON to the host.
Dynamic Lists
Use single_select_list() or multi_select_list() with an inspection_key to populate choices from SourceInspector metadata. The inspection_key must match a list key in SourceMeta.