123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- use kahlo::math::PixelSideOffsets;
- use patina::{
- layout::{HorizontalAlignment, TableCell, VerticalAlignment},
- prelude::*,
- ui::{UIControlMsg, UIHandle},
- widget,
- };
- struct TableWindow {
- root: widget::PlainGroup<Self>,
- }
- impl TableWindow {
- fn new(uih: &mut UIHandle) -> Self {
- let mut group = widget::PlainGroup::new_table(uih);
- group.extend(
- vec![
- widget::Label::new_with_text(uih, "x0y0")
- .with_valign(VerticalAlignment::Centre)
- // .framed()
- .with_table_cell(TableCell::new(0, 0))
- .boxed(),
- widget::Label::new_with_text(uih, "x0y1 [left aligned]")
- .with_halign(HorizontalAlignment::Left)
- .with_valign(VerticalAlignment::Centre)
- .framed()
- .with_margins(PixelSideOffsets::new_all_same(15))
- .with_table_cell(TableCell::new(0, 1))
- .boxed(),
- widget::Label::new_with_text(uih, "x1y1")
- .with_valign(VerticalAlignment::Centre)
- // .framed()
- .with_table_cell(TableCell::new(1, 1))
- .boxed(),
- widget::Label::new_with_text(uih, "x1y2")
- .with_valign(VerticalAlignment::Centre)
- .framed()
- .with_table_cell(TableCell::new(1, 2))
- .boxed(),
- widget::Label::new_with_text(uih, "x3y2")
- .with_valign(VerticalAlignment::Centre)
- // .framed()
- .with_table_cell(TableCell::new(3, 2))
- .boxed(),
- ]
- .into_iter(),
- );
- Self { root: group }
- }
- }
- impl Component for TableWindow {
- type ParentMsg = UIControlMsg;
- type Msg = ();
- fn process(&mut self, _msg: Self::Msg) -> Vec<Self::ParentMsg> {
- let mut out = String::new();
- patina::layout::dump_node_tree(self.root.layout_node(), &mut out);
- std::fs::write("patina-table-layout-example.layout_tree", out)
- .expect("couldn't dump node tree");
- vec![UIControlMsg::Terminate]
- }
- }
- impl WindowComponent for TableWindow {
- fn map_window_event(&self, we: patina::window::WindowEvent) -> Option<Self::Msg> {
- match we {
- patina::window::WindowEvent::CloseRequested => Some(()),
- _ => None,
- }
- }
- type RootWidget = widget::PlainGroup<Self>;
- fn root_widget(&self) -> &Self::RootWidget {
- &self.root
- }
- fn root_widget_mut(&mut self) -> &mut Self::RootWidget {
- &mut self.root
- }
- }
- fn main() {
- patina::ui::make_opinionated_ui(TableWindow::new).run();
- }
|