flipperzero-zig/lib/flipperzero/gui.zig
2024-08-21 19:27:21 -07:00

228 lines
6.3 KiB
Zig

const flipperzero = @import("flipperzero.zig");
const c = flipperzero.c;
pub const Canvas = extern struct {
const Self = @This();
pub fn clear(self: *Self) void {
c.canvas_clear(@ptrCast(self));
}
pub fn drawStr(self: *Self, x: u8, y: u8, str: [*:0]const u8) void {
c.canvas_draw_str(@ptrCast(self), x, y, str);
}
pub fn setFont(self: *Self, font: c.Font) void {
c.canvas_set_font(@ptrCast(self), font);
}
};
pub const Gui = extern struct {
const Self = @This();
pub fn open() *Self {
return @ptrCast(c.furi_record_open(c.RECORD_GUI));
}
pub fn close(self: *Self) void {
_ = self;
c.furi_record_close(c.RECORD_GUI);
}
pub fn addViewPort(self: *Self, view_port: *ViewPort, layer: c.GuiLayer) void {
c.gui_add_view_port(self, view_port, layer);
}
pub fn removeViewPort(self: *Self, view_port: *ViewPort) void {
c.gui_remove_view_port(self, view_port);
}
};
pub const SceneManager = extern struct {
const Self = @This();
pub fn create() *Self {
return @ptrCast(c.scene_manager_alloc());
}
pub fn destroy(self: *Self) void {
c.scene_manager_free(self);
}
pub fn getSceneState(self: *Self, scene_id: u32) u32 {
return c.scene_manager_get_scene_state(self, scene_id);
}
pub fn handleBackEvent(self: *Self) bool {
return c.scene_manager_handle_back_event(self);
}
pub fn handleCustomEvent(self: *Self, custom_event: u32) bool {
return c.scene_manager_handle_custom_event(self, custom_event);
}
pub fn handleTickEvent(self: *Self) void {
c.scene_manager_handle_tick_event(self);
}
pub fn hasPreviousScene(self: *Self, scene_id: u32) bool {
return c.scene_manager_has_previous_scene(self, scene_id);
}
pub fn nextScene(self: *Self, next_scene_id: u32) void {
c.scene_manager_next_scene(self, next_scene_id);
}
pub fn previousScene(self: *Self) bool {
return c.scene_manager_previous_scene(self);
}
pub fn searchAndSwitchToAnotherScene(self: *Self, scene_id: u32) bool {
return c.scene_manager_search_and_switch_to_another_scene(self, scene_id);
}
pub fn searchAndSwitchToPreviousScene(self: *Self, scene_id: u32) bool {
return c.scene_manager_search_and_switch_to_previous_scene(self, scene_id);
}
pub fn searchAndSwitchToPreviousSceneOneOf(self: *Self, scene_ids: *const u32, scene_ids_size: usize) bool {
return c.scene_manager_search_and_switch_to_previous_scene_one_of(self, scene_ids, scene_ids_size);
}
pub fn setSceneState(self: *Self, scene_id: u32, state: u32) void {
c.scene_manager_set_scene_state(self, scene_id, state);
}
pub fn stop(self: *Self) void {
c.scene_manager_stop(self);
}
};
pub const View = extern struct {
const Self = @This();
pub fn create() *Self {
return @ptrCast(c.view_alloc());
}
pub fn allocateModel(self: *Self, type_: c.ViewModelType, size: usize) void {
c.view_allocate_model(self, type_, size);
}
pub fn commitModel(self: *Self, update: bool) void {
c.view_commit_model(self, update);
}
pub fn destroy(self: *Self) void {
c.view_free(self);
}
pub fn freeModel(self: *Self) void {
c.view_free_model(self);
}
pub fn getModel(self: *Self) *anyopaque {
return c.view_get_model(self);
}
};
pub const ViewDispatcher = extern struct {
const Self = @This();
pub fn create() *Self {
return @ptrCast(c.view_dispatcher_alloc());
}
pub fn addView(self: *Self, view_id: u32, view: *View) void {
c.view_dispatcher_add_view(self, view_id, view);
}
pub fn attachToGui(self: *Self, gui: *Gui, type_: c.ViewDispatcherType) void {
c.view_dispatcher_attach_to_gui(self, gui, type_);
}
pub fn enableQueue(self: *Self) void {
c.view_dispatcher_enable_queue(self);
}
pub fn destroy(self: *Self) void {
c.view_dispatcher_free(self);
}
pub fn getEventLoop(self: *Self) *anyopaque {
return c.view_dispatcher_get_event_loop(self);
}
pub fn removeView(self: *Self, view_id: u32) void {
c.view_dispatcher_remove_view(self, view_id);
}
pub fn run(self: *Self) void {
c.view_dispatcher_run(self);
}
pub fn sendCustomEvent(self: *Self, event: u32) void {
c.view_dispatcher_send_custom_event(self, event);
}
pub fn sendToBack(self: *Self) void {
c.view_dispatcher_send_to_back(self);
}
pub fn sendToFront(self: *Self) void {
c.view_dispatcher_send_to_front(self);
}
pub fn setCustomEventCallback(self: *Self, callback: c.ViewDispatcherCustomEventCallback) void {
c.view_dispatcher_set_custom_event_callback(self, callback);
}
pub fn setEventCallbackContext(self: *Self, context: ?*anyopaque) void {
c.view_dispatcher_set_event_callback_context(self, context orelse null);
}
pub fn setNavigationEventCallback(self: *Self, callback: c.ViewDispatcherNavigationEventCallback) void {
c.view_dispatcher_set_navigation_event_callback(self, callback);
}
pub fn setTickEventCallback(self: *Self, callback: c.ViewDispatcherTickEventCallback, tick_period: u32) void {
c.view_dispatcher_set_tick_event_callback(self, callback, tick_period);
}
pub fn stop(self: *Self) void {
c.view_dispatcher_stop(self);
}
pub fn switchToView(self: *Self, view_id: u32) void {
c.view_dispatcher_switch_to_view(self, view_id);
}
};
pub const ViewPort = extern struct {
const Self = @This();
pub fn create() *Self {
return @ptrCast(c.view_port_alloc());
}
pub fn destroy(self: *Self) void {
c.view_port_free(self);
}
pub fn update(self: *Self) void {
c.view_port_update(self);
}
pub fn setDrawCallback(self: *Self, callback: c.ViewPortDrawCallback, context: ?*anyopaque) void {
c.view_port_draw_callback_set(self, callback, context orelse null);
}
pub fn setInputCallback(self: *Self, callback: c.ViewPortInputCallback, context: ?*anyopaque) void {
c.view_port_input_callback_set(self, callback, context orelse null);
}
pub fn setEnabled(self: *Self, enabled: bool) void {
c.view_port_enabled_set(self, enabled);
}
};