From 7f28aebb978a90fe3d4bae2067f458be5b4a07b9 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 12 Mar 2024 01:26:48 +0100 Subject: [PATCH] somewhat less hacky... --- hui/src/element.rs | 4 ++-- hui/src/element/builtin/container.rs | 3 +-- hui/src/element/builtin/interactable.rs | 3 +-- hui/src/instance.rs | 8 ++++---- hui/src/signal.rs | 27 +++++++------------------ 5 files changed, 15 insertions(+), 30 deletions(-) diff --git a/hui/src/element.rs b/hui/src/element.rs index 783be0b..4f4ac52 100644 --- a/hui/src/element.rs +++ b/hui/src/element.rs @@ -6,7 +6,7 @@ use crate::{ input::InputCtx, layout::LayoutInfo, measure::Response, - signal::SignalCtx, + signal::SignalStore, state::StateRepo, text::{FontHandle, TextMeasure}, UiInstance, @@ -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: &'a mut SignalStore, } pub trait UiElement { diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index a98a33c..65084c6 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -9,7 +9,6 @@ use crate::{ layout::{Alignment, Alignment2d, Direction, LayoutInfo, Size, Size2d}, measure::{Hints, Response}, rectangle::{Corners, Sides}, - signal::SignalCtx, }; // pub struct Border { @@ -456,7 +455,7 @@ impl UiElement for Container { input: ctx.input, //HACK: i have no idea what to do with this //this sucks - signal: SignalCtx(ctx.signal.0), + signal: ctx.signal, }); //layout diff --git a/hui/src/element/builtin/interactable.rs b/hui/src/element/builtin/interactable.rs index eb4d8a8..1773bbf 100644 --- a/hui/src/element/builtin/interactable.rs +++ b/hui/src/element/builtin/interactable.rs @@ -56,8 +56,7 @@ 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() { - //HACK: Fucking whatever - ctx.signal.0.add(sig); + ctx.signal.add(sig); } } diff --git a/hui/src/instance.rs b/hui/src/instance.rs index 4f7a88c..b23ed6c 100644 --- a/hui/src/instance.rs +++ b/hui/src/instance.rs @@ -8,7 +8,7 @@ use crate::{ event::{EventQueue, UiEvent}, input::UiInputState, layout::{Direction, LayoutInfo}, - signal::{SigIntStore, UiSignal}, + signal::{SignalStore, UiSignal}, state::StateRepo, text::{FontHandle, TextRenderer} }; @@ -29,7 +29,7 @@ pub struct UiInstance { atlas: TextureAtlasManager, events: EventQueue, input: UiInputState, - signal: SigIntStore, + signal: SignalStore, //True if in the middle of a laying out a frame state: bool, } @@ -57,7 +57,7 @@ impl UiInstance { }, events: EventQueue::new(), input: UiInputState::new(), - signal: SigIntStore::new(), + signal: SignalStore::new(), state: false, } } @@ -135,7 +135,7 @@ impl UiInstance { current_font: self.text_renderer.current_font(), images: self.atlas.context(), input: self.input.ctx(), - signal: self.signal.ctx(), + signal: &mut self.signal, }); } diff --git a/hui/src/signal.rs b/hui/src/signal.rs index 637a97d..238655a 100644 --- a/hui/src/signal.rs +++ b/hui/src/signal.rs @@ -5,18 +5,18 @@ use nohash_hasher::BuildNoHashHasher; /// A marker trait for signals pub trait UiSignal: Any {} -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)] -pub(crate) struct DummySignal; -impl UiSignal for DummySignal {} +// #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)] +// pub(crate) struct DummySignal; +// impl UiSignal for DummySignal {} -pub(crate) struct SigIntStore { +pub struct SignalStore { ///XXX: is this truly the most efficient structure? sig: HashMap>, BuildNoHashHasher> } -impl SigIntStore { +impl SignalStore { /// Create a new [`SigIntStore`] - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { sig: Default::default(), } @@ -41,22 +41,9 @@ impl SigIntStore { } /// Drain all signals of a given type - pub fn drain(&mut self) -> impl Iterator + '_ { + pub(crate) fn drain(&mut self) -> impl Iterator + '_ { self.internal_store::() .drain(..) .map(|x| *x.downcast::().unwrap()) //unchecked? } - - pub fn ctx(&mut self) -> SignalCtx { - SignalCtx(self) - } -} - -pub struct SignalCtx<'a>(pub(crate) &'a mut SigIntStore); - -impl<'a> SignalCtx<'a> { - /// Add a signal to the store - pub fn push(&mut self, sig: T) { - self.0.add(sig); - } }