mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-24 20:56:08 +03:00
apprt/gtk: stylistic changes
This commit is contained in:
@ -15,7 +15,25 @@ const c = @import("c.zig");
|
||||
|
||||
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
|
||||
paned: *c.GtkPaned,
|
||||
@ -83,10 +101,7 @@ pub fn init(
|
||||
.container = container,
|
||||
.top_left = .{ .surface = sibling },
|
||||
.bottom_right = .{ .surface = surface },
|
||||
.orientation = (switch (direction) {
|
||||
.right => .horizontal,
|
||||
.down => .vertical,
|
||||
}),
|
||||
.orientation = Orientation.fromDirection(direction),
|
||||
};
|
||||
|
||||
// Replace the previous containers element with our split.
|
||||
@ -146,12 +161,14 @@ fn removeChild(
|
||||
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 {
|
||||
const pos = c.gtk_paned_get_position(self.paned);
|
||||
const new = switch (direction) {
|
||||
.up, .left => pos - amount,
|
||||
.down, .right => pos + amount,
|
||||
};
|
||||
|
||||
c.gtk_paned_set_position(self.paned, new);
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,10 @@ pub const Container = union(enum) {
|
||||
|
||||
/// Returns the first split with the given orientation, walking upwards in
|
||||
/// the tree.
|
||||
pub fn firstSplitWithOrientation(self: Container, orientation: Split.Orientation) ?*Split {
|
||||
pub fn firstSplitWithOrientation(
|
||||
self: Container,
|
||||
orientation: Split.Orientation,
|
||||
) ?*Split {
|
||||
return switch (self) {
|
||||
.none, .tab_ => null,
|
||||
.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 {
|
||||
const s = self.container.firstSplitWithOrientation(switch (direction) {
|
||||
.up, .down => .vertical,
|
||||
.left, .right => .horizontal,
|
||||
}) orelse return;
|
||||
const s = self.container.firstSplitWithOrientation(
|
||||
Split.Orientation.fromResizeDirection(direction),
|
||||
) orelse return;
|
||||
s.moveDivider(direction, amount);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user