cargo fmt

This commit is contained in:
Yu Chen 2022-06-20 23:32:27 +08:00
parent f4a7714fe0
commit 58096b08d6
13 changed files with 181 additions and 135 deletions

View File

@ -50,7 +50,6 @@ impl VirtIOGPU {
} }
} }
} }
} }
impl GPUDevice for VirtIOGPU { impl GPUDevice for VirtIOGPU {
@ -63,7 +62,5 @@ impl GPUDevice for VirtIOGPU {
core::slice::from_raw_parts_mut(ptr, self.fb.len()) core::slice::from_raw_parts_mut(ptr, self.fb.len())
} }
} }
fn update_cursor(&self) { fn update_cursor(&self) {}
}
} }

View File

@ -1,10 +1,17 @@
use crate::{
gui::{Button, Component},
sync::UPIntrFreeCell,
syscall::PAD,
};
use alloc::{string::ToString, sync::Arc};
use core::any::Any; use core::any::Any;
use alloc::{sync::Arc, string::ToString}; use embedded_graphics::{
use embedded_graphics::{text::Text, prelude::{Size, Point}}; prelude::{Point, Size},
text::Text,
};
use k210_hal::cache::Uncache; use k210_hal::cache::Uncache;
use virtio_drivers::{VirtIOHeader, VirtIOInput}; use virtio_drivers::{VirtIOHeader, VirtIOInput};
use virtio_input_decoder::{Decoder, Key, KeyType}; use virtio_input_decoder::{Decoder, Key, KeyType};
use crate::{gui::{Button, Component}, sync::UPIntrFreeCell, syscall::PAD};
use super::GPU_DEVICE; use super::GPU_DEVICE;
@ -56,10 +63,9 @@ impl INPUTDevice for VirtIOINPUT {
} else { } else {
a.repaint(k.to_string()) a.repaint(k.to_string())
} }
}, }
Err(_) => {}, Err(_) => {}
} }
} }
} }
virtio_input_decoder::DecodeType::Mouse(mouse) => println!("{:?}", mouse), virtio_input_decoder::DecodeType::Mouse(mouse) => println!("{:?}", mouse),

View File

@ -1,8 +1,8 @@
pub mod block; pub mod block;
pub mod chardev; pub mod chardev;
pub mod plic;
pub mod gpu; pub mod gpu;
pub mod input; pub mod input;
pub mod plic;
pub use block::BLOCK_DEVICE; pub use block::BLOCK_DEVICE;
pub use chardev::UART; pub use chardev::UART;
pub use gpu::*; pub use gpu::*;

View File

@ -11,6 +11,6 @@ pub trait File: Send + Sync {
fn write(&self, buf: UserBuffer) -> usize; 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 pipe::{make_pipe, Pipe};
pub use stdio::{Stdin, Stdout}; pub use stdio::{Stdin, Stdout};

View File

@ -1,39 +1,51 @@
use alloc::{sync::Arc, string::String}; use alloc::{string::String, sync::Arc};
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 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}; use super::{Component, Graphics};
pub struct Button { pub struct Button {
inner: UPIntrFreeCell<ButtonInner> inner: UPIntrFreeCell<ButtonInner>,
} }
pub struct ButtonInner { pub struct ButtonInner {
graphic: Graphics, graphic: Graphics,
text: String, text: String,
parent: Option<Arc<dyn Component>> parent: Option<Arc<dyn Component>>,
} }
impl Button { impl Button {
pub fn new(size: Size, point: Point, parent: Option<Arc<dyn Component>>,text:String) -> Self { pub fn new(size: Size, point: Point, parent: Option<Arc<dyn Component>>, text: String) -> Self {
let point = match &parent { let point = match &parent {
Some(p) => { Some(p) => {
let (_, p) = p.bound(); 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, None => point,
}; };
Self { Self {
inner: unsafe { inner: unsafe {
UPIntrFreeCell::new( UPIntrFreeCell::new(ButtonInner {
ButtonInner { graphic: Graphics {
graphic: Graphics { size, point, drv:GPU_DEVICE.clone() }, size,
text, point,
parent, drv: GPU_DEVICE.clone(),
} },
) text,
} parent,
})
},
} }
} }
} }
@ -46,15 +58,21 @@ impl Component for Button {
text.as_str(), text.as_str(),
inner.graphic.bounding_box().center(), inner.graphic.bounding_box().center(),
MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK),
Alignment::Center Alignment::Center,
).draw(&mut inner.graphic); )
.draw(&mut inner.graphic);
} }
fn add(&self, comp: alloc::sync::Arc<dyn Component>) { fn add(&self, comp: alloc::sync::Arc<dyn Component>) {
unreachable!() 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(); let inner = self.inner.exclusive_access();
(inner.graphic.size, inner.graphic.point) (inner.graphic.size, inner.graphic.point)
} }

View File

@ -19,7 +19,7 @@ impl Graphics {
Self { Self {
size, size,
point, point,
drv: GPU_DEVICE.clone() drv: GPU_DEVICE.clone(),
} }
} }
} }

View File

@ -1,42 +1,44 @@
use alloc::{string::String, sync::Arc, vec::Vec};
use embedded_graphics::{
use alloc::{vec::Vec, string::String, sync::Arc}; image::Image,
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}; mono_font::{ascii::FONT_10X20, iso_8859_13::FONT_6X12, MonoTextStyle},
pixelcolor::Rgb888,
prelude::{Point, RgbColor, Size},
text::Text,
Drawable,
};
use tinybmp::Bmp; 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"); static FILEICON: &[u8] = include_bytes!("../assert/file.bmp");
pub struct IconController { pub struct IconController {
inner: UPIntrFreeCell<IconControllerInner> inner: UPIntrFreeCell<IconControllerInner>,
} }
pub struct IconControllerInner { pub struct IconControllerInner {
files: Vec<String>, files: Vec<String>,
graphic: Graphics, graphic: Graphics,
parent: Option<Arc<dyn Component>> parent: Option<Arc<dyn Component>>,
} }
impl IconController { impl IconController {
pub fn new(files: Vec<String>,parent: Option<Arc<dyn Component>>) -> Self { pub fn new(files: Vec<String>, parent: Option<Arc<dyn Component>>) -> Self {
IconController { IconController {
inner: unsafe { inner: unsafe {
UPIntrFreeCell::new( UPIntrFreeCell::new(IconControllerInner {
IconControllerInner { files,
files, graphic: Graphics {
graphic: Graphics { size: Size::new(1024, 768),
size: Size::new(1024, 768), point: Point::new(0, 0),
point: Point::new(0, 0), drv: GPU_DEVICE.clone(),
drv: GPU_DEVICE.clone() },
}, parent,
parent, })
} },
)
}
} }
} }
} }
@ -51,20 +53,19 @@ impl Component for IconController {
for file in v { for file in v {
println!("file"); println!("file");
let bmp = Bmp::<Rgb888>::from_slice(FILEICON).unwrap(); let bmp = Bmp::<Rgb888>::from_slice(FILEICON).unwrap();
Image::new(&bmp, Point::new(x, y),).draw(&mut inner.graphic); Image::new(&bmp, Point::new(x, y)).draw(&mut inner.graphic);
let text = Text::new( let text = Text::new(
file.as_str(), file.as_str(),
Point::new(x + 20, y + 80), Point::new(x + 20, y + 80),
MonoTextStyle::new(&FONT_10X20,Rgb888::BLACK) MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK),
); );
text.draw(&mut inner.graphic); text.draw(&mut inner.graphic);
if y >= 600 { if y >= 600 {
x = x + 70; x = x + 70;
y = 10; y = 10;
} else { } else {
y = y + 90; y = y + 90;
} }
} }
} }

View File

@ -1,7 +1,9 @@
use alloc::{vec::Vec, sync::Arc}; use alloc::{sync::Arc, vec::Vec};
use embedded_graphics::{ use embedded_graphics::{
image::Image, image::Image,
prelude::{Point, Size}, pixelcolor::Rgb888, Drawable, pixelcolor::Rgb888,
prelude::{Point, Size},
Drawable,
}; };
use tinybmp::Bmp; use tinybmp::Bmp;
@ -10,21 +12,25 @@ use crate::{
sync::UPIntrFreeCell, sync::UPIntrFreeCell,
}; };
use super::{Graphics, Component}; use super::{Component, Graphics};
pub struct ImageComp { pub struct ImageComp {
inner: UPIntrFreeCell<ImageInner>, inner: UPIntrFreeCell<ImageInner>,
} }
pub struct ImageInner { pub struct ImageInner {
image: &'static [u8], image: &'static [u8],
graphic: Graphics, graphic: Graphics,
parent: Option<Arc<dyn Component>> parent: Option<Arc<dyn Component>>,
} }
impl ImageComp { impl ImageComp {
pub fn new(size: Size, point: Point, v: &'static [u8],parent: Option<Arc<dyn Component>>) -> Self { pub fn new(
size: Size,
point: Point,
v: &'static [u8],
parent: Option<Arc<dyn Component>>,
) -> Self {
unsafe { unsafe {
ImageComp { ImageComp {
inner: UPIntrFreeCell::new(ImageInner { inner: UPIntrFreeCell::new(ImageInner {
@ -46,19 +52,21 @@ impl Component for ImageComp {
let mut inner = self.inner.exclusive_access(); let mut inner = self.inner.exclusive_access();
let b = unsafe { let b = unsafe {
let len = inner.image.len(); let len = inner.image.len();
let ptr = inner.image let ptr = inner.image.as_ptr() as *const u8;
.as_ptr() as *const u8;
core::slice::from_raw_parts(ptr, len) core::slice::from_raw_parts(ptr, len)
}; };
let bmp = Bmp::<Rgb888>::from_slice(b).unwrap(); let bmp = Bmp::<Rgb888>::from_slice(b).unwrap();
let point = match &inner.parent { let point = match &inner.parent {
Some(parent) => { Some(parent) => {
let (_, point) = parent.bound(); 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, 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<dyn Component>) { fn add(&self, comp: alloc::sync::Arc<dyn Component>) {

View File

@ -1,18 +1,18 @@
mod button;
mod graphic; mod graphic;
mod icon;
mod image; mod image;
mod panel; mod panel;
mod icon;
mod button;
mod terminal; mod terminal;
use alloc::sync::Arc; 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::*; 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 { pub trait Component: Send + Sync + Any {
fn paint(&self); fn paint(&self);

View File

@ -1,4 +1,4 @@
use alloc::{collections::VecDeque, sync::Arc, rc::Weak}; use alloc::{collections::VecDeque, rc::Weak, sync::Arc};
use embedded_graphics::{ use embedded_graphics::{
pixelcolor::Rgb888, pixelcolor::Rgb888,
prelude::{Point, Primitive, RgbColor, Size}, prelude::{Point, Primitive, RgbColor, Size},

View File

@ -1,50 +1,66 @@
use alloc::{collections::VecDeque, sync::Arc, string::{String, ToString}}; use alloc::{
use embedded_graphics::{prelude::{Size, Point, RgbColor, Primitive, Dimensions}, text::{Text, Alignment}, mono_font::{MonoTextStyle, ascii::FONT_10X20}, pixelcolor::Rgb888, Drawable, primitives::{Rectangle, PrimitiveStyle}}; 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 { pub struct Terminal {
inner: UPIntrFreeCell<TerminalInner> inner: UPIntrFreeCell<TerminalInner>,
} }
pub struct TerminalInner { pub struct TerminalInner {
pub text: String, pub text: String,
titel:Option<String>, titel: Option<String>,
graphic: Graphics, graphic: Graphics,
comps: VecDeque<Arc<dyn Component>>, comps: VecDeque<Arc<dyn Component>>,
} }
impl Terminal { impl Terminal {
pub fn new(size: Size, point: Point, parent: Option<Arc<dyn Component>>,titel: Option<String>,text:String) -> Self { pub fn new(
size: Size,
point: Point,
parent: Option<Arc<dyn Component>>,
titel: Option<String>,
text: String,
) -> Self {
Self { Self {
inner: unsafe { inner: unsafe {
UPIntrFreeCell::new( UPIntrFreeCell::new(TerminalInner {
TerminalInner { text,
text, titel,
titel, graphic: Graphics {
graphic: Graphics { size,
size, point,
point, drv: GPU_DEVICE.clone(),
drv: GPU_DEVICE.clone(), },
}, comps: VecDeque::new(),
comps: VecDeque::new(), })
} },
)
}
} }
} }
pub fn repaint(&self, text:String){ pub fn repaint(&self, text: String) {
let mut inner = self.inner.exclusive_access(); let mut inner = self.inner.exclusive_access();
inner.text += text.as_str(); inner.text += text.as_str();
Text::with_alignment( Text::with_alignment(
inner.text.clone().as_str(), inner.text.clone().as_str(),
Point::new( 20, 50), Point::new(20, 50),
MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK),
Alignment::Left Alignment::Left,
).draw(&mut inner.graphic); )
.draw(&mut inner.graphic);
} }
} }
@ -60,21 +76,21 @@ impl Component for Terminal {
comp.upgrade().unwrap().paint(); comp.upgrade().unwrap().paint();
} }
let mut inner = self.inner.exclusive_access(); 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( let text = Text::new(
titel.as_str(), titel.as_str(),
Point::new(20, 20), Point::new(20, 20),
MonoTextStyle::new(&FONT_10X20,Rgb888::BLACK) MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK),
); );
text.draw(&mut inner.graphic); text.draw(&mut inner.graphic);
Text::with_alignment( Text::with_alignment(
inner.text.clone().as_str(), inner.text.clone().as_str(),
Point::new( 20, 50), Point::new(20, 50),
MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK), MonoTextStyle::new(&FONT_10X20, Rgb888::BLACK),
Alignment::Left Alignment::Left,
).draw(&mut inner.graphic); )
.draw(&mut inner.graphic);
} }
fn add(&self, comp: Arc<dyn Component>) { fn add(&self, comp: Arc<dyn Component>) {

View File

@ -27,17 +27,17 @@ const SYSCALL_CONDVAR_SIGNAL: usize = 1031;
const SYSCALL_CONDVAR_WAIT: usize = 1032; const SYSCALL_CONDVAR_WAIT: usize = 1032;
const SYSCALL_CREATE_DESKTOP: usize = 2000; const SYSCALL_CREATE_DESKTOP: usize = 2000;
mod fs; mod fs;
mod gui;
mod process; mod process;
mod sync; mod sync;
mod thread; mod thread;
mod gui;
pub use self::gui::create_desktop;
use fs::*; use fs::*;
pub use gui::PAD;
use process::*; use process::*;
use sync::*; use sync::*;
use thread::*; use thread::*;
pub use gui::PAD;
pub use self::gui::create_desktop;
pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize { pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
match syscall_id { match syscall_id {