property editor for vertex buffer

This commit is contained in:
Dmitry Stepanov
2026-03-03 19:29:11 +03:00
parent ec2a3006c2
commit 8ca1245031
2 changed files with 92 additions and 2 deletions
+6 -2
View File
@@ -164,21 +164,22 @@ use crate::{
},
},
message::MessageSender,
plugins::inspector::editors::dyntype::DynTypePropertyEditorDefinition,
plugins::inspector::editors::shader::field::ShaderSourceCodeEditorDefinition,
plugins::{
inspector::editors::{
animation::{
AnimationContainerPropertyEditorDefinition, AnimationPropertyEditorDefinition,
MachinePropertyEditorDefinition,
},
dyntype::DynTypePropertyEditorDefinition,
font::FontPropertyEditorDefinition,
handle::NodeHandlePropertyEditorDefinition,
resource::ResourceFieldPropertyEditorDefinition,
script::ScriptPropertyEditorDefinition,
shader::field::ShaderSourceCodeEditorDefinition,
spritesheet::SpriteSheetFramesContainerEditorDefinition,
surface::SurfaceDataPropertyEditorDefinition,
texture::TexturePropertyEditorDefinition,
vertex_buffer::VertexBufferPropertyEditorDefinition,
},
tilemap::{
OptionTileDefinitionHandlePropertyEditorDefinition,
@@ -211,6 +212,7 @@ pub mod shader;
pub mod spritesheet;
pub mod surface;
pub mod texture;
mod vertex_buffer;
pub fn make_status_enum_editor_definition() -> EnumPropertyEditorDefinition<Status> {
EnumPropertyEditorDefinition {
@@ -682,6 +684,8 @@ pub fn make_property_editors_container(
container.insert(InspectablePropertyEditorDefinition::<CommandDescriptor>::new());
container.insert(HotKeyPropertyEditorDefinition);
container.insert(VertexBufferPropertyEditorDefinition);
reg_node_handle_editors!(
container,
sender,
@@ -0,0 +1,86 @@
// Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
use crate::fyrox::{
gui::{
inspector::{
editors::{
PropertyEditorBuildContext, PropertyEditorDefinition, PropertyEditorInstance,
PropertyEditorMessageContext, PropertyEditorTranslationContext,
},
InspectorError, PropertyChanged,
},
message::UiMessage,
text::{TextBuilder, TextMessage},
widget::WidgetBuilder,
Thickness, VerticalAlignment,
},
scene::mesh::buffer::VertexBuffer,
};
use std::any::TypeId;
#[derive(Debug)]
pub struct VertexBufferPropertyEditorDefinition;
fn vertex_buffer_description(vertex_buffer: &VertexBuffer) -> String {
format!(
"Vertices: {}\nVertex Size: {}\nAttributes: {}",
vertex_buffer.vertex_count(),
vertex_buffer.vertex_size(),
vertex_buffer.layout().len()
)
}
impl PropertyEditorDefinition for VertexBufferPropertyEditorDefinition {
fn value_type_id(&self) -> TypeId {
TypeId::of::<VertexBuffer>()
}
fn create_instance(
&self,
ctx: PropertyEditorBuildContext,
) -> Result<PropertyEditorInstance, InspectorError> {
let value = ctx.property_info.cast_value::<VertexBuffer>()?;
Ok(PropertyEditorInstance::simple(
TextBuilder::new(
WidgetBuilder::new()
.with_margin(Thickness::top_bottom(1.0))
.with_vertical_alignment(VerticalAlignment::Center),
)
.with_text(vertex_buffer_description(value))
.build(ctx.build_context),
))
}
fn create_message(
&self,
ctx: PropertyEditorMessageContext,
) -> Result<Option<UiMessage>, InspectorError> {
let value = ctx.property_info.cast_value::<VertexBuffer>()?;
Ok(Some(UiMessage::for_widget(
ctx.instance,
TextMessage::Text(vertex_buffer_description(value)),
)))
}
fn translate_message(&self, _ctx: PropertyEditorTranslationContext) -> Option<PropertyChanged> {
None
}
}