Skip to content

Commit

Permalink
live-preview: Enums in preview data mode
Browse files Browse the repository at this point in the history
... were shown as JSON, fix this!
  • Loading branch information
hunger committed Feb 21, 2025
1 parent 03b80df commit 34b115b
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tools/lsp/preview/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,14 +994,40 @@ fn map_value_and_type(
..Default::default()
});
}
Type::Enumeration(enumeration) => {
let selected_value = match &value {
Some(slint_interpreter::Value::EnumerationValue(_, k)) => enumeration
.values
.iter()
.position(|v| v.as_str() == k)
.unwrap_or(enumeration.default_value),
_ => enumeration.default_value,
};

mapping.header.push(mapping.name_prefix.clone());
mapping.current_values.push(PropertyValue {
kind: PropertyValueKind::Enum,
value_string: enumeration.name.as_str().into(),
default_selection: i32::try_from(enumeration.default_value).unwrap_or_default(),
value_int: i32::try_from(selected_value).unwrap_or_default(),
visual_items: Rc::new(VecModel::from(
enumeration
.values
.iter()
.map(|s| SharedString::from(s.as_str()))
.collect::<Vec<_>>(),
))
.into(),
..Default::default()
});
}
Type::Array(_)
| Type::Image
| Type::Model
| Type::PathData
| Type::Easing
| Type::Brush
| Type::Struct(_)
| Type::Enumeration(_)
| Type::UnitProduct(_) => {
mapping.is_too_complex = true;
}
Expand Down

0 comments on commit 34b115b

Please sign in to comment.