well it somewhat works, build using terrible hacks

This commit is contained in:
griffi-gh 2024-03-12 01:23:26 +01:00
parent 969d0400d2
commit 3a4b0eea66
7 changed files with 24 additions and 11 deletions

View file

@ -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);

View file

@ -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 {

View file

@ -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

View file

@ -56,7 +56,8 @@ impl<C: UiSignal + 'static> UiElement for Interactable<C> {
//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);
}
}

View file

@ -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);
}

View file

@ -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(),
});
}

View file

@ -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