mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-21 14:48:42 -06:00
drop interactable api for now
This commit is contained in:
parent
cd50736bfb
commit
afcaf5fbef
|
@ -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()
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
// }
|
||||
// }
|
||||
|
|
Loading…
Reference in a new issue