use fill paint

This commit is contained in:
Daniel Bulant 2023-10-23 16:05:37 +02:00
parent 19df12a8c8
commit 76d1ce07f4
2 changed files with 19 additions and 53 deletions

View file

@ -4,7 +4,7 @@ use std::ops::Deref;
use std::sync::{Arc, RwLock, Weak};
use femtovg::renderer::OpenGl;
use femtovg::{Canvas, Color};
use femtovg::{Canvas, Color, Paint};
use glutin::surface::Surface;
use glutin::{context::PossiblyCurrentContext, display::Display};
use glutin_winit::DisplayBuilder;
@ -65,7 +65,7 @@ fn main() {
..Default::default()
}
},
color: Color::rgb(255, 0, 0),
fill: Paint::color(Color::rgb(255, 0, 0)),
radius: 10.
})));
root.children.push(Arc::new(RwLock::new(Layout {
@ -95,7 +95,7 @@ fn main() {
..Default::default()
}
},
color: Color::rgb(0, 255, 0),
fill: Paint::color(Color::rgb(0, 255, 0)),
radius: 5.
})),
Arc::new(RwLock::new(nodes::primitives::Rectangle {
@ -109,7 +109,7 @@ fn main() {
..Default::default()
}
},
color: Color::rgb(0, 255, 255),
fill: Paint::color(Color::rgb(0, 255, 255)),
radius: 5.
}))
]
@ -126,7 +126,7 @@ fn main() {
..Default::default()
}
},
color: Color::rgb(0, 0, 255),
fill: Paint::color(Color::rgb(0, 0, 255)),
radius: 0.
})));
let groot: Arc<RwLock<Layout<CurrentRenderer>>> = Arc::new(RwLock::new(root));

View file

@ -5,7 +5,7 @@ use crate::nodes::{Node, NodeChildren, RenderContext, Style};
#[derive(Clone, Default, Debug)]
pub struct Rectangle {
pub style: Style,
pub color: Color,
pub fill: Paint,
pub radius: f32
}
@ -13,7 +13,7 @@ impl Rectangle {
pub(crate) fn new() -> Rectangle {
Rectangle {
style: Style::default(),
color: Color::rgb(0, 0, 0),
fill: Paint::color(Color::rgb(0, 0, 0)),
radius: 0.
}
}
@ -27,51 +27,17 @@ impl<T: Renderer> Node<T> for Rectangle {
None
}
fn render_pre_children(&self, context: &mut RenderContext<T>, layout: Layout) {
if self.radius > 0. {
let mut path = Path::new();
path.rounded_rect(
0.,
0.,
layout.size.width,
layout.size.height,
self.radius
);
context.canvas.fill_path(
&path,
&Paint::color(self.color)
);
} else {
context.fill_rect(
0,
0,
layout.size.width as u32,
layout.size.height as u32,
self.color
);
}
let mut path = Path::new();
path.rounded_rect(
0.,
0.,
layout.size.width,
layout.size.height,
self.radius
);
context.canvas.fill_path(
&path,
&self.fill
);
}
// fn render(&self, context: &mut RenderContext<T>, layout: Layout, _render_children: &dyn Fn(&mut RenderContext<T>)) {
// if self.radius > 0. {
// let mut path = Path::new();
// path.rounded_rect(
// 0.,
// 0.,
// layout.size.width,
// layout.size.height,
// self.radius
// );
// context.canvas.fill_path(
// &path,
// &Paint::color(self.color)
// );
// } else {
// context.canvas.clear_rect(
// 0,
// 0,
// layout.size.width as u32,
// layout.size.height as u32,
// self.color
// );
// }
// }
}