remove RcFrontend & RcLayout

[skip ci]
This commit is contained in:
Aleksander
2025-12-26 12:43:14 +01:00
parent f29de34de2
commit 4f7204ccf7
19 changed files with 145 additions and 128 deletions

View File

@@ -163,8 +163,6 @@ pub struct Layout {
pub animations: Animations,
}
pub type RcLayout = Rc<RefCell<Layout>>;
#[derive(Default)]
pub struct LayoutParams {
pub resize_to_parent: bool,
@@ -226,10 +224,6 @@ impl Layout {
}
}
pub fn as_rc(self) -> RcLayout {
Rc::new(RefCell::new(self))
}
pub fn add_topmost_child(
&mut self,
widget: WidgetState,

View File

@@ -35,6 +35,7 @@ pub mod layout;
pub mod parser;
pub mod renderer_vk;
pub mod stack;
pub mod task;
pub mod widget;
pub mod windowing;

50
wgui/src/task.rs Normal file
View File

@@ -0,0 +1,50 @@
use crate::components::button::ComponentButton;
use std::{cell::RefCell, collections::VecDeque, rc::Rc};
pub struct Tasks<TaskType>(Rc<RefCell<VecDeque<TaskType>>>);
impl<T> Clone for Tasks<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<TaskType: 'static> Tasks<TaskType> {
pub fn new() -> Self {
Self(Rc::new(RefCell::new(VecDeque::new())))
}
pub fn push(&self, task: TaskType) {
self.0.borrow_mut().push_back(task);
}
pub fn drain(&mut self) -> VecDeque<TaskType> {
let mut tasks = self.0.borrow_mut();
std::mem::take(&mut *tasks)
}
}
impl<TaskType: 'static> Default for Tasks<TaskType> {
fn default() -> Self {
Self::new()
}
}
impl<TaskType: Clone + 'static> Tasks<TaskType> {
pub fn handle_button(&self, button: &Rc<ComponentButton>, task: TaskType) {
button.on_click({
let this = self.clone();
Box::new(move |_, _| {
this.push(task.clone());
Ok(())
})
});
}
pub fn make_callback(&self, task: TaskType) -> Rc<dyn Fn()> {
let this = self.clone();
Rc::new(move || {
this.push(task.clone());
})
}
}