1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- use patina::{
- prelude::*,
- ui::{UIControlMsg, UIHandle},
- widget,
- };
- enum ButtonWindowMsg {
- Shutdown,
- }
- struct ButtonWindow {
- group: widget::PlainGroup<Self>,
- }
- impl ButtonWindow {
- fn new(uih: &mut UIHandle) -> Self {
- let mut group = widget::PlainGroup::new_column(uih);
- group.extend(vec![
- Box::new(widget::Spacer::new(uih)) as Box<dyn Widget<Self>>,
- Box::new({
- let mut button = widget::Button::new(uih);
- button.set_label("Button label");
- button.set_hook(Box::new(|| Some(ButtonWindowMsg::Shutdown)));
- button
- }),
- Box::new(widget::Spacer::new(uih)),
- ].into_iter());
- Self { group }
- }
- }
- impl Component for ButtonWindow {
- type ParentMsg = UIControlMsg;
- type Msg = ButtonWindowMsg;
- fn process(&mut self, msg: Self::Msg) -> Vec<Self::ParentMsg> {
- match msg {
- ButtonWindowMsg::Shutdown => vec![UIControlMsg::Terminate],
- }
- }
- }
- impl WindowComponent for ButtonWindow {
- fn map_window_event(&self, we: patina::window::WindowEvent) -> Option<Self::Msg> {
- match we {
- patina::window::WindowEvent::CloseRequested => Some(ButtonWindowMsg::Shutdown),
- _ => None,
- }
- }
- type RootWidget = widget::PlainGroup<Self>;
- fn root_widget(&self) -> &Self::RootWidget {
- &self.group
- }
- fn root_widget_mut(&mut self) -> &mut Self::RootWidget {
- &mut self.group
- }
- }
- fn main() {
- patina::ui::make_opinionated_ui(ButtonWindow::new).run();
- }
|