finally usable state stuff ig
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
use iris::winit::attr::Selector;
|
||||
|
||||
use super::*;
|
||||
|
||||
pub fn werror(ui: &mut Ui, msg: &str) -> WidgetRef {
|
||||
@@ -33,27 +31,72 @@ pub fn field_box(field: WidgetRef<TextEdit>, ui: &mut Ui) -> WidgetRef {
|
||||
.any()
|
||||
}
|
||||
|
||||
pub fn submit_button(
|
||||
text: &str,
|
||||
on_submit: impl Fn(&mut Client, &mut Ui) + 'static,
|
||||
) -> impl WidgetRet {
|
||||
let color = Color::rgb(0, 200, 0);
|
||||
rect(color)
|
||||
.radius(15)
|
||||
.on(CursorSense::click(), move |ctx| {
|
||||
ctx.widget.get_mut().color = color.darker(0.2);
|
||||
on_submit(ctx.state, ctx.ui);
|
||||
})
|
||||
.on(
|
||||
CursorSense::HoverStart | CursorSense::unclick(),
|
||||
move |ctx| {
|
||||
ctx.widget.get_mut().color = color.brighter(0.1);
|
||||
},
|
||||
)
|
||||
.on(CursorSense::HoverEnd, move |ctx| {
|
||||
ctx.widget.get_mut().color = color;
|
||||
})
|
||||
.height(60)
|
||||
.foreground(wtext(text).size(25).text_align(Align::CENTER))
|
||||
.to_any()
|
||||
#[derive(Clone)]
|
||||
pub struct Button {
|
||||
color: UiColor,
|
||||
root: WidgetRef,
|
||||
rect: WidgetRef<Rect>,
|
||||
enabled: Handle<bool>,
|
||||
}
|
||||
|
||||
impl WidgetView for Button {
|
||||
fn view(&self) -> &WidgetRef<Self::Widget> {
|
||||
&self.root
|
||||
}
|
||||
}
|
||||
|
||||
impl Button {
|
||||
pub fn new(text: &str, color: UiColor, ui: &mut Ui) -> Self {
|
||||
let rect = rect(color).radius(15).add(ui);
|
||||
let enabled = Handle::from(true);
|
||||
let enabled_ = enabled.clone();
|
||||
let enabled__ = enabled.clone();
|
||||
let root = rect
|
||||
.clone()
|
||||
.on(
|
||||
CursorSense::HoverStart | CursorSense::unclick(),
|
||||
move |ctx| {
|
||||
if !*enabled_.get() {
|
||||
return;
|
||||
}
|
||||
ctx.widget.get_mut().color = color.brighter(0.1);
|
||||
},
|
||||
)
|
||||
.on(CursorSense::HoverEnd, move |ctx| {
|
||||
if !*enabled__.get() {
|
||||
return;
|
||||
}
|
||||
ctx.widget.get_mut().color = color;
|
||||
})
|
||||
.height(60)
|
||||
.foreground(wtext(text).size(25).text_align(Align::CENTER))
|
||||
.add(ui)
|
||||
.any();
|
||||
let root_ = root.clone();
|
||||
let enabled_ = enabled.clone();
|
||||
rect.clone()
|
||||
.on(CursorSense::click(), move |ctx| {
|
||||
if !*enabled_.get() {
|
||||
return;
|
||||
}
|
||||
ctx.widget.get_mut().color = color.darker(0.2);
|
||||
ctx.ui.run_event(ctx.state, &root_, Submit, ());
|
||||
})
|
||||
.add(ui);
|
||||
Self {
|
||||
root,
|
||||
rect,
|
||||
color,
|
||||
enabled,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn submit(text: &str, ui: &mut Ui) -> Self {
|
||||
Self::new(text, color::GREEN, ui)
|
||||
}
|
||||
|
||||
pub fn disable(&self) {
|
||||
*self.enabled.get_mut() = false;
|
||||
self.rect.get_mut().color = self.color.darker(0.8);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user