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
// // Copyright (C) 2019 Robert Gill <locke@sdf.org> // // This file is a part of newt-rs. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License version 2.1 as published by the Free Software Foundation. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // use std::cell::Cell; use newt_sys::*; use crate::component::Component; use crate::constants::{NEWT_GRID_COMPONENT,NEWT_GRID_SUBGRID}; /// /// Create a simple window using sub-grids. /// #[derive(Grid)] pub struct BasicWindow<'a> { grid: Cell<newtGrid>, added_to_parent: Cell<bool>, children: Vec<&'a dyn Component> } impl<'a> BasicWindow<'a> { /// /// Create a new BasicWindow grid. /// /// * `text` - A text component to be displayed at the top of the window. /// * `middle` - A sub-grid to display in the middle of the window. /// * `buttons` - A sub-grid to display at the bottom of the window, /// hopefully containing buttons. /// pub fn new(text: &'a dyn Component, middle: &'a dyn Component, buttons: &'a dyn Component) -> BasicWindow<'a> { assert_eq!(text.grid_element_type(), NEWT_GRID_COMPONENT); assert_eq!(middle.grid_element_type(), NEWT_GRID_SUBGRID); assert_eq!(buttons.grid_element_type(), NEWT_GRID_SUBGRID); let grid = unsafe { newtGridBasicWindow(text.co(), middle.grid_ptr(), buttons.grid_ptr()) }; let mut children: Vec<&'a dyn Component> = Vec::new(); children.push(text); children.push(middle); children.push(buttons); BasicWindow { grid: Cell::new(grid), added_to_parent: Cell::new(false), children } } }