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} event_loop::{EventLoopBuilder, ControlFlow}
}; };
use hui::{ use hui::{
UiInstance, UiInstance, UiSize, UiDirection,
element::{ element::{
UiElement, UiElement,
progress_bar::ProgressBar, progress_bar::ProgressBar,
container::{Container, Sides, Alignment}, container::{Container, Sides, Alignment},
rect::Rect rect::Rect
}, },
interaction::IntoInteractable,
UiSize, UiDirection,
}; };
use hui_glium::GliumUiRenderer; use hui_glium::GliumUiRenderer;
@ -122,9 +120,7 @@ fn main() {
Box::new(Rect { Box::new(Rect {
size: (UiSize::Static(50.), UiSize::Static(50.)), size: (UiSize::Static(50.), UiSize::Static(50.)),
color: Some(vec4(1., 1., 1., 0.75)) color: Some(vec4(1., 1., 1., 0.75))
}.into_interactable().on_click(|| { }),
println!("clicked");
}))
], ],
..Default::default() ..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 struct Interactable<T: UiElement> {
pub element: T, // pub element: T,
pub hovered: Option<Box<dyn FnOnce()>>, // pub hovered: Option<Box<dyn FnOnce()>>,
pub clicked: Option<Box<dyn FnOnce()>>, // pub clicked: Option<Box<dyn FnOnce()>>,
} // }
impl<T: UiElement> Interactable<T> { // impl<T: UiElement> Interactable<T> {
pub fn new(element: T) -> Self { // pub fn new(element: T) -> Self {
Self { // Self {
element, // element,
hovered: None, // hovered: None,
clicked: None, // clicked: None,
} // }
} // }
pub fn on_click(self, clicked: impl FnOnce() + 'static) -> Self { // pub fn on_click(self, clicked: impl FnOnce() + 'static) -> Self {
Self { // Self {
clicked: Some(Box::new(clicked)), // clicked: Some(Box::new(clicked)),
..self // ..self
} // }
} // }
pub fn on_hover(self, clicked: impl FnOnce() + 'static) -> Self { // pub fn on_hover(self, clicked: impl FnOnce() + 'static) -> Self {
Self { // Self {
clicked: Some(Box::new(clicked)), // clicked: Some(Box::new(clicked)),
..self // ..self
} // }
} // }
} // }
impl<T: UiElement> UiElement for Interactable<T> { // impl<T: UiElement> UiElement for Interactable<T> {
fn measure(&self, ctx: MeasureContext) -> crate::measure::Response { // fn measure(&self, ctx: MeasureContext) -> crate::measure::Response {
self.element.measure(ctx) // self.element.measure(ctx)
} // }
fn process(&self, ctx: ProcessContext) { // fn process(&self, ctx: ProcessContext) {
self.element.process(ctx) // self.element.process(ctx)
} // }
} // }
pub trait IntoInteractable<T: UiElement>: UiElement { // pub trait IntoInteractable<T: UiElement>: UiElement {
fn into_interactable(self) -> Interactable<T>; // fn into_interactable(self) -> Interactable<T>;
} // }
impl<T: UiElement> IntoInteractable<T> for T { // impl<T: UiElement> IntoInteractable<T> for T {
fn into_interactable(self) -> Interactable<Self> { // fn into_interactable(self) -> Interactable<Self> {
Interactable::new(self) // Interactable::new(self)
} // }
} // }