apprt/gtk: stylistic changes

This commit is contained in:
Mitchell Hashimoto
2023-12-06 20:53:32 -08:00
parent 40e239bf7a
commit 3c4bd47de3
2 changed files with 29 additions and 10 deletions

View File

@ -15,7 +15,25 @@ const c = @import("c.zig");
const log = std.log.scoped(.gtk); const log = std.log.scoped(.gtk);
pub const Orientation = enum { horizontal, vertical }; /// The split orientation.
pub const Orientation = enum {
horizontal,
vertical,
pub fn fromDirection(direction: input.SplitDirection) Orientation {
return switch (direction) {
.right => .horizontal,
.down => .vertical,
};
}
pub fn fromResizeDirection(direction: input.SplitResizeDirection) Orientation {
return switch (direction) {
.up, .down => .vertical,
.left, .right => .horizontal,
};
}
};
/// Our actual GtkPaned widget /// Our actual GtkPaned widget
paned: *c.GtkPaned, paned: *c.GtkPaned,
@ -83,10 +101,7 @@ pub fn init(
.container = container, .container = container,
.top_left = .{ .surface = sibling }, .top_left = .{ .surface = sibling },
.bottom_right = .{ .surface = surface }, .bottom_right = .{ .surface = surface },
.orientation = (switch (direction) { .orientation = Orientation.fromDirection(direction),
.right => .horizontal,
.down => .vertical,
}),
}; };
// Replace the previous containers element with our split. // Replace the previous containers element with our split.
@ -146,12 +161,14 @@ fn removeChild(
alloc.destroy(self); alloc.destroy(self);
} }
/// Move the divider in the given direction by the given amount.
pub fn moveDivider(self: *Split, direction: input.SplitResizeDirection, amount: u16) void { pub fn moveDivider(self: *Split, direction: input.SplitResizeDirection, amount: u16) void {
const pos = c.gtk_paned_get_position(self.paned); const pos = c.gtk_paned_get_position(self.paned);
const new = switch (direction) { const new = switch (direction) {
.up, .left => pos - amount, .up, .left => pos - amount,
.down, .right => pos + amount, .down, .right => pos + amount,
}; };
c.gtk_paned_set_position(self.paned, new); c.gtk_paned_set_position(self.paned, new);
} }

View File

@ -153,7 +153,10 @@ pub const Container = union(enum) {
/// Returns the first split with the given orientation, walking upwards in /// Returns the first split with the given orientation, walking upwards in
/// the tree. /// the tree.
pub fn firstSplitWithOrientation(self: Container, orientation: Split.Orientation) ?*Split { pub fn firstSplitWithOrientation(
self: Container,
orientation: Split.Orientation,
) ?*Split {
return switch (self) { return switch (self) {
.none, .tab_ => null, .none, .tab_ => null,
.split_tl, .split_br => split: { .split_tl, .split_br => split: {
@ -573,10 +576,9 @@ pub fn gotoSplit(self: *const Surface, direction: input.SplitFocusDirection) voi
} }
pub fn resizeSplit(self: *const Surface, direction: input.SplitResizeDirection, amount: u16) void { pub fn resizeSplit(self: *const Surface, direction: input.SplitResizeDirection, amount: u16) void {
const s = self.container.firstSplitWithOrientation(switch (direction) { const s = self.container.firstSplitWithOrientation(
.up, .down => .vertical, Split.Orientation.fromResizeDirection(direction),
.left, .right => .horizontal, ) orelse return;
}) orelse return;
s.moveDivider(direction, amount); s.moveDivider(direction, amount);
} }