mirror of
https://github.com/danbulant/mangui
synced 2026-07-06 19:30:34 +00:00
use fill paint
This commit is contained in:
parent
19df12a8c8
commit
76d1ce07f4
2 changed files with 19 additions and 53 deletions
10
src/main.rs
10
src/main.rs
|
|
@ -4,7 +4,7 @@ use std::ops::Deref;
|
||||||
use std::sync::{Arc, RwLock, Weak};
|
use std::sync::{Arc, RwLock, Weak};
|
||||||
|
|
||||||
use femtovg::renderer::OpenGl;
|
use femtovg::renderer::OpenGl;
|
||||||
use femtovg::{Canvas, Color};
|
use femtovg::{Canvas, Color, Paint};
|
||||||
use glutin::surface::Surface;
|
use glutin::surface::Surface;
|
||||||
use glutin::{context::PossiblyCurrentContext, display::Display};
|
use glutin::{context::PossiblyCurrentContext, display::Display};
|
||||||
use glutin_winit::DisplayBuilder;
|
use glutin_winit::DisplayBuilder;
|
||||||
|
|
@ -65,7 +65,7 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
color: Color::rgb(255, 0, 0),
|
fill: Paint::color(Color::rgb(255, 0, 0)),
|
||||||
radius: 10.
|
radius: 10.
|
||||||
})));
|
})));
|
||||||
root.children.push(Arc::new(RwLock::new(Layout {
|
root.children.push(Arc::new(RwLock::new(Layout {
|
||||||
|
|
@ -95,7 +95,7 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
color: Color::rgb(0, 255, 0),
|
fill: Paint::color(Color::rgb(0, 255, 0)),
|
||||||
radius: 5.
|
radius: 5.
|
||||||
})),
|
})),
|
||||||
Arc::new(RwLock::new(nodes::primitives::Rectangle {
|
Arc::new(RwLock::new(nodes::primitives::Rectangle {
|
||||||
|
|
@ -109,7 +109,7 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
color: Color::rgb(0, 255, 255),
|
fill: Paint::color(Color::rgb(0, 255, 255)),
|
||||||
radius: 5.
|
radius: 5.
|
||||||
}))
|
}))
|
||||||
]
|
]
|
||||||
|
|
@ -126,7 +126,7 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
color: Color::rgb(0, 0, 255),
|
fill: Paint::color(Color::rgb(0, 0, 255)),
|
||||||
radius: 0.
|
radius: 0.
|
||||||
})));
|
})));
|
||||||
let groot: Arc<RwLock<Layout<CurrentRenderer>>> = Arc::new(RwLock::new(root));
|
let groot: Arc<RwLock<Layout<CurrentRenderer>>> = Arc::new(RwLock::new(root));
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use crate::nodes::{Node, NodeChildren, RenderContext, Style};
|
||||||
#[derive(Clone, Default, Debug)]
|
#[derive(Clone, Default, Debug)]
|
||||||
pub struct Rectangle {
|
pub struct Rectangle {
|
||||||
pub style: Style,
|
pub style: Style,
|
||||||
pub color: Color,
|
pub fill: Paint,
|
||||||
pub radius: f32
|
pub radius: f32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ impl Rectangle {
|
||||||
pub(crate) fn new() -> Rectangle {
|
pub(crate) fn new() -> Rectangle {
|
||||||
Rectangle {
|
Rectangle {
|
||||||
style: Style::default(),
|
style: Style::default(),
|
||||||
color: Color::rgb(0, 0, 0),
|
fill: Paint::color(Color::rgb(0, 0, 0)),
|
||||||
radius: 0.
|
radius: 0.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,51 +27,17 @@ impl<T: Renderer> Node<T> for Rectangle {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn render_pre_children(&self, context: &mut RenderContext<T>, layout: Layout) {
|
fn render_pre_children(&self, context: &mut RenderContext<T>, layout: Layout) {
|
||||||
if self.radius > 0. {
|
let mut path = Path::new();
|
||||||
let mut path = Path::new();
|
path.rounded_rect(
|
||||||
path.rounded_rect(
|
0.,
|
||||||
0.,
|
0.,
|
||||||
0.,
|
layout.size.width,
|
||||||
layout.size.width,
|
layout.size.height,
|
||||||
layout.size.height,
|
self.radius
|
||||||
self.radius
|
);
|
||||||
);
|
context.canvas.fill_path(
|
||||||
context.canvas.fill_path(
|
&path,
|
||||||
&path,
|
&self.fill
|
||||||
&Paint::color(self.color)
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
context.fill_rect(
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
layout.size.width as u32,
|
|
||||||
layout.size.height as u32,
|
|
||||||
self.color
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 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
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue