diff --git a/src/elements/div.rs b/src/elements/div.rs index 5960d18..0779a92 100644 --- a/src/elements/div.rs +++ b/src/elements/div.rs @@ -1,4 +1,4 @@ -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use crate::{ widget::{Element, Widget}, @@ -6,14 +6,14 @@ use crate::{ }; pub struct Div { - children: Mutex>>, + children: Vec>, size: (u16, u16), } impl Div { pub fn new() -> Self { Div { - children: Mutex::new(Vec::new()), + children: Vec::new(), size: (0, 0), } } @@ -30,7 +30,7 @@ impl Element for Div { let (w, h) = scope.get_parent_size(); scope.set_parent_size(transform.width, transform.height); - for elem in self.children.lock().unwrap().iter() { + for elem in &self.children { scope.clear(); if let Some(style) = elem.get() { scope.set_style(style); @@ -55,8 +55,8 @@ impl Element for Div { self.size = (transform.width, transform.height); } - fn draw_child(&self, element: &Arc) { - self.children.lock().unwrap().push(element.clone()); + fn draw_child(&mut self, element: &Arc) { + self.children.push(element.clone()); element.inject(|w| w.component(NoRender)); } diff --git a/src/elements/flex.rs b/src/elements/flex.rs index 71849a1..a34bc9d 100644 --- a/src/elements/flex.rs +++ b/src/elements/flex.rs @@ -1,4 +1,4 @@ -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use crate::{ widget::{Element, Widget}, @@ -7,20 +7,20 @@ use crate::{ pub struct FlexRow { pub gap: u16, - children: Mutex>>, + children: Vec>, size: (u16, u16), } pub struct FlexCol { pub gap: u16, - children: Mutex>>, + children: Vec>, size: (u16, u16), } impl FlexRow { pub fn new() -> Self { Self { - children: Mutex::new(Vec::new()), + children: Vec::new(), size: (0, 0), gap: 0, } @@ -30,7 +30,7 @@ impl FlexRow { impl FlexCol { pub fn new() -> Self { Self { - children: Mutex::new(Vec::new()), + children: Vec::new(), size: (0, 0), gap: 0, } @@ -50,7 +50,7 @@ impl Element for FlexRow { let mut v = 0; - for elem in self.children.lock().unwrap().iter() { + for elem in &self.children { scope.clear(); if let Some(style) = elem.get() { scope.set_style(style); @@ -79,8 +79,8 @@ impl Element for FlexRow { self.size = (transform.width, transform.height); } - fn draw_child(&self, element: &Arc) { - self.children.lock().unwrap().push(element.clone()); + fn draw_child(&mut self, element: &Arc) { + self.children.push(element.clone()); element.inject(|w| w.component(NoRender)); } @@ -106,7 +106,7 @@ impl Element for FlexCol { let mut v = 0; - for elem in self.children.lock().unwrap().iter() { + for elem in &self.children { scope.clear(); if let Some(style) = elem.get() { scope.set_style(style); @@ -135,8 +135,8 @@ impl Element for FlexCol { self.size = (transform.width, transform.height); } - fn draw_child(&self, element: &Arc) { - self.children.lock().unwrap().push(element.clone()); + fn draw_child(&mut self, element: &Arc) { + self.children.push(element.clone()); element.inject(|w| w.component(NoRender)); } diff --git a/src/elements/heading.rs b/src/elements/heading.rs index 2e83801..5a0166e 100644 --- a/src/elements/heading.rs +++ b/src/elements/heading.rs @@ -1,4 +1,4 @@ -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use figlet_rs::FIGfont; @@ -10,7 +10,7 @@ use crate::{ pub struct Heading { pub font: FIGfont, pub smooth: bool, - children: Mutex>>, + children: Vec>, } impl Heading { @@ -18,7 +18,7 @@ impl Heading { Heading { font: FIGfont::standard().unwrap(), smooth: false, - children: Mutex::new(Vec::new()), + children: Vec::new(), } } } @@ -26,7 +26,7 @@ impl Heading { impl Element for Heading { fn render(&mut self, scope: &mut crate::prelude::RenderScope) { let mut s = String::new(); - for element in self.children.lock().unwrap().iter() { + for element in &self.children { if let Some(e) = element.get_elem().as_any().downcast_ref::() { s += e; } @@ -44,9 +44,9 @@ impl Element for Heading { } } - fn draw_child(&self, element: &Arc) { + fn draw_child(&mut self, element: &Arc) { element.inject(|w| w.component(NoRender)); - self.children.lock().unwrap().push(element.clone()); + self.children.push(element.clone()); } fn as_any(&self) -> &dyn std::any::Any { diff --git a/src/widget.rs b/src/widget.rs index f8f3fa1..4d4cd20 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -39,7 +39,7 @@ pub trait Element: Send + Sync { /// Called to draw child widgets, if any. #[allow(unused)] - fn draw_child(&self, element: &Arc) {} + fn draw_child(&mut self, element: &Arc) {} #[allow(unused)] fn event(&mut self, event: &dyn Event) {}