123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- use patina::{
- layout::SizePolicy,
- 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(uih);
- group
- .layout_node_mut()
- .set_arrangement(patina::layout::ChildArrangement::Column)
- .set_width_policy(SizePolicy::expands(1))
- .set_height_policy(SizePolicy::expands(1));
- group.append(Box::new(widget::Spacer::new(uih)));
- group.append(Box::new({
- let mut button = widget::Button::new(uih);
- button.set_label("Button label");
- button.set_hook(Box::new(|| Some(ButtonWindowMsg::Shutdown)));
- button
- }));
- group.append(Box::new(widget::Spacer::new(uih)));
- 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();
- }
|