bug fix
This commit is contained in:
+19
-8
@@ -5,16 +5,23 @@ use crate::{
|
||||
widget::{Element, Widget},
|
||||
};
|
||||
|
||||
pub struct Div(Vec<Arc<Widget>>);
|
||||
pub struct DivStyle {
|
||||
background_color: u32,
|
||||
}
|
||||
|
||||
pub struct Div {
|
||||
children: Vec<Arc<Widget>>,
|
||||
style: DivStyle,
|
||||
}
|
||||
|
||||
impl Element for Div {
|
||||
fn render(&mut self, scope_parent: &mut crate::render::RenderScope) {
|
||||
let (w, h) = scope_parent.get_size_or_parent();
|
||||
scope_parent.draw_rect(0, 0, w, h, self.style.background_color);
|
||||
let mut scope = RenderScope::new(w, h);
|
||||
|
||||
for elem in &self.0 {
|
||||
for elem in &self.children {
|
||||
scope.clear();
|
||||
|
||||
if let Some(t) = elem.get() {
|
||||
scope.set_transform(&t);
|
||||
}
|
||||
@@ -24,9 +31,8 @@ impl Element for Div {
|
||||
if let Some(t) = elem.get() {
|
||||
scope.set_transform(&t);
|
||||
}
|
||||
scope_parent.merge(scope.clone(), 0, 0);
|
||||
}
|
||||
|
||||
scope_parent.merge(scope, 0, 0);
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
@@ -40,11 +46,16 @@ impl Element for Div {
|
||||
|
||||
impl Div {
|
||||
pub fn new() -> Self {
|
||||
Self(Vec::new())
|
||||
Self {
|
||||
children: Vec::new(),
|
||||
style: DivStyle {
|
||||
background_color: 0xF00000,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw<E: Element + 'static>(&mut self, element: E) -> &Arc<Widget> {
|
||||
self.0.push(Arc::new(Widget::new(Box::new(element))));
|
||||
self.0.last().unwrap()
|
||||
self.children.push(Arc::new(Widget::new(Box::new(element))));
|
||||
self.children.last().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -20,11 +20,12 @@ fn main() {
|
||||
|
||||
let mut d = Div::new();
|
||||
|
||||
d.draw("test".to_string())
|
||||
.component(Transform::new().margin(20, 0));
|
||||
d.draw("abcsdsd".to_string());
|
||||
d.draw("test".to_string()).component(Transform::center());
|
||||
d.draw("abc".to_string())
|
||||
.component(Transform::center().margin(0, 25));
|
||||
|
||||
app.draw(d).component(Transform::center());
|
||||
app.draw(d)
|
||||
.component(Transform::center().dimensions(150, 150));
|
||||
|
||||
app.run().unwrap();
|
||||
}
|
||||
|
||||
+8
-4
@@ -102,9 +102,17 @@ impl RenderScope {
|
||||
)
|
||||
.collect();
|
||||
|
||||
let r_base = ((base_color >> 16) & 0xFF) as f32;
|
||||
let g_base = ((base_color >> 8) & 0xFF) as f32;
|
||||
let b_base = (base_color & 0xFF) as f32;
|
||||
|
||||
for glyph in glyphs {
|
||||
if let Some(bb) = glyph.pixel_bounding_box() {
|
||||
glyph.draw(|gx, gy, v| {
|
||||
if v < 0.5 {
|
||||
return;
|
||||
}
|
||||
|
||||
let x = gx as i32 + bb.min.x + *px as i32;
|
||||
let y = gy as i32 + bb.min.y + *py as i32;
|
||||
|
||||
@@ -113,10 +121,6 @@ impl RenderScope {
|
||||
{
|
||||
let (x, y) = (x as usize, y as usize);
|
||||
|
||||
let r_base = ((base_color >> 16) & 0xFF) as f32;
|
||||
let g_base = ((base_color >> 8) & 0xFF) as f32;
|
||||
let b_base = (base_color & 0xFF) as f32;
|
||||
|
||||
let r = (r_base * v) as u32;
|
||||
let g = (g_base * v) as u32;
|
||||
let b = (b_base * v) as u32;
|
||||
|
||||
Reference in New Issue
Block a user