fixed layout of inheritable property editor + styling

This commit is contained in:
Dmitry Stepanov
2026-08-22 18:03:35 +03:00
parent 8b25b34db9
commit b88e4a09b6
10 changed files with 107 additions and 22 deletions
@@ -281,6 +281,7 @@ impl PropertyEditorDefinition for DynTypePropertyEditorDefinition {
},
ctx.name_column_width,
ctx.hide_name_column,
None,
ctx.build_context,
);
@@ -380,6 +380,7 @@ impl PropertyEditorDefinition for ScriptPropertyEditorDefinition {
},
ctx.name_column_width,
ctx.hide_name_column,
None,
ctx.build_context,
);
+10
View File
@@ -58,6 +58,16 @@ pub struct FieldMetadata<'s> {
pub precision: Option<usize>,
}
impl<'s> FieldMetadata<'s> {
pub fn description(&self) -> String {
if self.doc.is_empty() {
self.display_name.to_string()
} else {
format!("{}\n\n{}", self.display_name, self.doc)
}
}
}
pub struct FieldRef<'a, 'b> {
/// A reference to field's metadata.
pub metadata: &'a FieldMetadata<'b>,
+1
View File
@@ -360,6 +360,7 @@ where
},
ctx.name_column_width,
false,
None,
ctx.build_context,
);
@@ -497,6 +497,7 @@ where
},
ctx.name_column_width,
ctx.hide_name_column,
None,
ctx.build_context,
);
@@ -412,6 +412,7 @@ where
},
ctx.name_column_width,
ctx.hide_name_column,
None,
ctx.build_context,
);
+55 -9
View File
@@ -21,6 +21,8 @@
//! Property editor for [`InheritableVariable`]. It acts like a proxy to inner property, but also
//! adds a special "revert" button that is used to revert value to its parent's value.
use crate::brush::Brush;
use crate::inspector::{create_header, make_expander_container, make_simple_property_container};
use crate::{
button::{Button, ButtonBuilder, ButtonMessage},
core::{
@@ -210,28 +212,30 @@ where
let value = property_info.cast_value::<InheritableVariable<T>>()?;
let is_single_field = value.inner_value_ref().fields_count() <= 1;
let inspector_context = InspectorContext::from_object(InspectorContextArgs {
object: value,
ctx: ctx.build_context,
definition_container: ctx.definition_container.clone(),
environment: ctx.environment.clone(),
layer_index: 0,
layer_index: ctx.layer_index + 1,
generate_property_string_values: ctx.generate_property_string_values,
filter: ctx.filter,
name_column_width: ctx.name_column_width,
hide_name_column: true,
hide_name_column: is_single_field,
base_path: ctx.base_path.clone(),
has_parent_object: ctx.has_parent_object,
});
let editor = InspectorBuilder::new(WidgetBuilder::new())
let inspector = InspectorBuilder::new(WidgetBuilder::new())
.with_context(inspector_context)
.build(ctx.build_context)
.to_base();
let wrapper = InheritablePropertyEditorBuilder::new(WidgetBuilder::new())
.with_container(editor)
.with_inner_editor(editor)
let editor = InheritablePropertyEditorBuilder::new(WidgetBuilder::new())
.with_container(inspector)
.with_inner_editor(inspector)
.with_modified(
ctx.has_parent_object
&& ctx
@@ -239,10 +243,52 @@ where
.cast_value::<InheritableVariable<T>>()?
.is_modified(),
)
.build(ctx.build_context)
.to_base();
.build(ctx.build_context);
Ok(PropertyEditorInstance::Simple { editor: wrapper })
if is_single_field {
let title = if ctx.hide_name_column {
Handle::NONE
} else {
create_header(
ctx.build_context,
ctx.property_info.display_name,
0.0,
Some(Brush::solid(160, 160, 200)),
ctx.layer_index,
)
};
let container = make_simple_property_container(
title,
editor,
&ctx.property_info.description(),
ctx.name_column_width,
ctx.hide_name_column,
ctx.build_context,
);
Ok(PropertyEditorInstance::Custom {
container: container.to_base(),
editor: editor.to_base(),
})
} else {
let container = make_expander_container(
ctx.layer_index,
ctx.property_info.display_name,
ctx.property_info.doc,
Handle::<UiNode>::NONE,
editor,
ctx.name_column_width,
ctx.hide_name_column,
Some(Brush::solid(160, 160, 200)),
ctx.build_context,
);
Ok(PropertyEditorInstance::Custom {
container: container.to_base(),
editor: editor.to_base(),
})
}
}
fn create_message(
@@ -119,6 +119,7 @@ where
},
ctx.name_column_width,
ctx.hide_name_column,
None,
ctx.build_context,
);
@@ -110,6 +110,7 @@ where
},
ctx.name_column_width,
ctx.hide_name_column,
None,
ctx.build_context,
);
+35 -13
View File
@@ -22,6 +22,9 @@
//! structure or enumeration recursively. It's primary usage is provide unified and simple way of introspection.
//! See [`Inspector`] docs for more info and usage examples.
use crate::brush::Brush;
use crate::style::resource::StyleResourceExt;
use crate::style::{Style, StyledProperty};
use crate::{
border::BorderBuilder,
check_box::{CheckBox, CheckBoxBuilder},
@@ -1058,6 +1061,7 @@ fn make_expander_check_box(
property_name: &str,
property_description: &str,
hide_name: bool,
text_brush: Option<Brush>,
ctx: &mut BuildContext,
) -> Handle<CheckBox> {
let handle = CheckBoxBuilder::new(
@@ -1084,6 +1088,11 @@ fn make_expander_check_box(
};
TextBuilder::new(
WidgetBuilder::new()
.with_foreground(
text_brush
.map(StyledProperty::from)
.unwrap_or_else(|| ctx.style.property(Style::BRUSH_FOREGROUND)),
)
.with_opt_tooltip(make_tooltip(ctx, &description))
.with_height(16.0)
.with_margin(Thickness::left(2.0)),
@@ -1118,6 +1127,7 @@ pub fn make_expander_container(
content: Handle<impl ObjectOrVariant<UiNode>>,
width: f32,
hide_name_column: bool,
text_brush: Option<Brush>,
ctx: &mut BuildContext,
) -> Handle<UiNode> {
ExpanderBuilder::new(WidgetBuilder::new())
@@ -1126,6 +1136,7 @@ pub fn make_expander_container(
property_name,
description,
hide_name_column,
text_brush,
ctx,
))
.with_expander_column(if hide_name_column {
@@ -1144,12 +1155,21 @@ fn create_header(
ctx: &mut BuildContext,
text: &str,
offset: f32,
text_brush: Option<Brush>,
layer_index: usize,
) -> Handle<Text> {
TextBuilder::new(WidgetBuilder::new().with_margin(make_property_margin(offset, layer_index)))
.with_text(text)
.with_vertical_text_alignment(VerticalAlignment::Center)
.build(ctx)
TextBuilder::new(
WidgetBuilder::new()
.with_foreground(
text_brush
.map(StyledProperty::from)
.unwrap_or_else(|| ctx.style.property(Style::BRUSH_FOREGROUND)),
)
.with_margin(make_property_margin(offset, layer_index)),
)
.with_text(text)
.with_vertical_text_alignment(VerticalAlignment::Center)
.build(ctx)
}
fn make_tooltip(ctx: &mut BuildContext, text: &str) -> Option<RcUiNodeHandle> {
@@ -1160,7 +1180,7 @@ fn make_tooltip(ctx: &mut BuildContext, text: &str) -> Option<RcUiNodeHandle> {
}
}
fn make_simple_property_container(
pub fn make_simple_property_container(
title: Handle<Text>,
editor: Handle<impl ObjectOrVariant<UiNode>>,
description: &str,
@@ -1295,11 +1315,7 @@ impl InspectorContext {
continue;
}
let description = if info.doc.is_empty() {
info.display_name.to_string()
} else {
format!("{}\n\n{}", info.display_name, info.doc)
};
let description = info.description();
if let Some(definition) = definition_container
.definitions()
@@ -1333,7 +1349,13 @@ impl InspectorContext {
if hide_name_column {
Handle::NONE
} else {
create_header(ctx, info.display_name, 0.0, layer_index)
create_header(
ctx,
info.display_name,
0.0,
None,
layer_index,
)
},
editor,
&description,
@@ -1371,7 +1393,7 @@ impl InspectorContext {
"Unable to create property editor instance: Reason {e:?}"
));
make_simple_property_container(
create_header(ctx, info.display_name, 0.0, layer_index),
create_header(ctx, info.display_name, 0.0, None, layer_index),
TextBuilder::new(WidgetBuilder::new().on_row(i).on_column(1))
.with_wrap(WrapMode::Word)
.with_vertical_text_alignment(VerticalAlignment::Center)
@@ -1391,7 +1413,7 @@ impl InspectorContext {
editors.push(editor);
} else {
editors.push(make_simple_property_container(
create_header(ctx, info.display_name, 0.0, layer_index),
create_header(ctx, info.display_name, 0.0, None, layer_index),
TextBuilder::new(WidgetBuilder::new().on_row(i).on_column(1))
.with_wrap(WrapMode::Word)
.with_vertical_text_alignment(VerticalAlignment::Center)