1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
//! Useful types for GTK extensions. /// Specifies the position of a widget in a [`Grid`][Grid]. /// /// The primary use of this struct is to fetch the current /// position of a widget in the grid via /// [`GridExtHelpers::get_child_position`][get_child_position]. /// /// [Grid]: ../../gtk/struct.Grid.html /// [get_child_position]: ../ext/trait.GridExtHelpers.html#tymethod.get_child_position #[derive(Debug, Clone, PartialEq)] pub struct GridPosition { /// The column in the grid for the widget. pub left: i32, /// The row in the grid for the widget. pub top: i32, /// The number of columns the widget will span in the grid. pub width: i32, /// The number of rows the widget will span in the grid. pub height: i32, } /// These builder methods allow for an alternate syntax to be used when building /// grid layouts. A brief example: /// /// ```rust,no_run /// # use vgtk::{gtk, VNode, types::GridPosition}; /// # use vgtk::ext::*; /// # use vgtk::lib::gtk::*; /// # fn build() -> VNode<()> { gtk! { /// <Grid row_spacing=10 column_spacing=10> /// <Label label="Label1:" halign=Align::End /> /// <Entry Grid::position=GridPosition::default().with_left(1) hexpand=true /> /// </Grid> /// # }} /// ``` impl GridPosition { /// Specify the left/column position of the widget. pub fn with_left(mut self, left: i32) -> Self { self.left = left; self } /// Specify the top/row position of the widget. pub fn with_top(mut self, top: i32) -> Self { self.top = top; self } /// Specify the column span for the widget. pub fn with_width(mut self, width: i32) -> Self { self.width = width; self } /// Specify the row span for the widget. pub fn with_height(mut self, height: i32) -> Self { self.height = height; self } } impl Default for GridPosition { fn default() -> Self { Self { left: 0, top: 0, width: 1, height: 1, } } }