make Color a tuple struct that's always RGBA
This commit is contained in:
parent
889aef5cdc
commit
40084591ff
|
@ -10,29 +10,16 @@
|
||||||
use windows::Win32::Graphics::Direct2D::Common::D2D1_COLOR_F;
|
use windows::Win32::Graphics::Direct2D::Common::D2D1_COLOR_F;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum Color {
|
pub struct Color(pub f32, pub f32, pub f32, pub f32);
|
||||||
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),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
impl From<Color> for D2D1_COLOR_F {
|
impl From<Color> for D2D1_COLOR_F {
|
||||||
fn from(color: Color) -> Self {
|
fn from(color: Color) -> Self {
|
||||||
let rgba = color.to_rgba();
|
|
||||||
Self {
|
Self {
|
||||||
r: rgba.0,
|
r: color.0,
|
||||||
g: rgba.1,
|
g: color.1,
|
||||||
b: rgba.2,
|
b: color.2,
|
||||||
a: rgba.3,
|
a: color.3,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,6 @@ fn launch() -> _ {
|
||||||
.apply_plugin(QuitPlugin)
|
.apply_plugin(QuitPlugin)
|
||||||
.add_window(Window::builder(
|
.add_window(Window::builder(
|
||||||
Label::new("Hello, AbleTK!")
|
Label::new("Hello, AbleTK!")
|
||||||
.color(Color::RGB(1.0, 0.0, 1.0))
|
.color(Color(1.0, 0.0, 1.0, 1.0))
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl Label {
|
||||||
pub fn new<S: Into<String>>(text: S) -> Self {
|
pub fn new<S: Into<String>>(text: S) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
color: Color::RGB(1.0, 1.0, 1.0),
|
color: Color(1.0, 1.0, 1.0, 1.0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,7 +209,7 @@ impl WindowBuilder {
|
||||||
self.events,
|
self.events,
|
||||||
// todo: make this the application name
|
// todo: make this the application name
|
||||||
self.always_on_top,
|
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.decorations,
|
||||||
self.maximized,
|
self.maximized,
|
||||||
self.resizable,
|
self.resizable,
|
||||||
|
|
Loading…
Reference in a new issue