started working on dialogs
This commit is contained in:
@@ -12,3 +12,4 @@ mod gameoflife;
|
||||
mod tetris;
|
||||
mod asteroids;
|
||||
mod crystalrpg;
|
||||
mod pong;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user