holy (crab) that was a lot of work
it works. the input function is working now, passing it a reference to your root gui widget and a reference to it's own widget and a function to check if it should exit works now gg
This commit is contained in:
@@ -11,7 +11,10 @@ use alloc::{
|
||||
string::String,
|
||||
};
|
||||
use core::any::Any;
|
||||
use async_trait::async_trait;
|
||||
use lazy_static::lazy_static;
|
||||
use crate::std::application::Exit;
|
||||
use crate::std::io::KeyStroke;
|
||||
|
||||
/// implement this trait if you require the widget to be able to have an outline
|
||||
pub trait CgOutline: CgComponent {
|
||||
@@ -35,6 +38,11 @@ pub trait CgTextEdit: CgComponent {
|
||||
fn clear(&mut self);
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait CgTextInput: CgTextEdit {
|
||||
async fn input(&mut self, break_condition: fn(KeyStroke) -> (KeyStroke, Exit), id: &Widget, app: &Widget) -> Result<(String, bool), RenderError>;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ID_COUNTER: Mutex<usize> = Mutex::new(0);
|
||||
@@ -76,11 +84,13 @@ impl Widget {
|
||||
}
|
||||
|
||||
pub fn render(&self) -> Result<Frame, RenderError> {
|
||||
if let Some(frame) = GUITREE.lock().frame(self) {
|
||||
frame
|
||||
} else {
|
||||
panic!("CRITICAL: Widget not found in tree");
|
||||
}
|
||||
let component_arc_mutex = match GUITREE.lock().frame(self) {
|
||||
Some(component) => component,
|
||||
None => panic!("CRITICAL: Widget not found in tree"),
|
||||
};
|
||||
|
||||
let component = component_arc_mutex.lock();
|
||||
component.render()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,12 +131,9 @@ impl DataStore {
|
||||
})
|
||||
}
|
||||
|
||||
fn frame(&self, id: &Widget) -> Option<Result<Frame, RenderError>> {
|
||||
fn frame(&self, id: &Widget) -> Option<Arc<Mutex<dyn CgComponent + Send + Sync + 'static>>> {
|
||||
let items = self.items.lock();
|
||||
items.get(&id.id).and_then(|arc| {
|
||||
let item = arc.lock();
|
||||
Some(item.render())
|
||||
})
|
||||
items.get(&id.id).cloned()
|
||||
}
|
||||
|
||||
fn remove(&self, id: &Widget) {
|
||||
|
||||
Reference in New Issue
Block a user