kitgit

tirbofish/dropbear · diff

f57db28 · Thribhu K

packing up for tomorrow, got an idea for UI (planning on using asm-like instruction sets. Unverified

diff --git a/crates/eucalyptus-core/src/lib.rs b/crates/eucalyptus-core/src/lib.rs
index 25f83a6..50a9e1f 100644
--- a/crates/eucalyptus-core/src/lib.rs
+++ b/crates/eucalyptus-core/src/lib.rs
@@ -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| {
diff --git a/crates/eucalyptus-core/src/ui.rs b/crates/eucalyptus-core/src/ui.rs
index fdf1724..bd919e3 100644
--- a/crates/eucalyptus-core/src/ui.rs
+++ b/crates/eucalyptus-core/src/ui.rs
@@ -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()
     }
 }
\ No newline at end of file
diff --git a/crates/eucalyptus-editor/src/editor/component.rs b/crates/eucalyptus-editor/src/editor/component.rs
index fd152e7..444b0fd 100644
--- a/crates/eucalyptus-editor/src/editor/component.rs
+++ b/crates/eucalyptus-editor/src/editor/component.rs
@@ -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;
diff --git a/crates/eucalyptus-editor/src/editor/dock.rs b/crates/eucalyptus-editor/src/editor/dock.rs
index 04f0bb3..90f604b 100644
--- a/crates/eucalyptus-editor/src/editor/dock.rs
+++ b/crates/eucalyptus-editor/src/editor/dock.rs
@@ -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();
                             }
diff --git a/crates/redback-runtime/src/scene.rs b/crates/redback-runtime/src/scene.rs
index a95edbe..d113714 100644
--- a/crates/redback-runtime/src/scene.rs
+++ b/crates/redback-runtime/src/scene.rs
@@ -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();
                     });