|
@@ -1,4 +1,11 @@
|
|
|
-use crate::{component::Component, layout::{LayoutNode, LayoutNodeAccess, LeafLayoutNode, SizePolicy}, theme::Theme, ui::UIHandle};
|
|
|
+use kahlo::{colour::Colour, math::PixelBox, prelude::*};
|
|
|
+
|
|
|
+use crate::{
|
|
|
+ component::Component,
|
|
|
+ layout::{LayoutNode, LayoutNodeAccess, LeafLayoutNode, SizePolicy},
|
|
|
+ theme::Theme,
|
|
|
+ ui::UIHandle,
|
|
|
+};
|
|
|
|
|
|
use super::Widget;
|
|
|
|
|
@@ -11,7 +18,12 @@ pub struct Label<C: Component> {
|
|
|
impl<C: Component> Label<C> {
|
|
|
pub fn new(uih: &UIHandle) -> Self {
|
|
|
let mut node = uih.new_layout_node();
|
|
|
- node.set_width_policy(SizePolicy::expands(1)).set_height_policy(SizePolicy { minimum: 20, desired: 20, slack_weight: 0 });
|
|
|
+ node.set_width_policy(SizePolicy::expands(1))
|
|
|
+ .set_height_policy(SizePolicy {
|
|
|
+ minimum: 20,
|
|
|
+ desired: 20,
|
|
|
+ slack_weight: 0,
|
|
|
+ });
|
|
|
Self {
|
|
|
lnode: LeafLayoutNode::new(node),
|
|
|
text: "example text here".to_string(),
|
|
@@ -21,7 +33,11 @@ impl<C: Component> Label<C> {
|
|
|
}
|
|
|
|
|
|
impl<C: Component> Widget<C> for Label<C> {
|
|
|
- fn poll(&mut self, _uih: &mut UIHandle, _input_state: Option<&crate::input::InputState>) -> Vec<<C as Component>::Msg> {
|
|
|
+ fn poll(
|
|
|
+ &mut self,
|
|
|
+ _uih: &mut UIHandle,
|
|
|
+ _input_state: Option<&crate::input::InputState>,
|
|
|
+ ) -> Vec<<C as Component>::Msg> {
|
|
|
vec![]
|
|
|
}
|
|
|
|
|
@@ -32,24 +48,18 @@ impl<C: Component> Widget<C> for Label<C> {
|
|
|
&mut self.lnode
|
|
|
}
|
|
|
|
|
|
- fn render(&self, theme: &Theme, surface: &mut tiny_skia::Pixmap) {
|
|
|
+ fn render(&self, theme: &Theme, surface: &mut kahlo::RgbaBitmap) {
|
|
|
let line = theme.make_line(self.text.as_str());
|
|
|
let rendered = line.render_line();
|
|
|
|
|
|
- let render_location = self.layout_node().cached_rect().unwrap().to_rect();
|
|
|
-
|
|
|
- surface.fill_rect(render_location, &tiny_skia::Paint {
|
|
|
- shader: tiny_skia::Pattern::new(
|
|
|
- rendered.as_ref(), tiny_skia::SpreadMode::Pad, tiny_skia::FilterQuality::Nearest, 1.0, tiny_skia::Transform::identity()
|
|
|
- ),
|
|
|
- blend_mode: tiny_skia::BlendMode::SourceOver,
|
|
|
- ..Default::default()
|
|
|
- }, tiny_skia::Transform::identity(), None);
|
|
|
- /*painter.fill(
|
|
|
- self.layout_node().cached_rect().unwrap(),
|
|
|
- Colour::new_rgb(64, 64, 64),
|
|
|
+ let render_location = self.layout_node().cached_rect().unwrap();
|
|
|
+
|
|
|
+ surface.fill_masked(
|
|
|
+ &rendered,
|
|
|
+ &PixelBox::from_size(rendered.size()),
|
|
|
+ &render_location.origin,
|
|
|
+ theme.foreground,
|
|
|
+ kahlo::colour::BlendMode::SourceAlpha,
|
|
|
);
|
|
|
- let text_surf = ti.render_text(&self.buffer, 0.0);
|
|
|
- painter.blit(&text_surf, IRect::new_from_size(IPoint::ORIGIN, text_surf.size()), self.layout_node().cached_rect().unwrap().tl());*/
|
|
|
}
|
|
|
}
|