Jelajahi Sumber

Minor cleanups.

Kestrel 3 bulan lalu
induk
melakukan
975b4debe3
6 mengubah file dengan 9 tambahan dan 15 penghapusan
  1. 1 2
      examples/form_demo.rs
  2. 0 4
      examples/simplest.rs
  3. 5 4
      src/layout/arr/table.rs
  4. 1 2
      src/layout/cache.rs
  5. 0 1
      src/layout/calc.rs
  6. 2 2
      src/window.rs

+ 1 - 2
examples/form_demo.rs

@@ -1,6 +1,6 @@
 use kahlo::math::PixelSideOffsets;
 use patina::{
-    layout::{HorizontalAlignment, TableCell, VerticalAlignment, SizePolicy},
+    layout::SizePolicy,
     prelude::*,
     ui::{UIControlMsg, UIHandle},
     widget,
@@ -14,7 +14,6 @@ impl FormWindow {
     fn new(uih: &mut UIHandle) -> Self {
         let mut group = widget::FormGroup::new(uih);
         group.layout_node_mut().set_height_policy(SizePolicy::fixed(0));
-        // XXX: left margin not working??
         group.set_label_margin(PixelSideOffsets::new(0, 10, 0, 10));
         group.add_widget("button", widget::Button::new_with_label(uih, "engage").boxed());
         group.add_widget("button 2", widget::Button::new_with_label(uih, "engage").boxed());

+ 0 - 4
examples/simplest.rs

@@ -7,8 +7,6 @@ struct SimpleWindow {
 impl SimpleWindow {
     fn new(uih: &mut patina::ui::UIHandle) -> Self {
         Self {
-            // widget: patina::widget::Spacer::new(uih),
-            // widget: patina::widget::Label::new(uih),
             widget: patina::widget::Frame::new(uih),
         }
     }
@@ -37,8 +35,6 @@ impl WindowComponent for SimpleWindow {
         }
     }
 
-    // type RootWidget = patina::widget::Spacer<Self>;
-    // type RootWidget = patina::widget::Label<Self>;
     type RootWidget = patina::widget::Frame<Self>;
     fn root_widget(&self) -> &Self::RootWidget {
         &self.widget

+ 5 - 4
src/layout/arr/table.rs

@@ -1,10 +1,9 @@
 use super::{do_fit, ArrangementCalculator};
 use crate::{
     layout::{
-        cache::{LayoutCacheKey, NodeState},
-        LayoutNodeAccess, SizePolicy, TableCell, TableSize, SizePolicy2D,
+        LayoutNodeAccess, SizePolicy, SizePolicy2D,
     },
-    math::{PixelBox, PixelPoint, PixelSize},
+    math::{PixelBox, PixelPoint},
 };
 use std::ops::Add;
 
@@ -91,6 +90,8 @@ impl ArrangementCalculator for TableArrangement {
         let mut row_offsets = vec![0];
         row_offsets.extend(do_fit(inside.height(), tstate.row_policies.into_iter()));
 
+        let child_offset = inside.min.to_vector();
+
         for ch in node.child_iter() {
             let Some(cell) = ch.table_cell() else {
                 continue;
@@ -101,7 +102,7 @@ impl ArrangementCalculator for TableArrangement {
                 PixelPoint::new(col_offsets[cell.x + 1], row_offsets[cell.y + 1]),
             );
 
-            ch.child_arrangement.layout_step(ch, cbox);
+            ch.child_arrangement.layout_step(ch, cbox.translate(child_offset));
         }
     }
 }

+ 1 - 2
src/layout/cache.rs

@@ -1,6 +1,6 @@
 use std::{cell::RefCell, collections::HashMap, rc::Rc};
 
-use super::{SizePolicy, TableCell, SizePolicy2D};
+use super::SizePolicy2D;
 
 #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
 pub struct LayoutCacheKey(usize);
@@ -19,7 +19,6 @@ pub struct NodeState {
     pub(super) layer: Layer,
     pub(super) area: Option<kahlo::math::PixelBox>,
     pub(super) children: Vec<LayoutCacheKey>,
-    pub(super) layout_state: Option<Box<dyn std::any::Any>>,
 }
 
 #[derive(Debug, Default)]

+ 0 - 1
src/layout/calc.rs

@@ -47,7 +47,6 @@ fn arrangement_pass(parent: Option<LayoutCacheKey>, node: LayoutNodeAccess, laye
                 area: None,
                 layer,
                 children: child_ids,
-                layout_state: None,
             },
         );
     }

+ 2 - 2
src/window.rs

@@ -115,8 +115,8 @@ impl<WC: WindowComponent> WindowState<WC> {
 
         // now put the pre-render layout dump on the window
         // again, we're doing this the dumb way
-        let mut offset = 0;
-        /*for text in pre_render_dump.split('\n') {
+        /*let mut offset = 0;
+        for text in pre_render_dump.split('\n') {
             if text.is_empty() {
                 continue;
             }