跳转到内容

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

ItemPurpose
DialogSpecTop-level dialog descriptor.
DialogGroupLabeled group of widgets.
UiWidgetOne UI element in a group.
WidgetKindWidget type and configuration.
ChoiceItemChoice/list item with value, display text, and optional description.
FieldKindBackwards-compatible alias for WidgetKind.
DialogFieldBackwards-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

ConstructorDescription
ChoiceItem::simple(value: &str) -> ChoiceItemUses the same string for value and display.
ChoiceItem::with_display(value: &str, display: &str) -> ChoiceItemUses separate stored value and display text.
ChoiceItem::full(value: &str, display: &str, description: &str) -> ChoiceItemAdds a tooltip/description.

WidgetKind

VariantOption TypePurpose
CheckBox { default }boolCheckbox.
SpinBox { min, max, step, default, suffix }intInteger spinner.
RealSpinBox { min, max, step, decimals, default, suffix }realFloating-point spinner.
TextLine { default, placeholder }stringSingle-line text input.
ComboBox { choices, default }stringDropdown list.
SingleSelectList { static_choices, inspection_key }stringSingle-select list, optionally populated by source inspection.
MultiSelectList { static_choices, inspection_key, value_separator }stringMulti-select list whose option value is separator-joined.
Note { text }NoneDisplay-only note.
SeparatorNoneDisplay-only separator line.

Builder Methods

DialogSpec builder methods consume and return Self, so dialog definitions can be chained.

MethodDescription
DialogSpec::new(title: &str) -> DialogSpecCreate an empty dialog.
group(label: &str) -> SelfStart a vertically stacked group.
group_in_row(label: &str, row: u8) -> SelfStart a group assigned to a horizontal row.
bool_field(option_name, label, default) -> SelfAdd a checkbox.
int_field(option_name, label, min, max, default) -> SelfAdd an integer spinner with step 1.
real_field(option_name, label, min, max, default) -> SelfAdd a floating-point spinner.
string_field(option_name, label, default) -> SelfAdd a text field.
combo_field(option_name, label, choices, default) -> SelfAdd a combo box from string choices.
single_select_list(option_name, label, static_choices, inspection_key) -> SelfAdd a single-select list.
multi_select_list(option_name, label, static_choices, inspection_key, value_separator) -> SelfAdd a multi-select list.
note(text: &str) -> SelfAdd a display-only note.
separator() -> SelfAdd a separator.
to_json() -> StringSerialize 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.