Skip to content

Commit

Permalink
print surface resource kind in the property editor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Jun 26, 2024
1 parent 4018c84 commit 8fc7a5d
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions editor/src/inspector/editors/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
FieldKind, InspectorError, PropertyChanged,
},
message::{MessageDirection, UiMessage},
text::TextBuilder,
text::{TextBuilder, TextMessage},
widget::{Widget, WidgetBuilder, WidgetMessage},
BuildContext, Control, Thickness, UiNode, UserInterface,
},
Expand Down Expand Up @@ -50,6 +50,7 @@ pub struct SurfaceDataPropertyEditor {
widget: Widget,
view: Handle<UiNode>,
data: SurfaceResource,
text: Handle<UiNode>,
#[visit(skip)]
#[reflect(hidden)]
sender: Option<MessageSender>,
Expand Down Expand Up @@ -104,16 +105,24 @@ impl Control for SurfaceDataPropertyEditor {
{
self.data = value.clone();
ui.send_message(message.reverse());

ui.send_message(TextMessage::text(
self.text,
MessageDirection::ToWidget,
surface_data_info(value),
));
}
}
}
}

fn surface_data_info(data: &SurfaceResource) -> String {
let use_count = data.use_count();
let kind = data.kind();
let guard = data.data_ref();
format!(
"Vertices: {}\nTriangles: {}\nUse Count: {}",
"{}\nVertices: {}\nTriangles: {}\nUse Count: {}",
kind,
guard.vertex_buffer.vertex_count(),
guard.geometry_buffer.len(),
use_count
Expand All @@ -138,26 +147,22 @@ impl SurfaceDataPropertyEditor {
.with_text("View...")
.build(ctx);

let text = TextBuilder::new(
WidgetBuilder::new()
.on_row(0)
.on_column(0)
.with_margin(Thickness::uniform(1.0)),
)
.with_text(surface_data_info(&data))
.build(ctx);

let widget = WidgetBuilder::new()
.with_child(
GridBuilder::new(
WidgetBuilder::new()
.with_child(
TextBuilder::new(
WidgetBuilder::new()
.on_row(0)
.on_column(0)
.with_margin(Thickness::uniform(1.0)),
)
.with_text(surface_data_info(&data))
.build(ctx),
)
.with_child(view),
)
.add_column(Column::stretch())
.add_column(Column::auto())
.add_row(Row::auto())
.build(ctx),
GridBuilder::new(WidgetBuilder::new().with_child(text).with_child(view))
.add_column(Column::stretch())
.add_column(Column::auto())
.add_row(Row::auto())
.build(ctx),
)
.with_allow_drop(true)
.build();
Expand All @@ -168,6 +173,7 @@ impl SurfaceDataPropertyEditor {
view,
sender: Some(sender),
resource_manager,
text,
};

ctx.add_node(UiNode::new(editor))
Expand Down

0 comments on commit 8fc7a5d

Please sign in to comment.