pebble_rust/pebble/
window.rs1use crate::pebble::internal::{types, functions::interface};
20use crate::pebble::types::GColor;
21use crate::pebble::WindowPtr;
22use crate::pebble::layer::Layer;
23
24pub struct Window {
25 internal: *mut types::Window
26}
27
28#[derive(Copy, Clone)]
29pub struct WindowHandlers {
30 pub load: extern fn(WindowPtr),
31 pub unload: extern fn(WindowPtr),
32 pub appear: extern fn(WindowPtr),
33 pub disappear: extern fn(WindowPtr)
34}
35
36impl Window {
37 pub fn new() -> Window {
38 Window {
39 internal: interface::window_create()
40 }
41 }
42
43 pub fn from_raw(ptr: WindowPtr) -> Window {
44 Window {
45 internal: ptr
46 }
47 }
48
49 pub fn push(&self, animate: bool) {
50 interface::window_stack_push(self.internal, animate);
51 }
52
53 pub fn set_handlers(&self, handlers: WindowHandlers) {
54 let WindowHandlers {load, unload,
55 appear, disappear} = handlers;
56 let converted = types::WindowHandlers {
57 load, unload, appear, disappear
58 };
59
60 interface::window_set_window_handlers(self.internal, converted);
61 }
62
63 pub fn set_background_color(&self, color: GColor) {
64 interface::window_set_background_color(self.internal, color);
65 }
66
67 pub fn get_root_layer(&self) -> Layer {
68 let layer_ptr = interface::window_get_root_layer(self.internal);
69 Layer::from_raw(layer_ptr)
70 }
71
72 pub fn clean_exit(&self) {
73 interface::window_destroy(self.internal);
74 }
75}