diff --git a/src/lib.rs b/src/lib.rs index 00f0cd6..fdd8cc9 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ //! Able GUI Toolkit (AbleTK) #[doc(inline)] pub use abletk_macros::*; +pub use abletk_common::color; pub mod application; pub mod context; pub mod event; @@ -17,6 +18,7 @@ pub mod widget; pub mod window; pub mod prelude { pub use crate::application::*; + pub use crate::color::*; pub use crate::event::application::Event as ApplicationEvent; pub use crate::event::window::Event as WindowEvent; pub use crate::platform::Platform; diff --git a/src/main.rs b/src/main.rs index 70c1181..837632c 100755 --- a/src/main.rs +++ b/src/main.rs @@ -13,5 +13,8 @@ use abletk::prelude::*; fn launch() -> _ { Application::new() .apply_plugin(QuitPlugin) - .add_window(Window::builder(Label::new("Hello, AbleTK!"))) + .add_window(Window::builder( + Label::new("Hello, AbleTK!") + .color(Color::RGB(1.0, 0.0, 1.0)) + )) } diff --git a/src/widget/label.rs b/src/widget/label.rs index ba7fdc2..0bf6663 100755 --- a/src/widget/label.rs +++ b/src/widget/label.rs @@ -6,23 +6,31 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use abletk_common::Renderer; +use abletk_common::{Renderer, brush::Brush, color::Color}; use crate::widget::Widget; pub struct Label { - text: String + text: String, + color: Color, } impl Widget for Label { - fn draw(&self, renderer: &Renderer) { - renderer.draw_text(&self.text); + fn draw(&self, renderer: &mut Renderer) { + renderer.set_brush(Brush::Solid(self.color)); + renderer.draw_text(&self.text) } } impl Label { pub fn new>(text: S) -> Self { Self { - text: text.into() + text: text.into(), + color: Color::RGB(1.0, 1.0, 1.0), } } + + pub fn color(mut self, color: Color) -> Self { + self.color = color; + self + } } diff --git a/src/widget/mod.rs b/src/widget/mod.rs index b9c95c7..5f1a3be 100755 --- a/src/widget/mod.rs +++ b/src/widget/mod.rs @@ -12,5 +12,5 @@ use abletk_common::Renderer; pub use label::*; pub trait Widget { - fn draw(&self, renderer: &Renderer); + fn draw(&self, renderer: &mut Renderer); } diff --git a/src/window.rs b/src/window.rs index d15cf0b..c081874 100755 --- a/src/window.rs +++ b/src/window.rs @@ -76,7 +76,7 @@ impl Window { self.renderer.begin_draw(); self.renderer.clear(self.background); - self.root.draw(&self.renderer); + self.root.draw(&mut self.renderer); self.renderer.end_draw() }