started working on dialogs

This commit is contained in:
FantasyPvP
2024-03-20 18:03:15 +00:00
parent b0da71942a
commit e80df5100f
11 changed files with 158 additions and 464 deletions
+1
View File
@@ -12,3 +12,4 @@ mod gameoflife;
mod tetris;
mod asteroids;
mod crystalrpg;
mod pong;
+57
View File
@@ -0,0 +1,57 @@
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use async_trait::async_trait;
use core::fmt::Write;
use crate::std::application::{Application, Error};
use crate::std;
struct Game {
ball: Ball,
player1: Player,
player2: Player,
}
#[async_trait]
impl Application for Game {
fn new() -> Self {
Game {
ball: Ball::new(),
player1: Player::new(1),
player2: Player::new(2),
}
}
async fn run(&mut self, _: Vec<String>) -> Result<(), Error> {
loop {
self.ball.update(&self.player1, &self.player2);
}
Ok(())
}
}
struct Player {
x: i32,
y: i32,
score: i32,
}
impl Player {
fn new(y: i32) -> Self {
Player { x: 0, y, score: 0 }
}
}
struct Ball {
x: i32,
y: i32,
}
impl Ball {
fn new() -> Self {
Ball { x: 0, y: 0 }
}
fn update(&mut self, player1: &Player, player2: &Player) {
self.x += 1;
}
}
+13
View File
@@ -18,6 +18,7 @@ use crate::user::lib::libgui::{
cg_inputs::CgLineEdit,
};
use crate::user::lib::libgui::cg_core::{CgTextInput, Widget};
use crate::user::lib::libgui::cg_widgets::CgDialog;
lazy_static! {
pub static ref CMD: Mutex<CommandHandler> = Mutex::new(CommandHandler::new());
@@ -253,6 +254,18 @@ struct CmdHistory {
}
async fn setup_ui() {
let dialog = CgDialog::new(
Dimensions::new(40, 10),
String::from("test dialog"),
String::from("dialog body"),
String::from("[dialog footer]")
);
if let Ok(frame) = dialog.render() {
frame.write_to_screen().unwrap();
}
return;
serial_println!("idk");
let label= Widget::insert(CgLabel::new(
String::from("test label"),