tirbofish/dropbear · commit
f57db28bed5faab846765d141d4c86fb5f94f291
packing up for tomorrow, got an idea for UI (planning on using asm-like instruction sets. Unverified
@@ -38,6 +38,7 @@ use crate::physics::collider::ColliderGroup; use crate::physics::kcc::KCC; use crate::physics::rigidbody::RigidBody; use crate::states::{Camera3D, Light, Script, SerializedMeshRenderer}; +use crate::ui::UIComponent; /// The appdata directory for storing any information. /// @@ -67,6 +68,7 @@ pub fn register_components( component_registry.register_with_default::<RigidBody>(); component_registry.register_with_default::<ColliderGroup>(); component_registry.register_with_default::<KCC>(); + component_registry.register_with_default::<UIComponent>(); component_registry.register_converter::<MeshRenderer, SerializedMeshRenderer, _>( |_, _, renderer| { @@ -22,16 +22,46 @@ pub struct UIComponent { pub ui_file: ResourceReference, } +// note for tomorrow: use UIInstruction like that of asm + +#[derive(Default, Debug)] +pub enum UIInstruction { + #[default] + Nothing, + + StartColumn, + EndColumn, +} + pub struct UiContext { pub yakui_state: Mutex<Yakui>, - pub to_render: Mutex<Vec<Box<dyn FnOnce()>>>, + pub instruction_set: Mutex<Vec<UIInstruction>>, +} + +pub fn poll() { + UI_CONTEXT.with(|v| { + let ctx = v.borrow(); + let _yakui = ctx.yakui_state.lock(); + let instructions = ctx.instruction_set.lock().drain(..).collect::<Vec<UIInstruction>>(); + for i in instructions { + match i { + UIInstruction::StartColumn => { + + }, + UIInstruction::EndColumn => { + + }, + UIInstruction::Nothing => {} + } + } + }); } impl UiContext { pub fn new() -> Self { Self { yakui_state: Mutex::new(Yakui::new()), - to_render: Default::default(), + instruction_set: Default::default(), } } } @@ -42,20 +72,24 @@ pub mod jni { use crate::ui::{UiContext}; #[unsafe(no_mangle)] - pub extern "C" fn Java_YourClass_addOverlay( + pub extern "C" fn Java_foobar_addOverlay( _env: jni::JNIEnv, _class: jni::objects::JClass, ui_buf_ptr: jlong, ) { let ui = convert_ptr!(ui_buf_ptr => UiContext); - let mut state = ui.to_render.lock(); + ui.instruction_set.lock().push(crate::ui::UIInstruction::Nothing); + } + + #[unsafe(no_mangle)] + pub extern "C" fn Java_foobar_aisClicked( + _env: jni::JNIEnv, + _class: jni::objects::JClass, + ui_buf_ptr: jlong, + ) { + let _ui = convert_ptr!(ui_buf_ptr => UiContext); - state.push(Box::new(move || { - // yakui::colored_box( - // Color::rgba(255, 0, 0, 128), - // yakui::geometry::Vec2::new(width, height) - // ); - })); + // ui.yakui_state.lock() } } @@ -911,7 +911,7 @@ impl InspectableComponent for Script { _label: &mut String, ) { ui.vertical(|ui| { - CollapsingHeader::new("Tags") + CollapsingHeader::new("Logic") .default_open(true) .show(ui, |ui| { let mut local_del: Option<usize> = None; @@ -24,7 +24,7 @@ use dropbear_engine::{ use egui::{self, CollapsingHeader, Margin, RichText}; use egui_dock::TabViewer; use egui_ltreeview::{Action, NodeBuilder, TreeViewBuilder}; -use eucalyptus_core::hierarchy::{Children, Hierarchy, Parent}; +use eucalyptus_core::{hierarchy::{Children, Hierarchy, Parent}, ui::UIComponent}; use eucalyptus_core::states::{Label, Light, Script, PROJECT}; use eucalyptus_core::traits::registry::ComponentRegistry; use hecs::{Entity, EntityBuilder, World}; @@ -818,17 +818,32 @@ impl<'a> TabViewer for EditorTabViewer<'a> { } // script - if let Ok(script) = world.query_one::<&mut Script>(*entity).get() + if let Ok((script, ui_c)) = world.query_one::<(Option<&mut Script>, Option<&mut UIComponent>)>(*entity).get() { CollapsingHeader::new("Script").default_open(true).show(ui, |ui| { - script.inspect( - entity, - &mut cfg, - ui, - self.undo_stack, - self.signal, - label.as_mut_string(), - ); + if let Some(s) = script { + s.inspect( + entity, + &mut cfg, + ui, + self.undo_stack, + self.signal, + label.as_mut_string(), + ); + } + + if let Some(ui_c) = ui_c { + CollapsingHeader::new("UI").default_open(true).show(ui, |ui| { + ui_c.inspect( + entity, + &mut cfg, + ui, + self.undo_stack, + self.signal, + label.as_mut_string(), + ); + }); + } }); ui.separator(); } @@ -12,9 +12,6 @@ use hecs::Entity; use wgpu::{Color}; use wgpu::util::DeviceExt; use winit::event_loop::ActiveEventLoop; -use yakui::column; -use yakui::widgets::Button; -use yakui::widgets::{Layer, Pad}; use yakui_wgpu::SurfaceInfo; use dropbear_engine::camera::Camera; use dropbear_engine::buffer::ResizableBuffer; @@ -464,22 +461,18 @@ impl Scene for PlayMode { yakui.set_surface_size(yakui::geometry::Vec2::new(display_width, display_height)); yakui.start(); - let to_render = yak.to_render.lock().drain(..).collect::<Vec<_>>(); - - Layer::new().show(|| { - column(|| { - for f in to_render { - f() - } - - let button_response = Button::styled("My Button") - .padding(Pad::all(10.0)) - .show(); - if button_response.clicked { - println!("This is clicked!"); - } - }); - }); + eucalyptus_core::ui::poll(); + + // Layer::new().show(|| { + // column(|| { + // let button_response = Button::styled("My Button") + // .padding(Pad::all(10.0)) + // .show(); + // if button_response.clicked { + // println!("This is clicked!"); + // } + // }); + // }); yakui.finish(); });