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
+63 -47
View File
@@ -3,6 +3,7 @@ use lazy_static::lazy_static;
use spin::Mutex;
use alloc::{boxed::Box, string::{String, ToString}, vec, vec::Vec};
use core::future::Future;
use vga::writers::{GraphicsWriter, PrimitiveDrawing};
use crate::{print, printerr, println, serial_println, std, std::application::{Application, Error}, user::bin::*};
@@ -16,7 +17,8 @@ use crate::user::lib::libgui::{
cg_core::{CgComponent},
cg_widgets::{CgTextBox, CgContainer},
};
use crate::user::lib::libgui::cg_widgets::{CgIndicatorBar, CgIndicatorWidget, CgLabel};
use crate::user::lib::libgui::cg_inputs::CgLineEdit;
use crate::user::lib::libgui::cg_widgets::{CgIndicatorBar, CgIndicatorWidget, CgLabel, CgStatusBar};
lazy_static! {
pub static ref CMD: Mutex<CommandHandler> = Mutex::new(CommandHandler::new());
@@ -176,60 +178,24 @@ async fn exec() -> Result<(), Error> {
//interrupts::without_interrupts(|| {});
}
"switch" => {
Screen::switch();
match Screen::get_mode() {
Screen::Terminal => Screen::Application.set_mode().unwrap(),
Screen::Application => Screen::Terminal.set_mode().unwrap(),
};
}
"time" => {
use crate::std::time::timer;
timer();
}
"test_features" => {
std::io::Screen::application_mode();
Screen::Application.set_mode().unwrap();
let textbox = CgTextBox::new(
String::from("i'd just like to interject for a moment"),
String::from("I'd just like to interject for a moment. What you're refering to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called Linux, and many of its users are not aware that it is basically the GNU system, developed by the GNU Project. There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called Linux distributions are really distributions of GNU/Linux!"),
Position::new(2, 5),
Dimensions::new(40, 12),
true,
);
new_eventloop(|c| match c {
'x' => ('x', true),
_ => (c, false),
}).await;
let mut indicatorbar = CgIndicatorBar::new(
Position::new(0, 0),
80
);
let mut w1 = CgIndicatorWidget::new(
String::from("test"),
5
);
let mut w2 = CgIndicatorWidget::new(
String::from("widget 2"),
20
);
w2.set_colour(ColorCode::new(Color::Cyan, Color::Black));
indicatorbar.fields.push(w1);
indicatorbar.fields.push(w2);
let mut container = CgContainer::new(
Position::new(0, 0),
Dimensions::new(80, 25),
false,
);
container.elements.push(Box::new(textbox));
container.elements.push(Box::new(indicatorbar));
if let Ok(frame) = container.render() {
frame.render_to_screen().unwrap();
} else {
return Err(Error::CommandFailed("failed to render frame".to_string()))
};
//std::io::Screen::terminal_mode();
Screen::Terminal.set_mode().unwrap()
}
_ => {
@@ -292,3 +258,53 @@ impl CommandHandler {
struct CmdHistory {
history: Vec<String>,
}
async fn new_eventloop(input: impl Fn(char) -> (char, bool)) {
let textbox = CgTextBox::new(
String::from("i'd just like to interject for a moment"),
String::from("I'd just like to interject for a moment. What you're refering to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called Linux, and many of its users are not aware that it is basically the GNU system, developed by the GNU Project. There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called Linux distributions are really distributions of GNU/Linux!"),
Position::new(2, 5),
Dimensions::new(40, 12),
true,
);
let mut statusbar = CgStatusBar::new(Position::new(0, 0), Dimensions::new(80, 1));
let mut textedit = CgLineEdit::new(
Position::new(0, 1),
80,
String::from("enter text here >"),
);
textedit.text = "hello".chars().collect();
let mut container = CgContainer::new(
Position::new(0, 0),
Dimensions::new(80, 25),
false,
);
container.elements.push(Box::new(&textbox));
container.elements.push(Box::new(&statusbar));
container.elements.push(Box::new(&textedit));
while let (c, false) = input(Stdin::keystroke().await) {
textedit.text.push(c);
let mut container = CgContainer::new(
Position::new(0, 0),
Dimensions::new(80, 25),
false,
);
container.elements.push(Box::new(&textbox));
container.elements.push(Box::new(&statusbar));
container.elements.push(Box::new(&textedit));
if let Ok(frame) = container.render() {
frame.render_to_screen().unwrap();
}
}
}