label widgets with color
This commit is contained in:
parent
37b2e3caa8
commit
86cdd411a4
|
@ -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;
|
||||
|
|
|
@ -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))
|
||||
))
|
||||
}
|
||||
|
|
|
@ -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<S: Into<String>>(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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue