Skip to content

Commit 58cbf84

Browse files
committed
browser-rs: add gui.rs
1 parent 079f43a commit 58cbf84

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

app/browser-rs/src/gui.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use alloc::string::String;
2+
use liumlib::gui::*;
3+
use liumlib::*;
4+
5+
#[derive(Debug, Clone)]
6+
pub struct ApplicationWindow {
7+
width: u64,
8+
height: u64,
9+
title: String,
10+
buffer: WindowBuffer,
11+
}
12+
13+
impl ApplicationWindow {
14+
pub fn new(w: u64, h: u64, title: String) -> Self {
15+
let window_buffer = match create_window(w as usize, h as usize) {
16+
Err(_) => panic!("Failed to create window"),
17+
Ok(w) => w,
18+
};
19+
20+
Self {
21+
width: w,
22+
height: h,
23+
title,
24+
buffer: window_buffer,
25+
}
26+
}
27+
28+
pub fn initialize(&mut self) {
29+
match draw_rect(
30+
&self.buffer,
31+
0xffffff,
32+
0,
33+
0,
34+
self.width as i64,
35+
self.height as i64,
36+
) {
37+
Ok(()) => {}
38+
Err(e) => println!("{}", e),
39+
};
40+
self.buffer.flush();
41+
}
42+
}

app/browser-rs/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
extern crate alloc;
44

5+
pub mod gui;
56
pub mod http;
67
pub mod net;
78
pub mod renderer;

app/browser-rs/src/main.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![no_std]
22
#![no_main]
33

4+
mod gui;
45
mod http;
56
mod net;
67
mod renderer;
@@ -9,32 +10,33 @@ mod url;
910
extern crate alloc;
1011

1112
use alloc::string::ToString;
13+
use liumlib::gui::*;
1214
use liumlib::*;
1315

16+
use crate::gui::ApplicationWindow;
1417
use crate::net::udp_response;
1518
use crate::renderer::render;
1619
use crate::url::ParsedUrl;
1720

1821
fn help_message() {
1922
println!("Usage: browser-rs.bin [ OPTIONS ]");
2023
println!(" -u, --url URL. Default: http://127.0.0.1:8888/index.html");
24+
println!(" -h, --help Show this help message.");
2125
exit(0);
2226
}
2327

2428
entry_point!(main);
2529
fn main() {
2630
let mut url = "http://127.0.0.1:8888/index.html";
2731

28-
let help_flag = "--help".to_string();
29-
let url_flag = "--url".to_string();
30-
3132
let args = env::args();
3233
for i in 1..args.len() {
33-
if help_flag == args[i] {
34+
if "--help".to_string() == args[i] || "-h" == args[i] {
3435
help_message();
36+
return;
3537
}
3638

37-
if url_flag == args[i] {
39+
if "--url".to_string() == args[i] || "-u".to_string() == args[i] {
3840
if i + 1 >= args.len() {
3941
help_message();
4042
}
@@ -44,6 +46,8 @@ fn main() {
4446

4547
let parsed_url = ParsedUrl::new(url.to_string());
4648

49+
let _app = ApplicationWindow::new(512, 256, "my browser".to_string()).initialize();
50+
4751
let response = udp_response(&parsed_url);
4852

4953
println!("----- receiving a response -----");

app/liumlib/src/gui.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub struct BMPInfoV3Header {
3434
pub b_mask: u32,
3535
}
3636

37+
#[derive(Debug, Clone)]
3738
pub struct WindowBuffer {
3839
file_buf: *mut u8,
3940
file_size: usize,

0 commit comments

Comments
 (0)