apprt/gtk: nested splits are good

This commit is contained in:
Mitchell Hashimoto
2023-11-02 11:00:01 -07:00
parent 4c1300ab69
commit 17445a7d87
2 changed files with 16 additions and 23 deletions

View File

@ -87,6 +87,9 @@ pub fn init(
// Update our children so that our GL area is properly // Update our children so that our GL area is properly
// added to the paned. // added to the paned.
self.updateChildren(); self.updateChildren();
// The new surface should always grab focus
surface.grabFocus();
} }
/// Focus on first Surface that can be found in given position. If there's a /// Focus on first Surface that can be found in given position. If there's a
@ -199,8 +202,19 @@ pub fn replace(
// Update our paned children. This will reset the divider // Update our paned children. This will reset the divider
// position but we want to keep it in place so save and restore it. // position but we want to keep it in place so save and restore it.
const pos = c.gtk_paned_get_position(self.paned); const pos = c.gtk_paned_get_position(self.paned);
self.updateChildren(); defer c.gtk_paned_set_position(self.paned, pos);
c.gtk_paned_set_position(self.paned, pos);
if (ptr == &self.top_left) {
c.gtk_paned_set_start_child(
@ptrCast(self.paned),
self.top_left.widget(),
);
} else {
c.gtk_paned_set_end_child(
@ptrCast(self.paned),
self.bottom_right.widget(),
);
}
} }
/// Update the paned children to represent the current state. /// Update the paned children to represent the current state.

View File

@ -159,27 +159,6 @@ pub fn deinit(self: *Tab) void {
} }
} }
/// Splits the current child surface into a Paned in given direction. Child of
/// Tab must be a Surface.
pub fn splitSurface(self: *Tab, direction: input.SplitDirection) !void {
assert(self.child == .surface);
const surface = switch (self.child) {
.surface => |s| s,
else => unreachable,
};
self.removeChild();
// Create a Paned with two Surfaces.
const paned = try Paned.create(self.window.app.core_app.alloc, surface, direction);
// Add Paned to the Tab.
self.setChild(.{ .paned = paned });
// Focus on new surface
paned.focusFirstSurfaceInPosition(.end);
}
/// Remove the current child from the Tab. Noop if no child set. /// Remove the current child from the Tab. Noop if no child set.
pub fn removeChild(self: *Tab) void { pub fn removeChild(self: *Tab) void {
const widget = self.child.widget() orelse return; const widget = self.child.widget() orelse return;