label widgets with color

This commit is contained in:
TheOddGarlic 2022-04-21 17:59:16 +03:00
parent 37b2e3caa8
commit 86cdd411a4
5 changed files with 21 additions and 8 deletions

View file

@ -8,6 +8,7 @@
//! Able GUI Toolkit (AbleTK) //! Able GUI Toolkit (AbleTK)
#[doc(inline)] pub use abletk_macros::*; #[doc(inline)] pub use abletk_macros::*;
pub use abletk_common::color;
pub mod application; pub mod application;
pub mod context; pub mod context;
pub mod event; pub mod event;
@ -17,6 +18,7 @@ pub mod widget;
pub mod window; pub mod window;
pub mod prelude { pub mod prelude {
pub use crate::application::*; pub use crate::application::*;
pub use crate::color::*;
pub use crate::event::application::Event as ApplicationEvent; pub use crate::event::application::Event as ApplicationEvent;
pub use crate::event::window::Event as WindowEvent; pub use crate::event::window::Event as WindowEvent;
pub use crate::platform::Platform; pub use crate::platform::Platform;

View file

@ -13,5 +13,8 @@ use abletk::prelude::*;
fn launch() -> _ { fn launch() -> _ {
Application::new() Application::new()
.apply_plugin(QuitPlugin) .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))
))
} }

View file

@ -6,23 +6,31 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. * 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; use crate::widget::Widget;
pub struct Label { pub struct Label {
text: String text: String,
color: Color,
} }
impl Widget for Label { impl Widget for Label {
fn draw(&self, renderer: &Renderer) { fn draw(&self, renderer: &mut Renderer) {
renderer.draw_text(&self.text); renderer.set_brush(Brush::Solid(self.color));
renderer.draw_text(&self.text)
} }
} }
impl Label { 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),
} }
} }
pub fn color(mut self, color: Color) -> Self {
self.color = color;
self
}
} }

View file

@ -12,5 +12,5 @@ use abletk_common::Renderer;
pub use label::*; pub use label::*;
pub trait Widget { pub trait Widget {
fn draw(&self, renderer: &Renderer); fn draw(&self, renderer: &mut Renderer);
} }

View file

@ -76,7 +76,7 @@ impl Window {
self.renderer.begin_draw(); self.renderer.begin_draw();
self.renderer.clear(self.background); self.renderer.clear(self.background);
self.root.draw(&self.renderer); self.root.draw(&mut self.renderer);
self.renderer.end_draw() self.renderer.end_draw()
} }