diff --git a/os/src/drivers/gpu/mod.rs b/os/src/drivers/gpu/mod.rs index 9984ac9..2dc80d4 100644 --- a/os/src/drivers/gpu/mod.rs +++ b/os/src/drivers/gpu/mod.rs @@ -50,7 +50,6 @@ impl VirtIOGPU { } } } - } impl GPUDevice for VirtIOGPU { @@ -63,7 +62,5 @@ impl GPUDevice for VirtIOGPU { core::slice::from_raw_parts_mut(ptr, self.fb.len()) } } - fn update_cursor(&self) { - - } + fn update_cursor(&self) {} } diff --git a/os/src/drivers/input/mod.rs b/os/src/drivers/input/mod.rs index ef89fc6..aa3022f 100644 --- a/os/src/drivers/input/mod.rs +++ b/os/src/drivers/input/mod.rs @@ -1,10 +1,17 @@ +use crate::{ + gui::{Button, Component}, + sync::UPIntrFreeCell, + syscall::PAD, +}; +use alloc::{string::ToString, sync::Arc}; use core::any::Any; -use alloc::{sync::Arc, string::ToString}; -use embedded_graphics::{text::Text, prelude::{Size, Point}}; +use embedded_graphics::{ + prelude::{Point, Size}, + text::Text, +}; use k210_hal::cache::Uncache; use virtio_drivers::{VirtIOHeader, VirtIOInput}; use virtio_input_decoder::{Decoder, Key, KeyType}; -use crate::{gui::{Button, Component}, sync::UPIntrFreeCell, syscall::PAD}; use super::GPU_DEVICE; @@ -56,13 +63,12 @@ impl INPUTDevice for VirtIOINPUT { } else { a.repaint(k.to_string()) } - }, - Err(_) => {}, + } + Err(_) => {} } - } } virtio_input_decoder::DecodeType::Mouse(mouse) => println!("{:?}", mouse), } } -} \ No newline at end of file +} diff --git a/os/src/drivers/mod.rs b/os/src/drivers/mod.rs index ae6830c..337c76d 100644 --- a/os/src/drivers/mod.rs +++ b/os/src/drivers/mod.rs @@ -1,9 +1,9 @@ pub mod block; pub mod chardev; -pub mod plic; pub mod gpu; pub mod input; +pub mod plic; pub use block::BLOCK_DEVICE; pub use chardev::UART; pub use gpu::*; -pub use input::*; \ No newline at end of file +pub use input::*; diff --git a/os/src/fs/mod.rs b/os/src/fs/mod.rs index be9b077..221d68b 100644 --- a/os/src/fs/mod.rs +++ b/os/src/fs/mod.rs @@ -11,6 +11,6 @@ pub trait File: Send + Sync { fn write(&self, buf: UserBuffer) -> usize; } -pub use inode::{list_apps, open_file, OSInode, OpenFlags,ROOT_INODE}; +pub use inode::{list_apps, open_file, OSInode, OpenFlags, ROOT_INODE}; pub use pipe::{make_pipe, Pipe}; pub use stdio::{Stdin, Stdout}; diff --git a/os/src/gui/button.rs b/os/src/gui/button.rs index f84f11f..dee2f7c 100644 --- a/os/src/gui/button.rs +++ b/os/src/gui/button.rs @@ -1,39 +1,51 @@ -use alloc::{sync::Arc, string::String}; -use embedded_graphics::{prelude::{Size, Point, Primitive, RgbColor, Dimensions}, primitives::{Rectangle, PrimitiveStyle}, pixelcolor::Rgb888, Drawable, text::{Text, Alignment}, mono_font::{ascii::{FONT_6X10, FONT_10X20}, MonoTextStyle}}; +use alloc::{string::String, sync::Arc}; +use embedded_graphics::{ + mono_font::{ + ascii::{FONT_10X20, FONT_6X10}, + MonoTextStyle, + }, + pixelcolor::Rgb888, + prelude::{Dimensions, Point, Primitive, RgbColor, Size}, + primitives::{PrimitiveStyle, Rectangle}, + text::{Alignment, Text}, + Drawable, +}; -use crate::{sync::UPIntrFreeCell, drivers::GPU_DEVICE}; +use crate::{drivers::GPU_DEVICE, sync::UPIntrFreeCell}; use super::{Component, Graphics}; pub struct Button { - inner: UPIntrFreeCell + inner: UPIntrFreeCell, } pub struct ButtonInner { graphic: Graphics, text: String, - parent: Option> + parent: Option>, } impl Button { - pub fn new(size: Size, point: Point, parent: Option>,text:String) -> Self { + pub fn new(size: Size, point: Point, parent: Option>, text: String) -> Self { let point = match &parent { Some(p) => { let (_, p) = p.bound(); - Point::new(p.x + point.x,p.y + point.y) - }, + Point::new(p.x + point.x, p.y + point.y) + } None => point, }; Self { inner: unsafe { - UPIntrFreeCell::new( - ButtonInner { - graphic: Graphics { size, point, drv:GPU_DEVICE.clone() }, - text, - parent, - } - ) - } + UPIntrFreeCell::new(ButtonInner { + graphic: Graphics { + size, + point, + drv: GPU_DEVICE.clone(), + }, + text, + parent, + }) + }, } } } @@ -44,18 +56,24 @@ impl Component for Button { let text = inner.text.clone(); Text::with_alignment( text.as_str(), - inner.graphic.bounding_box().center(), - MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), - Alignment::Center - ).draw(&mut inner.graphic); + inner.graphic.bounding_box().center(), + MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), + Alignment::Center, + ) + .draw(&mut inner.graphic); } fn add(&self, comp: alloc::sync::Arc) { unreachable!() } - fn bound(&self) -> (embedded_graphics::prelude::Size, embedded_graphics::prelude::Point) { + fn bound( + &self, + ) -> ( + embedded_graphics::prelude::Size, + embedded_graphics::prelude::Point, + ) { let inner = self.inner.exclusive_access(); (inner.graphic.size, inner.graphic.point) } -} \ No newline at end of file +} diff --git a/os/src/gui/graphic.rs b/os/src/gui/graphic.rs index b673690..0fdfce9 100644 --- a/os/src/gui/graphic.rs +++ b/os/src/gui/graphic.rs @@ -19,7 +19,7 @@ impl Graphics { Self { size, point, - drv: GPU_DEVICE.clone() + drv: GPU_DEVICE.clone(), } } } diff --git a/os/src/gui/icon.rs b/os/src/gui/icon.rs index e93ccd9..d70462a 100644 --- a/os/src/gui/icon.rs +++ b/os/src/gui/icon.rs @@ -1,42 +1,44 @@ - - -use alloc::{vec::Vec, string::String, sync::Arc}; -use embedded_graphics::{prelude::{Size, Point, RgbColor}, image::Image, text::Text, mono_font::{MonoTextStyle, iso_8859_13::FONT_6X12, ascii::FONT_10X20}, pixelcolor::Rgb888, Drawable}; +use alloc::{string::String, sync::Arc, vec::Vec}; +use embedded_graphics::{ + image::Image, + mono_font::{ascii::FONT_10X20, iso_8859_13::FONT_6X12, MonoTextStyle}, + pixelcolor::Rgb888, + prelude::{Point, RgbColor, Size}, + text::Text, + Drawable, +}; use tinybmp::Bmp; -use crate::{sync::UPIntrFreeCell, drivers::GPU_DEVICE}; +use crate::{drivers::GPU_DEVICE, sync::UPIntrFreeCell}; -use super::{Graphics, Component, ImageComp}; +use super::{Component, Graphics, ImageComp}; static FILEICON: &[u8] = include_bytes!("../assert/file.bmp"); pub struct IconController { - inner: UPIntrFreeCell + inner: UPIntrFreeCell, } pub struct IconControllerInner { files: Vec, graphic: Graphics, - parent: Option> + parent: Option>, } impl IconController { - pub fn new(files: Vec,parent: Option>) -> Self { - IconController { + pub fn new(files: Vec, parent: Option>) -> Self { + IconController { inner: unsafe { - UPIntrFreeCell::new( - IconControllerInner { - files, - graphic: Graphics { - size: Size::new(1024, 768), - point: Point::new(0, 0), - drv: GPU_DEVICE.clone() - }, - parent, - } - ) - - } + UPIntrFreeCell::new(IconControllerInner { + files, + graphic: Graphics { + size: Size::new(1024, 768), + point: Point::new(0, 0), + drv: GPU_DEVICE.clone(), + }, + parent, + }) + }, } } } @@ -51,20 +53,19 @@ impl Component for IconController { for file in v { println!("file"); let bmp = Bmp::::from_slice(FILEICON).unwrap(); - Image::new(&bmp, Point::new(x, y),).draw(&mut inner.graphic); - let text = Text::new( - file.as_str(), - Point::new(x + 20, y + 80), - MonoTextStyle::new(&FONT_10X20,Rgb888::BLACK) - ); - text.draw(&mut inner.graphic); - if y >= 600 { - x = x + 70; - y = 10; - } else { - y = y + 90; - } - + Image::new(&bmp, Point::new(x, y)).draw(&mut inner.graphic); + let text = Text::new( + file.as_str(), + Point::new(x + 20, y + 80), + MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), + ); + text.draw(&mut inner.graphic); + if y >= 600 { + x = x + 70; + y = 10; + } else { + y = y + 90; + } } } @@ -75,4 +76,4 @@ impl Component for IconController { fn bound(&self) -> (Size, Point) { todo!() } -} \ No newline at end of file +} diff --git a/os/src/gui/image.rs b/os/src/gui/image.rs index 12087b2..aac5829 100644 --- a/os/src/gui/image.rs +++ b/os/src/gui/image.rs @@ -1,7 +1,9 @@ -use alloc::{vec::Vec, sync::Arc}; +use alloc::{sync::Arc, vec::Vec}; use embedded_graphics::{ image::Image, - prelude::{Point, Size}, pixelcolor::Rgb888, Drawable, + pixelcolor::Rgb888, + prelude::{Point, Size}, + Drawable, }; use tinybmp::Bmp; @@ -10,21 +12,25 @@ use crate::{ sync::UPIntrFreeCell, }; -use super::{Graphics, Component}; +use super::{Component, Graphics}; pub struct ImageComp { - inner: UPIntrFreeCell, } pub struct ImageInner { image: &'static [u8], graphic: Graphics, - parent: Option> + parent: Option>, } impl ImageComp { - pub fn new(size: Size, point: Point, v: &'static [u8],parent: Option>) -> Self { + pub fn new( + size: Size, + point: Point, + v: &'static [u8], + parent: Option>, + ) -> Self { unsafe { ImageComp { inner: UPIntrFreeCell::new(ImageInner { @@ -44,21 +50,23 @@ impl ImageComp { impl Component for ImageComp { fn paint(&self) { let mut inner = self.inner.exclusive_access(); - let b = unsafe { + let b = unsafe { let len = inner.image.len(); - let ptr = inner.image - .as_ptr() as *const u8; + let ptr = inner.image.as_ptr() as *const u8; core::slice::from_raw_parts(ptr, len) }; let bmp = Bmp::::from_slice(b).unwrap(); let point = match &inner.parent { Some(parent) => { let (_, point) = parent.bound(); - Point::new(point.x + inner.graphic.point.x, point.y + inner.graphic.point.y) + Point::new( + point.x + inner.graphic.point.x, + point.y + inner.graphic.point.y, + ) } None => inner.graphic.point, }; - Image::new(&bmp, point,).draw(&mut inner.graphic); + Image::new(&bmp, point).draw(&mut inner.graphic); } fn add(&self, comp: alloc::sync::Arc) { diff --git a/os/src/gui/mod.rs b/os/src/gui/mod.rs index 1111730..da3aae9 100644 --- a/os/src/gui/mod.rs +++ b/os/src/gui/mod.rs @@ -1,18 +1,18 @@ +mod button; mod graphic; +mod icon; mod image; mod panel; -mod icon; -mod button; mod terminal; use alloc::sync::Arc; -use embedded_graphics::prelude::{Size, Point}; -use core::any::Any; -pub use graphic::*; -pub use panel::*; -pub use image::*; -pub use icon::*; -pub use terminal::*; pub use button::*; +use core::any::Any; +use embedded_graphics::prelude::{Point, Size}; +pub use graphic::*; +pub use icon::*; +pub use image::*; +pub use panel::*; +pub use terminal::*; pub trait Component: Send + Sync + Any { fn paint(&self); diff --git a/os/src/gui/panel.rs b/os/src/gui/panel.rs index b420012..2af2961 100644 --- a/os/src/gui/panel.rs +++ b/os/src/gui/panel.rs @@ -1,4 +1,4 @@ -use alloc::{collections::VecDeque, sync::Arc, rc::Weak}; +use alloc::{collections::VecDeque, rc::Weak, sync::Arc}; use embedded_graphics::{ pixelcolor::Rgb888, prelude::{Point, Primitive, RgbColor, Size}, diff --git a/os/src/gui/terminal.rs b/os/src/gui/terminal.rs index 81168fb..8d233f5 100644 --- a/os/src/gui/terminal.rs +++ b/os/src/gui/terminal.rs @@ -1,50 +1,66 @@ -use alloc::{collections::VecDeque, sync::Arc, string::{String, ToString}}; -use embedded_graphics::{prelude::{Size, Point, RgbColor, Primitive, Dimensions}, text::{Text, Alignment}, mono_font::{MonoTextStyle, ascii::FONT_10X20}, pixelcolor::Rgb888, Drawable, primitives::{Rectangle, PrimitiveStyle}}; +use alloc::{ + collections::VecDeque, + string::{String, ToString}, + sync::Arc, +}; +use embedded_graphics::{ + mono_font::{ascii::FONT_10X20, MonoTextStyle}, + pixelcolor::Rgb888, + prelude::{Dimensions, Point, Primitive, RgbColor, Size}, + primitives::{PrimitiveStyle, Rectangle}, + text::{Alignment, Text}, + Drawable, +}; -use crate::{sync::UPIntrFreeCell, drivers::GPU_DEVICE}; +use crate::{drivers::GPU_DEVICE, sync::UPIntrFreeCell}; -use super::{Graphics, Component, Panel, button::Button}; +use super::{button::Button, Component, Graphics, Panel}; pub struct Terminal { - inner: UPIntrFreeCell + inner: UPIntrFreeCell, } pub struct TerminalInner { pub text: String, - titel:Option, + titel: Option, graphic: Graphics, comps: VecDeque>, } impl Terminal { - pub fn new(size: Size, point: Point, parent: Option>,titel: Option,text:String) -> Self { + pub fn new( + size: Size, + point: Point, + parent: Option>, + titel: Option, + text: String, + ) -> Self { Self { inner: unsafe { - UPIntrFreeCell::new( - TerminalInner { - text, - titel, - graphic: Graphics { - size, - point, - drv: GPU_DEVICE.clone(), - }, - comps: VecDeque::new(), - } - ) - } + UPIntrFreeCell::new(TerminalInner { + text, + titel, + graphic: Graphics { + size, + point, + drv: GPU_DEVICE.clone(), + }, + comps: VecDeque::new(), + }) + }, } } - pub fn repaint(&self, text:String){ + pub fn repaint(&self, text: String) { let mut inner = self.inner.exclusive_access(); inner.text += text.as_str(); Text::with_alignment( inner.text.clone().as_str(), - Point::new( 20, 50), - MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), - Alignment::Left - ).draw(&mut inner.graphic); + Point::new(20, 50), + MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), + Alignment::Left, + ) + .draw(&mut inner.graphic); } } @@ -60,21 +76,21 @@ impl Component for Terminal { comp.upgrade().unwrap().paint(); } let mut inner = self.inner.exclusive_access(); - let titel = inner.titel.get_or_insert("No Titel".to_string()).clone(); + let titel = inner.titel.get_or_insert("No Titel".to_string()).clone(); let text = Text::new( - titel.as_str(), - Point::new(20, 20), - MonoTextStyle::new(&FONT_10X20,Rgb888::BLACK) + titel.as_str(), + Point::new(20, 20), + MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), ); text.draw(&mut inner.graphic); Text::with_alignment( inner.text.clone().as_str(), - Point::new( 20, 50), - MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), - Alignment::Left - ).draw(&mut inner.graphic); - + Point::new(20, 50), + MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), + Alignment::Left, + ) + .draw(&mut inner.graphic); } fn add(&self, comp: Arc) { @@ -86,4 +102,4 @@ impl Component for Terminal { let inner = self.inner.exclusive_access(); (inner.graphic.size, inner.graphic.point) } -} \ No newline at end of file +} diff --git a/os/src/sync/mod.rs b/os/src/sync/mod.rs index c047d27..d9a00b5 100644 --- a/os/src/sync/mod.rs +++ b/os/src/sync/mod.rs @@ -6,4 +6,4 @@ mod up; pub use condvar::Condvar; pub use mutex::{Mutex, MutexBlocking, MutexSpin}; pub use semaphore::Semaphore; -pub use up::{UPIntrFreeCell, UPIntrRefMut}; \ No newline at end of file +pub use up::{UPIntrFreeCell, UPIntrRefMut}; diff --git a/os/src/syscall/mod.rs b/os/src/syscall/mod.rs index 46890ed..5d8660f 100644 --- a/os/src/syscall/mod.rs +++ b/os/src/syscall/mod.rs @@ -27,17 +27,17 @@ const SYSCALL_CONDVAR_SIGNAL: usize = 1031; const SYSCALL_CONDVAR_WAIT: usize = 1032; const SYSCALL_CREATE_DESKTOP: usize = 2000; mod fs; +mod gui; mod process; mod sync; mod thread; -mod gui; +pub use self::gui::create_desktop; use fs::*; +pub use gui::PAD; use process::*; use sync::*; use thread::*; -pub use gui::PAD; -pub use self::gui::create_desktop; pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize { match syscall_id {