mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 01:16:26 +04:00
cargo fmt
This commit is contained in:
parent
f4a7714fe0
commit
58096b08d6
@ -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) {}
|
||||
}
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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::*;
|
||||
pub use input::*;
|
||||
|
@ -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};
|
||||
|
@ -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<ButtonInner>
|
||||
inner: UPIntrFreeCell<ButtonInner>,
|
||||
}
|
||||
|
||||
pub struct ButtonInner {
|
||||
graphic: Graphics,
|
||||
text: String,
|
||||
parent: Option<Arc<dyn Component>>
|
||||
parent: Option<Arc<dyn Component>>,
|
||||
}
|
||||
|
||||
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 {
|
||||
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<dyn Component>) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ impl Graphics {
|
||||
Self {
|
||||
size,
|
||||
point,
|
||||
drv: GPU_DEVICE.clone()
|
||||
drv: GPU_DEVICE.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<IconControllerInner>
|
||||
inner: UPIntrFreeCell<IconControllerInner>,
|
||||
}
|
||||
|
||||
pub struct IconControllerInner {
|
||||
files: Vec<String>,
|
||||
graphic: Graphics,
|
||||
parent: Option<Arc<dyn Component>>
|
||||
parent: Option<Arc<dyn Component>>,
|
||||
}
|
||||
|
||||
impl IconController {
|
||||
pub fn new(files: Vec<String>,parent: Option<Arc<dyn Component>>) -> Self {
|
||||
IconController {
|
||||
pub fn new(files: Vec<String>, parent: Option<Arc<dyn Component>>) -> 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::<Rgb888>::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!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<ImageInner>,
|
||||
}
|
||||
|
||||
pub struct ImageInner {
|
||||
image: &'static [u8],
|
||||
graphic: Graphics,
|
||||
parent: Option<Arc<dyn Component>>
|
||||
parent: Option<Arc<dyn Component>>,
|
||||
}
|
||||
|
||||
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 {
|
||||
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::<Rgb888>::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<dyn Component>) {
|
||||
|
@ -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);
|
||||
|
@ -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},
|
||||
|
@ -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<TerminalInner>
|
||||
inner: UPIntrFreeCell<TerminalInner>,
|
||||
}
|
||||
|
||||
pub struct TerminalInner {
|
||||
pub text: String,
|
||||
titel:Option<String>,
|
||||
titel: Option<String>,
|
||||
graphic: Graphics,
|
||||
comps: VecDeque<Arc<dyn Component>>,
|
||||
}
|
||||
|
||||
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 {
|
||||
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<dyn Component>) {
|
||||
@ -86,4 +102,4 @@ impl Component for Terminal {
|
||||
let inner = self.inner.exclusive_access();
|
||||
(inner.graphic.size, inner.graphic.point)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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};
|
||||
pub use up::{UPIntrFreeCell, UPIntrRefMut};
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user