- got text boxes fully working

- this includes text wrapping not cutting words in half (can be disabled using a method on the text box)
- refactored frame.rs, cg_core.rs and cg_widgets.rs to avoid code reuse and duplication
- created a simplified unified interface for rendering frames to the screen using the Frame struct provided by frame.rs instead of Element, FrameGen, etc.
- moved all widgets from cg_core.rs to cg_widgets.rs
- the label widget now works
- also added CgIndicatorBar and CgIndicatorWidget widgets to eventually make a working status bar
- refactored all applications in the system to use the new api to render to the screen
This commit is contained in:
FantasyPvP
2023-11-23 00:29:04 +00:00
parent 0ac21cd0b1
commit 461c9d9c6a
11 changed files with 488 additions and 501 deletions
+15 -13
View File
@@ -6,6 +6,7 @@ use volatile::Volatile;
use alloc::borrow::ToOwned;
use alloc::vec;
use alloc::vec::Vec;
use crate::kernel::render::RenderError::InvalidRenderMode;
use crate::serial_println;
use crate::std::io::Screen;
@@ -48,6 +49,14 @@ pub struct ScreenChar {
pub colour: ColorCode,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RenderError {
OutOfBounds(bool, bool), // (bool, bool) refers to x and y respectively
InvalidCharacter,
InvalidColour,
InvalidRenderMode,
}
impl ScreenChar {
pub fn null() -> ScreenChar {
ScreenChar {
@@ -108,7 +117,6 @@ impl Renderer {
pub fn render_frame(&mut self, frame: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT]) { // renders the given frame to the app buffer
let mut processed_frame: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT] = [[ScreenChar::null(); BUFFER_WIDTH]; BUFFER_HEIGHT];
for (i, row) in frame.iter().enumerate() {
for (j, col) in row.iter().enumerate() {
processed_frame[i][j] = match special_char(col.character as char) {
@@ -128,9 +136,9 @@ impl Renderer {
self.internal_render();
}
pub fn application_mode(&mut self) -> Result<(), ()> {
pub fn application_mode(&mut self) -> Result<(), RenderError> {
if self.application_mode {
return Err(());
return Err(InvalidRenderMode);
} else {
self.application_mode = true;
self.internal_render();
@@ -138,9 +146,9 @@ impl Renderer {
}
}
pub fn terminal_mode(&mut self) -> Result<(), ()> {
pub fn terminal_mode(&mut self) -> Result<(), RenderError> {
if !self.application_mode {
return Err(());
return Err(InvalidRenderMode);
} else {
self.application_mode = false;
self.internal_render();
@@ -172,7 +180,7 @@ impl Renderer {
self.internal_render();
}
pub fn backspace(&mut self) -> Result<(), ()> {
pub fn backspace(&mut self) -> Result<(), RenderError> {
if self.application_mode { return Ok(()); };
loop {
@@ -218,7 +226,7 @@ impl Renderer {
}
}
fn internal_backspace(&mut self) -> Result<bool, ()> {
fn internal_backspace(&mut self) -> Result<bool, RenderError> {
let mut should_break = false;
if self.col_pos == 0 {
@@ -327,12 +335,6 @@ pub fn special_char(ch: char) -> Option<u8> {
}
impl fmt::Write for Renderer {
fn write_str(&mut self, string: &str) -> fmt::Result {
self.write_string(string, None);