From 3a4b0eea667f3ec19f3ac7d89e6e3bb94ef7ecf5 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 12 Mar 2024 01:23:26 +0100 Subject: [PATCH] well it somewhat works, build using terrible hacks --- hui-examples/examples/ui_test_5_input.rs | 16 +++++++++++----- hui/src/element.rs | 2 +- hui/src/element/builtin/container.rs | 10 +++++++--- hui/src/element/builtin/interactable.rs | 3 ++- hui/src/element/builtin/transformer.rs | 1 + hui/src/instance.rs | 1 + hui/src/signal.rs | 2 +- 7 files changed, 24 insertions(+), 11 deletions(-) diff --git a/hui-examples/examples/ui_test_5_input.rs b/hui-examples/examples/ui_test_5_input.rs index f714a50..4367db4 100644 --- a/hui-examples/examples/ui_test_5_input.rs +++ b/hui-examples/examples/ui_test_5_input.rs @@ -41,11 +41,17 @@ ui_main!( Text::new("-") .add_child(ui); }) - .on_click(CounterSignal::Increment) + .on_click(CounterSignal::Decrement) .add_child(ui); - Text::new(counter.to_string()) - .with_color(color::BLACK) - .with_text_size(32) + Container::default() + .with_size(size!(20, auto)) + .with_align(Alignment::Center) + .with_children(|ui| { + Text::new(counter.to_string()) + .with_color(color::BLACK) + .with_text_size(32) + .add_child(ui); + }) .add_child(ui); Container::default() .with_padding(10.) @@ -55,7 +61,7 @@ ui_main!( Text::new("+") .add_child(ui); }) - .on_click(CounterSignal::Decrement) + .on_click(CounterSignal::Increment) .add_child(ui); }) .add_root(ui, size); diff --git a/hui/src/element.rs b/hui/src/element.rs index f3f2164..783be0b 100644 --- a/hui/src/element.rs +++ b/hui/src/element.rs @@ -36,7 +36,7 @@ pub struct ProcessContext<'a> { pub current_font: FontHandle, pub images: ImageCtx<'a>, pub input: InputCtx<'a>, - //pub signal: SignalCtx<'a>, + pub signal: SignalCtx<'a>, } pub trait UiElement { diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index 4308e65..a98a33c 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -4,11 +4,12 @@ use derive_setters::Setters; use glam::{Vec2, vec2}; use crate::{ background::BackgroundColor, - draw::{RoundedCorners, ImageHandle, UiDrawCommand}, + draw::{ImageHandle, RoundedCorners, UiDrawCommand}, element::{ElementList, MeasureContext, ProcessContext, UiElement}, - layout::{Alignment, Alignment2d, LayoutInfo, Size, Size2d, Direction}, + layout::{Alignment, Alignment2d, Direction, LayoutInfo, Size, Size2d}, measure::{Hints, Response}, - rectangle::{Corners, Sides} + rectangle::{Corners, Sides}, + signal::SignalCtx, }; // pub struct Border { @@ -453,6 +454,9 @@ impl UiElement for Container { current_font: ctx.current_font, images: ctx.images, input: ctx.input, + //HACK: i have no idea what to do with this + //this sucks + signal: SignalCtx(ctx.signal.0), }); //layout diff --git a/hui/src/element/builtin/interactable.rs b/hui/src/element/builtin/interactable.rs index 8aa2079..eb4d8a8 100644 --- a/hui/src/element/builtin/interactable.rs +++ b/hui/src/element/builtin/interactable.rs @@ -56,7 +56,8 @@ impl UiElement for Interactable { //XXX: should we do this AFTER normal process call of wrapped element? if ctx.input.check_click(rect) { if let Some(sig) = self.signal.take() { - //ctx.signal.push(sig); + //HACK: Fucking whatever + ctx.signal.0.add(sig); } } diff --git a/hui/src/element/builtin/transformer.rs b/hui/src/element/builtin/transformer.rs index a9ab5db..f04812b 100644 --- a/hui/src/element/builtin/transformer.rs +++ b/hui/src/element/builtin/transformer.rs @@ -57,6 +57,7 @@ impl UiElement for Transformer { current_font: ctx.current_font, images: ctx.images, input: ctx.input, + signal: ctx.signal, }); ctx.draw.add(UiDrawCommand::PopTransform); } diff --git a/hui/src/instance.rs b/hui/src/instance.rs index f70491e..4f7a88c 100644 --- a/hui/src/instance.rs +++ b/hui/src/instance.rs @@ -135,6 +135,7 @@ impl UiInstance { current_font: self.text_renderer.current_font(), images: self.atlas.context(), input: self.input.ctx(), + signal: self.signal.ctx(), }); } diff --git a/hui/src/signal.rs b/hui/src/signal.rs index f6768ec..637a97d 100644 --- a/hui/src/signal.rs +++ b/hui/src/signal.rs @@ -52,7 +52,7 @@ impl SigIntStore { } } -pub struct SignalCtx<'a>(&'a mut SigIntStore); +pub struct SignalCtx<'a>(pub(crate) &'a mut SigIntStore); impl<'a> SignalCtx<'a> { /// Add a signal to the store