drop interactable api for now

This commit is contained in:
griffi-gh 2024-02-20 15:57:57 +01:00
parent 770cae8acc
commit 972c086a32
2 changed files with 45 additions and 49 deletions

View file

@ -6,15 +6,13 @@ use winit::{
event_loop::{EventLoopBuilder, ControlFlow}
};
use hui::{
UiInstance,
UiInstance, UiSize, UiDirection,
element::{
UiElement,
progress_bar::ProgressBar,
container::{Container, Sides, Alignment},
rect::Rect
},
interaction::IntoInteractable,
UiSize, UiDirection,
};
use hui_glium::GliumUiRenderer;
@ -122,9 +120,7 @@ fn main() {
Box::new(Rect {
size: (UiSize::Static(50.), UiSize::Static(50.)),
color: Some(vec4(1., 1., 1., 0.75))
}.into_interactable().on_click(|| {
println!("clicked");
}))
}),
],
..Default::default()
})

View file

@ -1,51 +1,51 @@
use crate::element::{UiElement, MeasureContext, ProcessContext};
// use crate::element::{UiElement, MeasureContext, ProcessContext};
pub struct Interactable<T: UiElement> {
pub element: T,
pub hovered: Option<Box<dyn FnOnce()>>,
pub clicked: Option<Box<dyn FnOnce()>>,
}
// pub struct Interactable<T: UiElement> {
// pub element: T,
// pub hovered: Option<Box<dyn FnOnce()>>,
// pub clicked: Option<Box<dyn FnOnce()>>,
// }
impl<T: UiElement> Interactable<T> {
pub fn new(element: T) -> Self {
Self {
element,
hovered: None,
clicked: None,
}
}
// impl<T: UiElement> Interactable<T> {
// pub fn new(element: T) -> Self {
// Self {
// element,
// hovered: None,
// clicked: None,
// }
// }
pub fn on_click(self, clicked: impl FnOnce() + 'static) -> Self {
Self {
clicked: Some(Box::new(clicked)),
..self
}
}
// pub fn on_click(self, clicked: impl FnOnce() + 'static) -> Self {
// Self {
// clicked: Some(Box::new(clicked)),
// ..self
// }
// }
pub fn on_hover(self, clicked: impl FnOnce() + 'static) -> Self {
Self {
clicked: Some(Box::new(clicked)),
..self
}
}
}
// pub fn on_hover(self, clicked: impl FnOnce() + 'static) -> Self {
// Self {
// clicked: Some(Box::new(clicked)),
// ..self
// }
// }
// }
impl<T: UiElement> UiElement for Interactable<T> {
fn measure(&self, ctx: MeasureContext) -> crate::measure::Response {
self.element.measure(ctx)
}
// impl<T: UiElement> UiElement for Interactable<T> {
// fn measure(&self, ctx: MeasureContext) -> crate::measure::Response {
// self.element.measure(ctx)
// }
fn process(&self, ctx: ProcessContext) {
self.element.process(ctx)
}
}
// fn process(&self, ctx: ProcessContext) {
// self.element.process(ctx)
// }
// }
pub trait IntoInteractable<T: UiElement>: UiElement {
fn into_interactable(self) -> Interactable<T>;
}
// pub trait IntoInteractable<T: UiElement>: UiElement {
// fn into_interactable(self) -> Interactable<T>;
// }
impl<T: UiElement> IntoInteractable<T> for T {
fn into_interactable(self) -> Interactable<Self> {
Interactable::new(self)
}
}
// impl<T: UiElement> IntoInteractable<T> for T {
// fn into_interactable(self) -> Interactable<Self> {
// Interactable::new(self)
// }
// }