style: Make start/end_window_draw safe and Size struct for define window
This commit is contained in:
parent
3ce36749a5
commit
447bb48501
@ -3,34 +3,35 @@
|
|||||||
|
|
||||||
use cstr_core::{cstr, CStr};
|
use cstr_core::{cstr, CStr};
|
||||||
|
|
||||||
use kos::{Color, Dot, Event, WindowKind, WindowParams, WindowTextParams};
|
use kos::{Color, Dot, Event, Size, WindowKind, WindowParams, WindowTextParams};
|
||||||
|
|
||||||
const HEADER: &CStr = cstr!("Hey Kolibri");
|
const HEADER: &CStr = cstr!("Hey Kolibri");
|
||||||
const MSG: &str = "Hello from Rust!";
|
const MSG: &str = "Hello from Rust!";
|
||||||
|
|
||||||
#[inline(always)] // for some reason function removed otherwise
|
#[inline(always)] // for some reason function removed otherwise
|
||||||
fn draw_window() {
|
fn draw_window() {
|
||||||
unsafe {
|
kos::start_window_draw();
|
||||||
kos::start_window_draw();
|
kos::define_window(
|
||||||
kos::define_window(
|
Dot { x: 50, y: 50 },
|
||||||
Dot { x: 50, y: 50 },
|
Size {
|
||||||
300, 400,
|
width: 300,
|
||||||
WindowParams {
|
height: 400,
|
||||||
color: Color::rgb(0xff, 0xff, 0xff),
|
},
|
||||||
kind: WindowKind::Themed,
|
WindowParams {
|
||||||
title: Some(HEADER),
|
color: Color::rgb(0xff, 0xff, 0xff),
|
||||||
},
|
kind: WindowKind::Themed,
|
||||||
);
|
title: Some(HEADER),
|
||||||
kos::display_message(
|
},
|
||||||
Dot { x: 0, y: 10 },
|
);
|
||||||
WindowTextParams {
|
kos::display_message(
|
||||||
color: Color::rgb(0x66, 0x22, 0x22),
|
Dot { x: 0, y: 10 },
|
||||||
text: MSG,
|
WindowTextParams {
|
||||||
bg_color: None,
|
color: Color::rgb(0x66, 0x22, 0x22),
|
||||||
},
|
text: MSG,
|
||||||
);
|
bg_color: None,
|
||||||
kos::end_window_draw();
|
},
|
||||||
}
|
);
|
||||||
|
kos::end_window_draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
19
src/lib.rs
19
src/lib.rs
@ -35,6 +35,11 @@ pub struct Dot {
|
|||||||
pub y: u32,
|
pub y: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Size {
|
||||||
|
pub width: u32,
|
||||||
|
pub height: u32,
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
pub enum WindowKind {
|
pub enum WindowKind {
|
||||||
Fixed = 0,
|
Fixed = 0,
|
||||||
@ -50,13 +55,13 @@ pub struct WindowParams<'a> {
|
|||||||
pub title: Option<&'a cstr_core::CStr>,
|
pub title: Option<&'a cstr_core::CStr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn define_window(start: Dot, width: u32, height: u32, params: WindowParams<'_>) {
|
pub fn define_window(start: Dot, size: Size, params: WindowParams<'_>) {
|
||||||
const RELATIVE_FLAG: u32 = 0x20;
|
const RELATIVE_FLAG: u32 = 0x20;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
sys::define_window(
|
sys::define_window(
|
||||||
start.x * 65536 + width,
|
start.x * 65536 + size.width,
|
||||||
start.y * 65536 + height,
|
start.y * 65536 + size.height,
|
||||||
params.color.as_rgb_val()
|
params.color.as_rgb_val()
|
||||||
| (RELATIVE_FLAG | (params.title.is_some() as u32) << 4 | params.kind as u32) << 24,
|
| (RELATIVE_FLAG | (params.title.is_some() as u32) << 4 | params.kind as u32) << 24,
|
||||||
0,
|
0,
|
||||||
@ -93,6 +98,14 @@ pub fn exit() -> ! {
|
|||||||
unsafe { sys::exit() }
|
unsafe { sys::exit() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn start_window_draw() {
|
||||||
|
unsafe { sys::start_window_draw() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn end_window_draw() {
|
||||||
|
unsafe { sys::end_window_draw() }
|
||||||
|
}
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||||
exit();
|
exit();
|
||||||
|
Loading…
Reference in New Issue
Block a user