extern crate alloc; use alloc::format; use crate::graphics::color::Color; use crate::graphics::icons::IconType; use crate::graphics::surface::Surface; use crate::net::wifi; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum SettingsTab { Wifi, System, Personalization, } pub struct SettingsApp { pub active_tab: SettingsTab, } impl SettingsApp { pub fn new() -> Self { Self { active_tab: SettingsTab::Wifi, } } pub fn handle_click(&mut self, rel_x: i32, rel_y: i32) { // Tab switching along top row (y = 12..38) if rel_y >= 12 && rel_y <= 38 { if rel_x >= 16 && rel_x <= 130 { self.active_tab = SettingsTab::Wifi; } else if rel_x >= 140 && rel_x <= 250 { self.active_tab = SettingsTab::System; } else if rel_x >= 260 && rel_x <= 390 { self.active_tab = SettingsTab::Personalization; } return; } if matches!(self.active_tab, SettingsTab::Wifi) { let aps = wifi::scan_networks(); for (i, ap) in aps.iter().take(4).enumerate() { let item_y = 182 + (i as i32 * 26); if rel_y >= item_y && rel_y <= item_y + 24 && rel_x >= 16 && rel_x <= 500 { wifi::connect_ap(ap, ""); break; } } } } pub fn render(&self, surface: &mut Surface, x: i32, y: i32, w: usize, h: usize) { surface.draw_rect(x, y, w, h, Color::rgb(24, 27, 36)); // 1. Navigation Tabs let is_wifi = matches!(self.active_tab, SettingsTab::Wifi); let is_sys = matches!(self.active_tab, SettingsTab::System); let is_pers = matches!(self.active_tab, SettingsTab::Personalization); let wifi_bg = if is_wifi { Color::rgb(0, 120, 215) } else { Color::rgba(255, 255, 255, 12) }; let sys_bg = if is_sys { Color::rgb(0, 120, 215) } else { Color::rgba(255, 255, 255, 12) }; let pers_bg = if is_pers { Color::rgb(0, 120, 215) } else { Color::rgba(255, 255, 255, 12) }; surface.draw_rounded_rect(x + 16, y + 10, 114, 26, 6, wifi_bg); surface.draw_text("Wi-Fi & Network", x + 24, y + 16, Color::WHITE); surface.draw_rounded_rect(x + 140, y + 10, 110, 26, 6, sys_bg); surface.draw_text("System Hardware", x + 148, y + 16, Color::WHITE); surface.draw_rounded_rect(x + 260, y + 10, 125, 26, 6, pers_bg); surface.draw_text("Personalization", x + 270, y + 16, Color::WHITE); // Divider surface.draw_rect(x, y + 42, w, 1, Color::rgba(255, 255, 255, 20)); let card_w = w.saturating_sub(32); match self.active_tab { SettingsTab::Wifi => { let st = wifi::get_status(); // 1. Active Wi-Fi Connection Card surface.draw_rounded_rect(x + 16, y + 50, card_w, 114, 8, Color::rgb(32, 36, 48)); surface.draw_rect_outline(x + 16, y + 50, card_w, 114, Color::rgba(0, 150, 255, 40), 1); surface.draw_icon_16(IconType::Network, x + 26, y + 58, Color::rgb(16, 185, 129)); let header = format!("Wi-Fi: Connected to '{}'", st.connected_ssid); surface.draw_text(&header, x + 48, y + 60, Color::WHITE); let speed_badge = format!("[ Connected • {} Mbps ]", st.link_speed_mbps); surface.draw_text(&speed_badge, x + card_w as i32 - 170, y + 60, Color::rgb(16, 185, 129)); let net_info = format!("IPv4: {}.{}.{}.{} | Mask: {}.{}.{}.{} | GW: {}.{}.{}.{}", st.ip_address[0], st.ip_address[1], st.ip_address[2], st.ip_address[3], st.subnet_mask[0], st.subnet_mask[1], st.subnet_mask[2], st.subnet_mask[3], st.gateway_ip[0], st.gateway_ip[1], st.gateway_ip[2], st.gateway_ip[3]); surface.draw_text(&net_info, x + 28, y + 82, Color::TEXT_SECONDARY); let mac_str = format!("{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}", st.mac_address[0], st.mac_address[1], st.mac_address[2], st.mac_address[3], st.mac_address[4], st.mac_address[5]); let rssi = -100 + (st.signal_percent as i32 / 2); let sig_info = format!("MAC: {} | Signal: {}% ({} dBm) | 5 GHz Ch {}", mac_str, st.signal_percent, rssi, st.channel); surface.draw_text(&sig_info, x + 28, y + 102, Color::ACCENT_CYAN); let hw_info = format!("Hardware: {} ({})", st.adapter_name, st.phy_mode); surface.draw_text(&hw_info, x + 28, y + 122, Color::TEXT_MUTED); // 2. Available Networks Card surface.draw_rounded_rect(x + 16, y + 172, card_w, 118, 8, Color::rgb(32, 36, 48)); surface.draw_text("Available Wireless Networks (Click to Connect):", x + 26, y + 180, Color::WHITE); let aps = wifi::scan_networks(); let mut ap_y = y + 200; for ap in aps.iter().take(4) { let is_active = st.connected && st.connected_ssid == ap.ssid; let item_bg = if is_active { Color::rgba(0, 120, 215, 45) } else { Color::rgba(255, 255, 255, 6) }; surface.draw_rounded_rect(x + 24, ap_y, card_w.saturating_sub(16), 22, 4, item_bg); surface.draw_icon_16(IconType::Network, x + 30, ap_y + 3, Color::WHITE); surface.draw_text(ap.ssid, x + 50, ap_y + 4, Color::WHITE); let sec_str = match ap.security { wifi::WifiSecurity::Open => "Open", wifi::WifiSecurity::Wpa2Personal => "WPA2", wifi::WifiSecurity::Wpa3Personal => "WPA3", wifi::WifiSecurity::Wpa2Enterprise => "802.1X", }; surface.draw_text(sec_str, x + 230, ap_y + 4, Color::TEXT_MUTED); let sig_text = format!("{}%", ap.signal_percent); surface.draw_text(&sig_text, x + 290, ap_y + 4, Color::rgb(16, 185, 129)); let btn_text = if is_active { "[Connected]" } else { "[Connect]" }; let btn_color = if is_active { Color::rgb(16, 185, 129) } else { Color::rgb(0, 198, 255) }; surface.draw_text(btn_text, x + card_w as i32 - 75, ap_y + 4, btn_color); ap_y += 24; } } SettingsTab::System => { // Display Card surface.draw_rounded_rect(x + 16, y + 54, card_w, 75, 8, Color::rgb(32, 36, 48)); surface.draw_text("Display Driver: Direct UEFI GOP Framebuffer", x + 28, y + 66, Color::WHITE); let res_text = format!("Resolution: {} x {} (32-bit ARGB TrueColor)", surface.width, surface.height); surface.draw_text(&res_text, x + 28, y + 86, Color::TEXT_SECONDARY); surface.draw_text("Refresh Rate: 60 Hz VSync Buffered", x + 28, y + 104, Color::ACCENT_CYAN); // Hardware Specs Card surface.draw_rounded_rect(x + 16, y + 138, card_w, 70, 8, Color::rgb(32, 36, 48)); surface.draw_text("Processor: 64-bit x86_64 SMP Virtual Core", x + 28, y + 148, Color::WHITE); surface.draw_text("Memory: 16 MiB High-Performance Heap (4-Level Paging)", x + 28, y + 166, Color::TEXT_SECONDARY); surface.draw_text("Input Controller: PS/2 Keyboard & IntelliMouse Scroll Wheel", x + 28, y + 184, Color::TEXT_SECONDARY); // Real-Time Clock Hardware Card let dt = crate::drivers::rtc::get_datetime(); surface.draw_rounded_rect(x + 16, y + 216, card_w, 55, 8, Color::rgb(32, 36, 48)); surface.draw_text("Date & Time: Synchronized with Host CMOS RTC", x + 28, y + 226, Color::WHITE); let time_full = format!("Current: {} ({})", dt.format_full(), dt.format_time_12()); surface.draw_text(&time_full, x + 28, y + 244, Color::ACCENT_CYAN); } SettingsTab::Personalization => { // Theme Card surface.draw_rounded_rect(x + 16, y + 54, card_w, 75, 8, Color::rgb(32, 36, 48)); surface.draw_text("Theme: Windows 11 Fluent Mica + macOS Dark Mode", x + 28, y + 66, Color::WHITE); surface.draw_text("Window Chrome: Centered Taskbar, Acrylic Shadows, Traffic Controls", x + 28, y + 86, Color::TEXT_SECONDARY); surface.draw_text("Accent Color: Deep Ocean Cyan (#00C6FF)", x + 28, y + 104, Color::ACCENT_CYAN); // Sound Card surface.draw_rounded_rect(x + 16, y + 138, card_w, 65, 8, Color::rgb(32, 36, 48)); surface.draw_text("Audio: PC Speaker Chimes & Melodies Active", x + 28, y + 150, Color::WHITE); surface.draw_text("Status: Sound Output Enabled", x + 28, y + 170, Color::rgb(16, 185, 129)); } } } }