diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-12 00:18:39 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-12 00:18:39 -0700 |
| commit | 6480f84e8ee9839fb486916d708712daf34a0aff (patch) | |
| tree | b53dd2b3eeecad2d52d926f8b2977051551e5bcb /src/x | |
| parent | cea4c230b40d5ea2851ed3f97f73b2554849dc34 (diff) | |
rounded corners
fun that was some nontrivial type magick Force-Push: yes Change-Id: I9b2848cc76f3dfab5b87d7e6b2f28bf2a136fca5
Diffstat (limited to 'src/x')
| -rw-r--r-- | src/x/geometry.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/x/geometry.rs b/src/x/geometry.rs new file mode 100644 index 0000000..fcbb15a --- /dev/null +++ b/src/x/geometry.rs @@ -0,0 +1,66 @@ +use crate::geometry::*; + +use std::fmt::Debug; + + +pub const X_CLOCKWISE_RIGHT_ANGLE: i16 = -90 * 64; + + +pub trait SideExt { + fn to_x_angle(&self) -> i16; +} + +impl SideExt for Side { + fn to_x_angle(&self) -> i16 { + match self { + Side::Top => 90 * 64, + Side::Right => 0, + Side::Bottom => 270 * 64, + Side::Left => 180 * 64, + } + } +} + + +pub trait RectangleExt<T: Coordinate> { + fn to_x_rectangle(&self) -> xcb::x::Rectangle + where T: TryInto<i16> + TryInto<u16> + Debug, + <T as TryInto<i16>>::Error: Debug, + <T as TryInto<u16>>::Error: Debug; + fn to_x_arc(&self, angle1: i16, angle2: i16) -> xcb::x::Arc + where T: TryInto<i16> + TryInto<u16> + Debug, + <T as TryInto<i16>>::Error: Debug, + <T as TryInto<u16>>::Error: Debug; +} + + +impl<T: Coordinate> RectangleExt<T> for Rectangle<T> { + fn to_x_rectangle(&self) -> xcb::x::Rectangle + where T: TryInto<i16> + TryInto<u16> + Debug, + <T as TryInto<i16>>::Error: Debug, + <T as TryInto<u16>>::Error: Debug + { + xcb::x::Rectangle { + x: self.left.try_into().unwrap(), + y: self.top.try_into().unwrap(), + width: self.width.try_into().unwrap(), + height: self.height.try_into().unwrap() + } + } + + fn to_x_arc(&self, angle1: i16, angle2: i16) -> xcb::x::Arc + where T: TryInto<i16> + TryInto<u16> + Debug, + <T as TryInto<i16>>::Error: Debug, + <T as TryInto<u16>>::Error: Debug + { + xcb::x::Arc { + x: self.left.try_into().unwrap(), + y: self.top.try_into().unwrap(), + width: self.width.try_into().unwrap(), + height: self.height.try_into().unwrap(), + angle1: angle1.try_into().unwrap(), + angle2: angle2.try_into().unwrap(), + } + } +} + |