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;
|
||||
|
||||
#[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<Color> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
))
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ impl Label {
|
|||
pub fn new<S: Into<String>>(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),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue