decoration.rs (2513B)
1 use winsys::geometry::Extents; 2 use winsys::geometry::Padding; 3 4 use std::ops::Add; 5 6 pub type Color = u32; 7 8 #[derive(Debug, Copy, Clone, PartialEq, Eq)] 9 pub struct ColorScheme { 10 pub focused: Color, 11 pub fdisowned: Color, 12 pub fsticky: Color, 13 pub unfocused: Color, 14 pub udisowned: Color, 15 pub usticky: Color, 16 pub urgent: Color, 17 } 18 19 impl ColorScheme { 20 pub const DEFAULT: Self = Self { 21 focused: 0xe78a53, 22 fdisowned: 0xc1c1c1, 23 fsticky: 0x5f8787, 24 unfocused: 0x333333, 25 udisowned: 0x999999, 26 usticky: 0x444444, 27 urgent: 0xfbcb97, 28 }; 29 } 30 31 impl Default for ColorScheme { 32 fn default() -> Self { 33 Self::DEFAULT 34 } 35 } 36 37 #[derive(Debug, Copy, Clone, PartialEq, Eq)] 38 pub struct Border { 39 pub width: u32, 40 pub colors: ColorScheme, 41 } 42 43 impl Add<Border> for Padding { 44 type Output = Self; 45 46 fn add( 47 self, 48 border: Border, 49 ) -> Self::Output { 50 Self::Output { 51 left: self.left + border.width as i32, 52 right: self.right + border.width as i32, 53 top: self.top + border.width as i32, 54 bottom: self.bottom + border.width as i32, 55 } 56 } 57 } 58 59 #[derive(Debug, Copy, Clone, PartialEq, Eq)] 60 pub struct Frame { 61 pub extents: Extents, 62 pub colors: ColorScheme, 63 } 64 65 impl Add<Frame> for Padding { 66 type Output = Self; 67 68 fn add( 69 self, 70 frame: Frame, 71 ) -> Self::Output { 72 Self::Output { 73 left: self.left + frame.extents.left, 74 right: self.right + frame.extents.right, 75 top: self.top + frame.extents.top, 76 bottom: self.bottom + frame.extents.bottom, 77 } 78 } 79 } 80 81 #[derive(Debug, Copy, Clone, PartialEq, Eq)] 82 pub struct Decoration { 83 pub border: Option<Border>, 84 pub frame: Option<Frame>, 85 } 86 87 impl Default for Decoration { 88 fn default() -> Self { 89 Self { 90 border: None, 91 frame: None, 92 } 93 } 94 } 95 96 impl Decoration { 97 pub fn extents(&self) -> Extents { 98 Extents { 99 left: 0, 100 right: 0, 101 top: 0, 102 bottom: 0, 103 } + *self 104 } 105 } 106 107 impl Add<Decoration> for Padding { 108 type Output = Self; 109 110 fn add( 111 mut self, 112 decoration: Decoration, 113 ) -> Self::Output { 114 if let Some(border) = decoration.border { 115 self = self + border; 116 } 117 118 if let Some(frame) = decoration.frame { 119 self = self + frame; 120 } 121 122 self 123 } 124 }