1
0
forked from Rust/Core

style: Make start/end_window_draw safe and Size struct for define window

This commit is contained in:
Gleb Zaharov 2024-01-11 20:01:27 +03:00
parent 3ce36749a5
commit 447bb48501
2 changed files with 39 additions and 25 deletions

View File

@ -3,34 +3,35 @@
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 MSG: &str = "Hello from Rust!";
#[inline(always)] // for some reason function removed otherwise
fn draw_window() {
unsafe {
kos::start_window_draw();
kos::define_window(
Dot { x: 50, y: 50 },
300, 400,
WindowParams {
color: Color::rgb(0xff, 0xff, 0xff),
kind: WindowKind::Themed,
title: Some(HEADER),
},
);
kos::display_message(
Dot { x: 0, y: 10 },
WindowTextParams {
color: Color::rgb(0x66, 0x22, 0x22),
text: MSG,
bg_color: None,
},
);
kos::end_window_draw();
}
kos::start_window_draw();
kos::define_window(
Dot { x: 50, y: 50 },
Size {
width: 300,
height: 400,
},
WindowParams {
color: Color::rgb(0xff, 0xff, 0xff),
kind: WindowKind::Themed,
title: Some(HEADER),
},
);
kos::display_message(
Dot { x: 0, y: 10 },
WindowTextParams {
color: Color::rgb(0x66, 0x22, 0x22),
text: MSG,
bg_color: None,
},
);
kos::end_window_draw();
}
#[no_mangle]

View File

@ -35,6 +35,11 @@ pub struct Dot {
pub y: u32,
}
pub struct Size {
pub width: u32,
pub height: u32,
}
#[repr(u32)]
pub enum WindowKind {
Fixed = 0,
@ -50,13 +55,13 @@ pub struct WindowParams<'a> {
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;
unsafe {
sys::define_window(
start.x * 65536 + width,
start.y * 65536 + height,
start.x * 65536 + size.width,
start.y * 65536 + size.height,
params.color.as_rgb_val()
| (RELATIVE_FLAG | (params.title.is_some() as u32) << 4 | params.kind as u32) << 24,
0,
@ -93,6 +98,14 @@ pub fn 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]
fn panic(_info: &core::panic::PanicInfo) -> ! {
exit();