feat: scrap platform backevents
Backevents are no longer sent to the platform event loop. Instead, a user must implement a custom widget to handle backevents. The advantage of this is that the existance of the widget is still guaranteed at the time the event is handled. Also, this removes some pointless need to data allocation in most backend implementations. We should think about an alternative, cross-platform API that still allows the user to utlilize the platform's event loop somehow.
This commit is contained in:
parent
80209aceac
commit
1862a0e3fe
|
@ -19,15 +19,27 @@ const Widget = @import("widget.zig").Widget;
|
|||
fn Prototype(comptime Self: type) type {
|
||||
std.debug.assert(Self == Backevent);
|
||||
return struct {
|
||||
//! Propagates this backevent up the widget tree. If the current (given) Widget has a parent,
|
||||
//! the event is propagated to it. Otherwise, it is pushed to the platform event loop.
|
||||
//! Widgets should call this in their backevent handler if they do not wish to modify or
|
||||
//! intercept the backevent.
|
||||
/// Called if the Backevent made it's way up the widget tree without being intercepted.
|
||||
/// The root widget will be passed.
|
||||
pub fn unhandled(self: Self, root: *Widget) !void {
|
||||
try (statspatch.implcallOptional(
|
||||
self,
|
||||
.self,
|
||||
"unhandled",
|
||||
anyerror!void,
|
||||
.{ self, root },
|
||||
) orelse {});
|
||||
}
|
||||
|
||||
/// Propagates this backevent up the widget tree. If the current (given) Widget has a parent,
|
||||
/// the event is propagated to it. Otherwise, the backevent's unhandled handler is called.
|
||||
/// Widgets should call this in their backevent handler if they do not wish to modify or
|
||||
/// intercept the backevent.
|
||||
pub fn dispatch(self: Self, widget: *Widget) anyerror!void {
|
||||
if (widget.data.parent) |p| {
|
||||
try p.backevent(self);
|
||||
} else {
|
||||
try widget.data.platform.?.pushBackevent(self);
|
||||
try self.unhandled(widget);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//! The platform is the main interface to be implemnted by backends. It's responsible for driving
|
||||
//! the GUI by sending treevents, handling system events and rendering the GUI.
|
||||
//! the GUI by sending treevents and rendering the GUI.
|
||||
const std = @import("std");
|
||||
const statspatch = @import("statspatch");
|
||||
|
||||
|
@ -10,14 +10,7 @@ const Backevent = @import("backevent.zig").Backevent;
|
|||
fn Prototype(comptime Self: type) type {
|
||||
std.debug.assert(Self == Platform);
|
||||
|
||||
return struct {
|
||||
//! Pushes a backevent to the platform's event loop.
|
||||
//! These should make their way back to the user code, how exactly depende on the Platform's
|
||||
//! API. This function must be threadsafe!
|
||||
pub fn pushBackevent(self: *Self, ev: Backevent) !void {
|
||||
try statspatch.implcall(self, .ptr, "pushBackevent", anyerror!void, .{ev});
|
||||
}
|
||||
};
|
||||
return struct {};
|
||||
}
|
||||
|
||||
pub const Platform = statspatch.StatspatchType(Prototype, void, &zenolith.platform_impls);
|
||||
|
|
Loading…
Reference in a new issue