mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-22 07:08:42 -06:00
somewhat less hacky...
This commit is contained in:
parent
3a4b0eea66
commit
7f28aebb97
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
input::InputCtx,
|
input::InputCtx,
|
||||||
layout::LayoutInfo,
|
layout::LayoutInfo,
|
||||||
measure::Response,
|
measure::Response,
|
||||||
signal::SignalCtx,
|
signal::SignalStore,
|
||||||
state::StateRepo,
|
state::StateRepo,
|
||||||
text::{FontHandle, TextMeasure},
|
text::{FontHandle, TextMeasure},
|
||||||
UiInstance,
|
UiInstance,
|
||||||
|
@ -36,7 +36,7 @@ pub struct ProcessContext<'a> {
|
||||||
pub current_font: FontHandle,
|
pub current_font: FontHandle,
|
||||||
pub images: ImageCtx<'a>,
|
pub images: ImageCtx<'a>,
|
||||||
pub input: InputCtx<'a>,
|
pub input: InputCtx<'a>,
|
||||||
pub signal: SignalCtx<'a>,
|
pub signal: &'a mut SignalStore,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait UiElement {
|
pub trait UiElement {
|
||||||
|
|
|
@ -9,7 +9,6 @@ use crate::{
|
||||||
layout::{Alignment, Alignment2d, Direction, LayoutInfo, Size, Size2d},
|
layout::{Alignment, Alignment2d, Direction, LayoutInfo, Size, Size2d},
|
||||||
measure::{Hints, Response},
|
measure::{Hints, Response},
|
||||||
rectangle::{Corners, Sides},
|
rectangle::{Corners, Sides},
|
||||||
signal::SignalCtx,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// pub struct Border {
|
// pub struct Border {
|
||||||
|
@ -456,7 +455,7 @@ impl UiElement for Container {
|
||||||
input: ctx.input,
|
input: ctx.input,
|
||||||
//HACK: i have no idea what to do with this
|
//HACK: i have no idea what to do with this
|
||||||
//this sucks
|
//this sucks
|
||||||
signal: SignalCtx(ctx.signal.0),
|
signal: ctx.signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
//layout
|
//layout
|
||||||
|
|
|
@ -56,8 +56,7 @@ impl<C: UiSignal + 'static> UiElement for Interactable<C> {
|
||||||
//XXX: should we do this AFTER normal process call of wrapped element?
|
//XXX: should we do this AFTER normal process call of wrapped element?
|
||||||
if ctx.input.check_click(rect) {
|
if ctx.input.check_click(rect) {
|
||||||
if let Some(sig) = self.signal.take() {
|
if let Some(sig) = self.signal.take() {
|
||||||
//HACK: Fucking whatever
|
ctx.signal.add(sig);
|
||||||
ctx.signal.0.add(sig);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
event::{EventQueue, UiEvent},
|
event::{EventQueue, UiEvent},
|
||||||
input::UiInputState,
|
input::UiInputState,
|
||||||
layout::{Direction, LayoutInfo},
|
layout::{Direction, LayoutInfo},
|
||||||
signal::{SigIntStore, UiSignal},
|
signal::{SignalStore, UiSignal},
|
||||||
state::StateRepo,
|
state::StateRepo,
|
||||||
text::{FontHandle, TextRenderer}
|
text::{FontHandle, TextRenderer}
|
||||||
};
|
};
|
||||||
|
@ -29,7 +29,7 @@ pub struct UiInstance {
|
||||||
atlas: TextureAtlasManager,
|
atlas: TextureAtlasManager,
|
||||||
events: EventQueue,
|
events: EventQueue,
|
||||||
input: UiInputState,
|
input: UiInputState,
|
||||||
signal: SigIntStore,
|
signal: SignalStore,
|
||||||
//True if in the middle of a laying out a frame
|
//True if in the middle of a laying out a frame
|
||||||
state: bool,
|
state: bool,
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ impl UiInstance {
|
||||||
},
|
},
|
||||||
events: EventQueue::new(),
|
events: EventQueue::new(),
|
||||||
input: UiInputState::new(),
|
input: UiInputState::new(),
|
||||||
signal: SigIntStore::new(),
|
signal: SignalStore::new(),
|
||||||
state: false,
|
state: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ impl UiInstance {
|
||||||
current_font: self.text_renderer.current_font(),
|
current_font: self.text_renderer.current_font(),
|
||||||
images: self.atlas.context(),
|
images: self.atlas.context(),
|
||||||
input: self.input.ctx(),
|
input: self.input.ctx(),
|
||||||
signal: self.signal.ctx(),
|
signal: &mut self.signal,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,18 @@ use nohash_hasher::BuildNoHashHasher;
|
||||||
/// A marker trait for signals
|
/// A marker trait for signals
|
||||||
pub trait UiSignal: Any {}
|
pub trait UiSignal: Any {}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
|
// #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
|
||||||
pub(crate) struct DummySignal;
|
// pub(crate) struct DummySignal;
|
||||||
impl UiSignal for DummySignal {}
|
// impl UiSignal for DummySignal {}
|
||||||
|
|
||||||
pub(crate) struct SigIntStore {
|
pub struct SignalStore {
|
||||||
///XXX: is this truly the most efficient structure?
|
///XXX: is this truly the most efficient structure?
|
||||||
sig: HashMap<TypeId, Vec<Box<dyn Any>>, BuildNoHashHasher<u64>>
|
sig: HashMap<TypeId, Vec<Box<dyn Any>>, BuildNoHashHasher<u64>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SigIntStore {
|
impl SignalStore {
|
||||||
/// Create a new [`SigIntStore`]
|
/// Create a new [`SigIntStore`]
|
||||||
pub fn new() -> Self {
|
pub(crate) fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
sig: Default::default(),
|
sig: Default::default(),
|
||||||
}
|
}
|
||||||
|
@ -41,22 +41,9 @@ impl SigIntStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Drain all signals of a given type
|
/// Drain all signals of a given type
|
||||||
pub fn drain<T: UiSignal + 'static>(&mut self) -> impl Iterator<Item = T> + '_ {
|
pub(crate) fn drain<T: UiSignal + 'static>(&mut self) -> impl Iterator<Item = T> + '_ {
|
||||||
self.internal_store::<T>()
|
self.internal_store::<T>()
|
||||||
.drain(..)
|
.drain(..)
|
||||||
.map(|x| *x.downcast::<T>().unwrap()) //unchecked?
|
.map(|x| *x.downcast::<T>().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<T: UiSignal + 'static>(&mut self, sig: T) {
|
|
||||||
self.0.add(sig);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue