Jaswanth-2008's picture
Upload AeroOS complete Rust source code
dcbeeb2 verified
Raw History Blame Contribute Delete
6.58 kB
extern crate alloc;
use alloc::string::String;
use pc_keyboard::DecodedKey;
use crate::apps::calculator::CalculatorApp;
use crate::apps::editor::EditorApp;
use crate::apps::file_manager::FileManagerApp;
use crate::apps::net_manager::NetManagerApp;
use crate::apps::settings::SettingsApp;
use crate::apps::snapstore::SnapStoreApp;
use crate::apps::snake::SnakeApp;
use crate::apps::sysinfo::SysInfoApp;
use crate::apps::terminal::TerminalApp;
use crate::apps::wifi_app::WifiManagerApp;
use crate::apps::AppType;
use crate::graphics::icons::IconType;
use crate::graphics::surface::Surface;
pub struct Window {
pub id: usize,
pub title: String,
pub x: i32,
pub y: i32,
pub width: usize,
pub height: usize,
pub is_minimized: bool,
pub is_maximized: bool,
pub prev_rect: (i32, i32, usize, usize),
pub app_type: AppType,
pub icon: IconType,
// App state
pub terminal: Option<TerminalApp>,
pub net_manager: Option<NetManagerApp>,
pub sysinfo: Option<SysInfoApp>,
pub file_manager: Option<FileManagerApp>,
pub calculator: Option<CalculatorApp>,
pub editor: Option<EditorApp>,
pub settings: Option<SettingsApp>,
pub snake: Option<SnakeApp>,
pub snapstore: Option<SnapStoreApp>,
pub wifi_manager: Option<WifiManagerApp>,
}
impl Window {
pub fn new(id: usize, title: String, x: i32, y: i32, width: usize, height: usize, app_type: AppType) -> Self {
let mut term = None;
let mut net = None;
let mut sys = None;
let mut fm = None;
let mut calc = None;
let mut ed = None;
let mut set = None;
let mut snake = None;
let mut snap = None;
let mut wifi = None;
let icon;
match app_type {
AppType::Terminal => {
icon = IconType::Terminal;
term = Some(TerminalApp::new());
}
AppType::NetManager => {
icon = IconType::Network;
net = Some(NetManagerApp::new());
}
AppType::WifiManager => {
icon = IconType::Network;
wifi = Some(WifiManagerApp::new());
}
AppType::SysInfo => {
icon = IconType::TaskManager;
sys = Some(SysInfoApp::new());
}
AppType::FileManager => {
icon = IconType::FileManager;
fm = Some(FileManagerApp::new());
}
AppType::Calculator => {
icon = IconType::Calculator;
calc = Some(CalculatorApp::new());
}
AppType::Editor => {
icon = IconType::Editor;
ed = Some(EditorApp::new());
}
AppType::Settings => {
icon = IconType::Settings;
set = Some(SettingsApp::new());
}
AppType::Snake => {
icon = IconType::TaskManager;
snake = Some(SnakeApp::new());
}
AppType::SnapStore => {
icon = IconType::OsLogo;
snap = Some(SnapStoreApp::new());
}
}
Self {
id,
title,
x,
y,
width,
height,
is_minimized: false,
is_maximized: false,
prev_rect: (x, y, width, height),
app_type,
icon,
terminal: term,
net_manager: net,
sysinfo: sys,
file_manager: fm,
calculator: calc,
editor: ed,
settings: set,
snake,
snapstore: snap,
wifi_manager: wifi,
}
}
pub fn handle_key(&mut self, key: DecodedKey) {
if let Some(ref mut term) = self.terminal {
term.handle_key(key);
} else if let Some(ref mut ed) = self.editor {
ed.handle_key(key);
} else if let Some(ref mut snake) = self.snake {
snake.handle_key(key);
} else if let Some(ref mut snap) = self.snapstore {
snap.handle_key(key);
}
}
pub fn handle_scroll(&mut self, delta: i32) {
if let Some(ref mut term) = self.terminal {
term.handle_scroll(delta);
} else if let Some(ref mut snap) = self.snapstore {
snap.handle_scroll(delta);
}
}
pub fn handle_client_click(&mut self, rel_x: i32, rel_y: i32) {
if let Some(ref mut wifi) = self.wifi_manager {
wifi.handle_click(rel_x, rel_y);
} else if let Some(ref mut net) = self.net_manager {
net.handle_click(rel_x, rel_y);
} else if let Some(ref mut fm) = self.file_manager {
fm.handle_click(rel_x, rel_y);
} else if let Some(ref mut calc) = self.calculator {
calc.handle_click(rel_x, rel_y);
} else if let Some(ref mut snap) = self.snapstore {
snap.handle_click(rel_x, rel_y);
} else if let Some(ref mut set) = self.settings {
set.handle_click(rel_x, rel_y);
}
}
pub fn render_content(&mut self, surface: &mut Surface, client_x: i32, client_y: i32, client_w: usize, client_h: usize) {
if let Some(ref term) = self.terminal {
term.render(surface, client_x, client_y, client_w, client_h);
} else if let Some(ref wifi) = self.wifi_manager {
wifi.render(surface, client_x, client_y, client_w, client_h);
} else if let Some(ref net) = self.net_manager {
net.render(surface, client_x, client_y, client_w, client_h);
} else if let Some(ref sys) = self.sysinfo {
sys.render(surface, client_x, client_y, client_w, client_h);
} else if let Some(ref fm) = self.file_manager {
fm.render(surface, client_x, client_y, client_w, client_h);
} else if let Some(ref calc) = self.calculator {
calc.render(surface, client_x, client_y, client_w, client_h);
} else if let Some(ref ed) = self.editor {
ed.render(surface, client_x, client_y, client_w, client_h);
} else if let Some(ref set) = self.settings {
set.render(surface, client_x, client_y, client_w, client_h);
} else if let Some(ref mut snake) = self.snake {
snake.render(surface, client_x, client_y, client_w, client_h);
} else if let Some(ref snap) = self.snapstore {
snap.render(surface, client_x, client_y, client_w, client_h);
}
}
}