continued to work on new UI library

- implemented CgStatusBar widget which is a specific version of the CgIndicatorBar widget with predefined fields

- std::io::Screen is now an enum that makes switching between display modes more intuitive

- created a basic CgLineEdit implementation that allows for a user to type in a character and have it re-render that widget

- other more minor changes like fixes for existing apps to work with new features
This commit is contained in:
FantasyPvP
2023-11-23 20:29:51 +00:00
parent 461c9d9c6a
commit 467a42a5fa
14 changed files with 352 additions and 128 deletions
+53
View File
@@ -0,0 +1,53 @@
use alloc::string::String;
use alloc::vec::Vec;
use crate::std::frame::{ColouredChar, Dimensions, Frame, Position, RenderError};
use crate::user::lib::libgui::cg_core::{CgComponent, CgTextEdit};
pub struct CgLineEdit {
pub position: Position,
pub dimensions: Dimensions,
pub prompt: String,
pub text: Vec<char>,
pub ptr: usize, // cursor position
}
impl CgLineEdit {
pub fn new(position: Position, width: usize, prompt: String) -> CgLineEdit {
CgLineEdit {
position,
dimensions: Dimensions::new(width, 1),
prompt: prompt,
text: Vec::new(),
ptr: 0
}
}
}
impl CgComponent for CgLineEdit {
fn render(&self) -> Result<Frame, RenderError> {
let mut frame = Frame::new(self.position, self.dimensions)?;
let mut ptr = 0;
for c in self.prompt.chars() {
if ptr >= self.dimensions.x {
break;
}
frame.write(Position::new(ptr, 0), ColouredChar::new(c));
ptr += 1
}
ptr += 1; // create a space between the prompt and the text
for c in self.text.iter() {
if ptr >= self.dimensions.x {
break;
}
frame.write(Position::new(ptr, 0), ColouredChar::new(*c));
ptr += 1
}
Ok(frame)
}
}