several fixes and changes

This commit is contained in:
FantasyPvP
2023-11-29 23:45:40 +00:00
parent d89a30d390
commit 7ae2308a83
10 changed files with 215 additions and 68 deletions
+4 -3
View File
@@ -96,7 +96,8 @@ impl Widget {
impl Drop for Widget {
fn drop(&mut self) {
GUITREE.lock().remove(self);
let removed = GUITREE.lock().remove(self);
drop(removed);
}
}
@@ -136,9 +137,9 @@ impl DataStore {
items.get(&id.id).cloned()
}
fn remove(&self, id: &Widget) {
fn remove(&self, id: &Widget) -> Option<Arc<Mutex<dyn CgComponent + Send + Sync>>> {
let mut items = self.items.lock();
items.remove(&id.id);
items.remove(&id.id)
}
}
+52 -24
View File
@@ -93,31 +93,61 @@ impl CgTextEdit for CgLineEdit {
#[async_trait]
impl CgTextInput for CgLineEdit {
async fn input(&mut self, break_condition: fn(KeyStroke) -> (KeyStroke, Exit), id: &Widget, app: &Widget) -> Result<(String, bool), RenderError> {
while let (c, Exit::None) = break_condition(Stdin::keystroke().await) {
match c {
KeyStroke::Char('\n') => break,
KeyStroke::Char('\x08') => self.backspace(),
KeyStroke::Backspace => self.backspace(),
KeyStroke::Char(c) => self.write_char(c),
KeyStroke::Left => self.move_cursor(false),
KeyStroke::Right => self.move_cursor(true),
loop {
match break_condition(Stdin::keystroke().await) {
(KeyStroke::Char('\n'), Exit::None) => {
let res = self.text.iter().collect();
self.clear();
id.update(self.clone());
match app.render() {
Ok(frame) => frame.write_to_screen()?,
Err(e) => return Err(e),
}
return Ok((res, false))
},
(c, Exit::None) => {
match c {
KeyStroke::Char('\x08') => self.backspace(),
KeyStroke::Backspace => self.backspace(),
KeyStroke::Char(c) => self.write_char(c),
KeyStroke::Left => self.move_cursor(false),
KeyStroke::Right => self.move_cursor(true),
_ => (),
}
id.update(self.clone());
match app.render() {
Ok(frame) => frame.write_to_screen()?,
Err(e) => return Err(e),
}
},
(_, Exit::Exit) => {
return Ok((String::new(), true))
},
_ => (),
}
id.update(self.clone());
match app.render() {
Ok(frame) => frame.write_to_screen()?,
Err(e) => return Err(e),
}
};
let res = self.text.iter().collect();
self.clear();
id.update(self.clone());
match app.render() {
Ok(frame) => frame.write_to_screen()?,
Err(e) => return Err(e),
}
Ok((res, false))
}
}
#[derive(Debug, Clone)]
pub struct CgBoxEdit {
pub position: Position,
pub dimensions: Dimensions,
pub prompt: String,
pub text: Vec<char>,
pub ptr: Position,
}
impl CgBoxEdit {
pub fn new(position: Position, dimensions: Dimensions, prompt: String) -> CgBoxEdit {
CgBoxEdit {
position,
dimensions,
prompt,
text: Vec::new(),
ptr: Position::new(0, 0)
}
}
}
@@ -137,5 +167,3 @@ impl CgTextInput for CgLineEdit {
-5
View File
@@ -58,12 +58,7 @@ impl CgOutline for CgContainer {
impl CgComponent for CgContainer {
fn render(&self) -> Result<Frame, RenderError> {
serial_println!("rendering");
let mut result = Frame::new(self.position, self.dimensions)?;
serial_println!("{:?}", self.elements);
for widget in &self.elements {
let frame = widget.1.render()?;
match result.render_bounds_check(&frame, true) { // TODO: this needs to be set to false for production