From 40084591ffd0a7a62d34736c5f6f031ee69efb52 Mon Sep 17 00:00:00 2001 From: TheOddGarlic Date: Sat, 23 Apr 2022 11:19:00 +0300 Subject: [PATCH] make Color a tuple struct that's always RGBA --- abletk-common/src/color.rs | 23 +++++------------------ src/main.rs | 2 +- src/widget/label.rs | 2 +- src/window.rs | 2 +- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/abletk-common/src/color.rs b/abletk-common/src/color.rs index e2e8e0b..3028975 100755 --- a/abletk-common/src/color.rs +++ b/abletk-common/src/color.rs @@ -10,29 +10,16 @@ use windows::Win32::Graphics::Direct2D::Common::D2D1_COLOR_F; #[derive(Copy, Clone, Debug)] -pub enum Color { - RGBA(f32, f32, f32, f32), - RGB(f32, f32, f32), -} - -impl Color { - pub fn to_rgba(&self) -> (f32, f32, f32, f32) { - match *self { - Self::RGBA(r, g, b, a) => (r, g, b, a), - Self::RGB(r, g, b) => (r, g, b, 1.0), - } - } -} +pub struct Color(pub f32, pub f32, pub f32, pub f32); #[cfg(windows)] impl From for D2D1_COLOR_F { fn from(color: Color) -> Self { - let rgba = color.to_rgba(); Self { - r: rgba.0, - g: rgba.1, - b: rgba.2, - a: rgba.3, + r: color.0, + g: color.1, + b: color.2, + a: color.3, } } } diff --git a/src/main.rs b/src/main.rs index 837632c..567991b 100755 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,6 @@ fn launch() -> _ { .apply_plugin(QuitPlugin) .add_window(Window::builder( Label::new("Hello, AbleTK!") - .color(Color::RGB(1.0, 0.0, 1.0)) + .color(Color(1.0, 0.0, 1.0, 1.0)) )) } diff --git a/src/widget/label.rs b/src/widget/label.rs index ee8d31c..1b023e5 100755 --- a/src/widget/label.rs +++ b/src/widget/label.rs @@ -29,7 +29,7 @@ impl Label { pub fn new>(text: S) -> Self { Self { text: text.into(), - color: Color::RGB(1.0, 1.0, 1.0), + color: Color(1.0, 1.0, 1.0, 1.0), } } diff --git a/src/window.rs b/src/window.rs index 9af57b9..d885dc1 100755 --- a/src/window.rs +++ b/src/window.rs @@ -209,7 +209,7 @@ impl WindowBuilder { self.events, // todo: make this the application name self.always_on_top, - self.background.unwrap_or(Color::RGB(1.0, 1.0, 1.0)), + self.background.unwrap_or(Color(1.0, 1.0, 1.0, 1.0)), self.decorations, self.maximized, self.resizable,