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:
FantasyPvP
2023-11-28 00:12:59 +00:00
parent f48eb133b3
commit c194109487
5 changed files with 138 additions and 68 deletions
+56 -1
View File
@@ -1,8 +1,13 @@
use alloc::string::String;
use alloc::vec::Vec;
use alloc::boxed::Box;
use core::any::Any;
use core::task::ready;
use async_trait::async_trait;
use crate::std::application::Exit;
use crate::std::frame::{ColouredChar, Dimensions, Frame, Position, RenderError};
use crate::user::lib::libgui::cg_core::{CgComponent, CgTextEdit};
use crate::std::io::{KeyStroke, Stdin};
use crate::user::lib::libgui::cg_core::{CgComponent, CgTextEdit, CgTextInput, Widget};
#[derive(Debug, Clone)]
pub struct CgLineEdit {
@@ -84,3 +89,53 @@ impl CgTextEdit for CgLineEdit {
self.ptr = 0
}
}
#[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),
_ => (),
}
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))
}
}