forked from capy-ui/capy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
136 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
const std = @import("std"); | ||
const shared = @import("../shared.zig"); | ||
const lib = @import("../../main.zig"); | ||
|
||
const EventFunctions = shared.EventFunctions(@This()); | ||
const EventType = shared.BackendEventType; | ||
const BackendError = shared.BackendError; | ||
const MouseButton = shared.MouseButton; | ||
//pub const PeerType = *c.GtkWidget; | ||
pub const PeerType = *opaque {}; | ||
|
||
var activeWindows = std.atomic.Atomic(usize).init(0); | ||
var hasInit: bool = false; | ||
|
||
pub fn init() BackendError!void { | ||
if (!hasInit) { | ||
hasInit = true; | ||
} | ||
} | ||
|
||
pub fn showNativeMessageDialog(msgType: shared.MessageType, comptime fmt: []const u8, args: anytype) void { | ||
const msg = std.fmt.allocPrintZ(lib.internal.scratch_allocator, fmt, args) catch { | ||
std.log.err("Could not launch message dialog, original text: " ++ fmt, args); | ||
return; | ||
}; | ||
defer lib.internal.scratch_allocator.free(msg); | ||
_ = msgType; | ||
@panic("TODO: message dialogs on Android"); | ||
} | ||
|
||
/// user data used for handling events | ||
pub const EventUserData = struct { | ||
user: EventFunctions = .{}, | ||
class: EventFunctions = .{}, | ||
userdata: usize = 0, | ||
classUserdata: usize = 0, | ||
peer: PeerType, | ||
focusOnClick: bool = false, | ||
}; | ||
|
||
pub inline fn getEventUserData(peer: PeerType) *EventUserData { | ||
_ = peer; | ||
//return @ptrCast(*EventUserData, @alignCast(@alignOf(EventUserData), c.g_object_get_data(@ptrCast(*c.GObject, peer), "eventUserData").?)); | ||
} | ||
|
||
pub fn Events(comptime T: type) type { | ||
_ = T; | ||
return struct {}; | ||
} | ||
|
||
pub const Window = struct { | ||
source_dpi: u32 = 96, | ||
scale: f32 = 1.0, | ||
|
||
pub usingnamespace Events(Window); | ||
|
||
pub fn create() BackendError!Window { | ||
return Window{}; | ||
} | ||
|
||
pub fn resize(self: *Window, width: c_int, height: c_int) void { | ||
_ = self; | ||
_ = width; | ||
_ = height; | ||
} | ||
|
||
pub fn setTitle(self: *Window, title: [*:0]const u8) void { | ||
_ = self; | ||
_ = title; | ||
} | ||
|
||
pub fn setChild(self: *Window, peer: ?PeerType) void { | ||
_ = self; | ||
_ = peer; | ||
} | ||
|
||
pub fn setSourceDpi(self: *Window, dpi: u32) void { | ||
self.source_dpi = 96; | ||
// TODO | ||
const resolution = @as(f32, 96.0); | ||
self.scale = resolution / @intToFloat(f32, dpi); | ||
} | ||
|
||
pub fn show(self: *Window) void { | ||
_ = self; | ||
_ = activeWindows.fetchAdd(1, .Release); | ||
} | ||
|
||
pub fn close(self: *Window) void { | ||
_ = self; | ||
@panic("TODO: close window"); | ||
} | ||
}; | ||
|
||
pub fn postEmptyEvent() void { | ||
@panic("TODO: postEmptyEvent"); | ||
} | ||
|
||
pub fn runStep(step: shared.EventLoopStep) bool { | ||
_ = step; | ||
return activeWindows.load(.Acquire) != 0; | ||
} | ||
|
||
pub const backendExport = struct { | ||
pub fn panic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { | ||
_ = msg; | ||
|
||
@breakpoint(); | ||
unreachable; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters