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 76 77 78
use orbclient::Renderer; use std::cell::{Cell, RefCell}; use std::sync::Arc; use cell::CloneCell; use draw::draw_box; use rect::{Rect}; use point::Point; use thickness::Thickness; use theme::{Selector, Theme}; use traits::{Place, Style}; use widgets::{Widget, VerticalPlacement, HorizontalPlacement}; pub struct Rectangle { pub rect: Cell<Rect>, local_position: Cell<Point>, vertical_placement: Cell<VerticalPlacement>, horizontal_placement: Cell<HorizontalPlacement>, margin: Cell<Thickness>, children: RefCell<Vec<Arc<dyn Widget>>>, pub selector: CloneCell<Selector>, } impl Rectangle { pub fn new() -> Arc<Self> { Arc::new(Rectangle { rect: Cell::new(Rect::default()), local_position: Cell::new(Point::new(0, 0)), vertical_placement: Cell::new(VerticalPlacement::Absolute), horizontal_placement: Cell::new(HorizontalPlacement::Absolute), margin: Cell::new(Thickness::default()), children: RefCell::new(vec![]), selector: CloneCell::new(Selector::new(Some("Rectangle"))), }) } } impl Place for Rectangle {} impl Style for Rectangle { fn selector(&self) -> &CloneCell<Selector> { &self.selector } } impl Widget for Rectangle { fn name(&self) -> &str { "Rectangle" } fn rect(&self) -> &Cell<Rect> { &self.rect } fn vertical_placement(&self) -> &Cell<VerticalPlacement> { &self.vertical_placement } fn horizontal_placement(&self) -> &Cell<HorizontalPlacement> { &self.horizontal_placement } fn margin(&self) -> &Cell<Thickness> { &self.margin } fn local_position(&self) -> &Cell<Point> { &self.local_position } fn draw(&self, renderer: &mut dyn Renderer, _focused: bool, theme: &Theme) { draw_box(renderer, self.rect().get(), theme, &self.selector().get()); } fn children(&self) -> &RefCell<Vec<Arc<dyn Widget>>> { &self.children } }