use super::*; pub fn werror(msg: &str, rsc: &mut Rsc) -> StrongWidget { wtext(msg) .size(20) .pad(10) .background(rect(Color::RED).radius(10)) .add_strong(rsc) } pub fn hint(msg: impl Into) -> TextBuilder { wtext(msg).size(20).color(Color::GRAY) } pub fn field_widget(name: &str, hint_text: &str, rsc: &mut Rsc) -> WeakWidget { wtext(name) .editable(EditMode::SingleLine) .size(20) .hint(hint(hint_text)) .add(rsc) } pub fn field_box(field: WeakWidget, rsc: &mut Rsc) -> WeakWidget { field .pad(10) .background(rect(Color::BLACK.brighter(0.1)).radius(15)) .attr::(field) .add(rsc) } #[derive(Clone, Copy, WidgetView)] pub struct Button { #[root] root: WeakWidget, rect: WeakWidget, color: UiColor, enabled: WeakState, } impl Button { pub fn new(text: &str, color: UiColor, rsc: &mut Rsc) -> Self { let rect = rect(color).radius(15).add(rsc); let enabled = rsc.create_state(rect, true); let root = rect .on( CursorSense::HoverStart | CursorSense::unclick(), move |ctx, rsc: &mut Rsc| { if !rsc[enabled] { return; } rsc[ctx.widget].color = color.brighter(0.1); }, ) .on(CursorSense::HoverEnd, move |ctx, rsc| { if !rsc[enabled] { return; } rsc[ctx.widget].color = color; }) .height(60) .foreground(wtext(text).size(25).text_align(Align::CENTER)) .add(rsc); rect.on(CursorSense::click(), move |ctx, rsc: &mut Rsc| { if !rsc[enabled] { return; } rsc[ctx.widget].color = color.darker(0.2); rsc.run_event::(root, (), ctx.state); }) .add(rsc); Self { root, rect, color, enabled, } } pub fn submit(text: &str, rsc: &mut Rsc) -> Self { Self::new(text, color::GREEN, rsc) } pub fn disable(&self, rsc: &mut Rsc) { rsc[self.enabled] = false; rsc[self.rect].color = self.color.darker(0.8); } } widget_trait! { pub trait Stuff; fn modal(self, width: impl UiNum) -> impl WidgetIdFn { |rsc| { self .pad(15) .background(rect(color::MODAL_BG).radius(15)) .width(width) .align(Align::CENTER) .add(rsc) } } }