work
This commit is contained in:
@@ -1,106 +1,101 @@
|
||||
use super::*;
|
||||
|
||||
pub fn werror(ui: &mut Ui, msg: &str) -> WidgetRef {
|
||||
pub fn werror(msg: &str, rsc: &mut Rsc) -> WidgetHandle {
|
||||
wtext(msg)
|
||||
.size(20)
|
||||
.pad(10)
|
||||
.background(rect(Color::RED).radius(10))
|
||||
.add(ui)
|
||||
.add_strong(rsc)
|
||||
}
|
||||
|
||||
pub fn hint(msg: impl Into<String>) -> TextBuilder {
|
||||
pub fn hint(msg: impl Into<String>) -> TextBuilder<Rsc> {
|
||||
wtext(msg).size(20).color(Color::GRAY)
|
||||
}
|
||||
|
||||
pub fn field_widget(name: &str, hint_text: &str, ui: &mut Ui) -> WidgetRef<TextEdit> {
|
||||
pub fn field_widget(name: &str, hint_text: &str, rsc: &mut Rsc) -> WidgetRef<TextEdit> {
|
||||
wtext(name)
|
||||
.editable(true)
|
||||
.editable(EditMode::SingleLine)
|
||||
.size(20)
|
||||
.hint(hint(hint_text))
|
||||
.add(ui)
|
||||
.add(rsc)
|
||||
}
|
||||
|
||||
pub fn field_box(field: WidgetRef<TextEdit>, ui: &mut Ui) -> WidgetRef {
|
||||
pub fn field_box(field: WidgetRef<TextEdit>, rsc: &mut Rsc) -> WidgetRef {
|
||||
field
|
||||
.clone()
|
||||
.pad(10)
|
||||
.background(rect(Color::BLACK.brighter(0.1)).radius(15))
|
||||
.attr::<Selector>(field)
|
||||
.add(ui)
|
||||
.add(rsc)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Copy, WidgetView)]
|
||||
pub struct Button {
|
||||
color: UiColor,
|
||||
#[root]
|
||||
root: WidgetRef,
|
||||
rect: WidgetRef<Rect>,
|
||||
enabled: Handle<bool>,
|
||||
}
|
||||
|
||||
impl WidgetView for Button {
|
||||
fn view(&self) -> &WidgetRef<Self::Widget> {
|
||||
&self.root
|
||||
}
|
||||
}
|
||||
// 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();
|
||||
pub fn new(text: &str, color: UiColor, rsc: &mut Rsc) -> Self {
|
||||
let rect = rect(color).radius(15).add(rsc);
|
||||
// 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);
|
||||
move |ctx, rsc: &mut Rsc| {
|
||||
// if !*enabled_.get() {
|
||||
// return;
|
||||
// }
|
||||
rsc.ui[ctx.widget].color = color.brighter(0.1);
|
||||
},
|
||||
)
|
||||
.on(CursorSense::HoverEnd, move |ctx| {
|
||||
if !*enabled__.get() {
|
||||
return;
|
||||
}
|
||||
ctx.widget.get_mut().color = color;
|
||||
.on(CursorSense::HoverEnd, move |ctx, rsc| {
|
||||
// if !*enabled__.get() {
|
||||
// return;
|
||||
// }
|
||||
rsc.ui[ctx.widget].color = color;
|
||||
})
|
||||
.height(60)
|
||||
.foreground(wtext(text).size(25).text_align(Align::CENTER))
|
||||
.add(ui);
|
||||
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);
|
||||
.add(rsc);
|
||||
// let enabled_ = enabled.clone();
|
||||
rect.on(CursorSense::click(), move |ctx, rsc: &mut Rsc| {
|
||||
// if !*enabled_.get() {
|
||||
// return;
|
||||
// }
|
||||
rsc.ui[ctx.widget].color = color.darker(0.2);
|
||||
rsc.run_event::<Submit>(root, (), ctx.state);
|
||||
})
|
||||
.add(rsc);
|
||||
Self {
|
||||
root,
|
||||
rect,
|
||||
color,
|
||||
enabled,
|
||||
// enabled,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn submit(text: &str, ui: &mut Ui) -> Self {
|
||||
Self::new(text, color::GREEN, ui)
|
||||
pub fn submit(text: &str, rsc: &mut Rsc) -> Self {
|
||||
Self::new(text, color::GREEN, rsc)
|
||||
}
|
||||
|
||||
pub fn disable(&self) {
|
||||
pub fn disable(&self, rsc: &mut Rsc) {
|
||||
*self.enabled.get_mut() = false;
|
||||
self.rect.get_mut().color = self.color.darker(0.8);
|
||||
}
|
||||
}
|
||||
|
||||
widget_trait! {
|
||||
pub trait Stuff;
|
||||
fn modal(self, width: impl UiNum) -> impl WidgetIdFn {
|
||||
pub trait Stuff<Rsc: HasUi + 'static>;
|
||||
fn modal(self, width: impl UiNum) -> impl WidgetIdFn<Rsc> {
|
||||
|ui| {
|
||||
self
|
||||
.pad(15)
|
||||
|
||||
Reference in New Issue
Block a user