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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
use rin::events::{Property, StreamRc, StreamT}; use rin::math::{Pnt2, origin, Rect}; use rin::color::{consts::WHITE, Rgb}; use rin::graphics::{vertex::*, Ttf}; use rin::window; use control_shape::ControlShape; use traits::*; pub struct Separator{ name: String, pos: Property<'static, Pnt2>, width: Property<'static, f32>, height: Property<'static, f32>, events: StreamRc<'static, window::Event>, color: Rgb<f32>, } pub struct SeparatorBuilder{ name: String, control_shape: ControlShape, events: StreamRc<'static, window::Event>, } pub struct SepH(f32); pub fn sep_h(sep: f32) -> SepH{ SepH(sep) } impl BuilderFromProperty<SepH> for SeparatorBuilder{ fn from_parameter<S: StreamT<'static, window::Event>>(property: SepH, name: &str, events: S) -> SeparatorBuilder{ let pos = Property::new(origin()); let width = Property::new(property.0); let height = Property::new(0.0); SeparatorBuilder{ name: name.to_owned(), control_shape: ControlShape::new(pos, width, height, 0., 0., WHITE), events: events.rc(), } } } impl ControlDefaultProperty for SepH{ type Builder = SeparatorBuilder; } pub struct SepV(pub f32); pub fn sep_v(sep: f32) -> SepV{ SepV(sep) } impl BuilderFromProperty<SepV> for SeparatorBuilder{ fn from_parameter<S: StreamT<'static, window::Event>>(property: SepV, name: &str, events: S) -> SeparatorBuilder{ let pos = Property::new(origin()); let width = Property::new(0.0); let height = Property::new(property.0); SeparatorBuilder{ name: name.to_owned(), control_shape: ControlShape::new(pos, width, height, 0., 0., WHITE), events: events.rc(), } } } impl ControlDefaultProperty for SepV{ type Builder = SeparatorBuilder; } impl ControlBuilder for SeparatorBuilder{ type Control = Separator; fn shape(&mut self) -> &mut ControlShape{ &mut self.control_shape } fn create(self) -> Separator{ Separator{ pos: self.control_shape.position(), width: self.control_shape.width(), height: self.control_shape.height(), name: self.name, events: self.events, color: self.control_shape.color(), } } } impl Control for Separator{ fn name(&self) -> &str{ &self.name } } impl ControlEvents for Separator{ fn non_attended(&self) -> StreamRc<'static, window::Event>{ self.events.clone() } } impl ControlGeometry for Separator{ fn flexible() -> bool{ false } fn geometry(&self, _container: Option<&Rect<f32>>) -> Option<Vec<Vertex2DColor>>{ None } fn text_geometry(&self, _container: Option<&Rect<f32>>) -> Option<Vec<Vertex2DTex>>{ None } fn texture_geometry(&self, _container: Option<&Rect<f32>>) -> Option<Vec<Vertex2DTex>>{ None } fn font(&self) -> Option<&Ttf>{ None } fn color(&self) -> &Rgb<f32>{ &self.color } fn position(&self) -> &Property<'static, Pnt2>{ &self.pos } fn width(&self) -> &Property<'static, f32>{ &self.width } fn height(&self) -> &Property<'static, f32>{ &self.height } }