apprt/gtk-ng: write back split ratio to tree

This commit is contained in:
Mitchell Hashimoto
2025-08-09 12:19:03 -07:00
parent e396d9d78d
commit 34be4de018
2 changed files with 49 additions and 15 deletions

View File

@@ -174,6 +174,27 @@ pub fn SplitTree(comptime V: type) type {
}
};
/// Resize the given node in place. The node MUST be a split (asserted).
///
/// In general, this is an immutable data structure so this is
/// heavily discouraged. However, this is provided for convenience
/// and performance reasons where its very important for GUIs to
/// update the ratio during a live resize than to redraw the entire
/// widget tree.
pub fn resizeInPlace(
self: *Self,
at: Node.Handle,
ratio: f16,
) void {
// Let's talk about this constCast. Our member are const but
// we actually always own their memory. We don't want consumers
// who directly access the nodes to be able to modify them
// (without nasty stuff like this), but given this is internal
// usage its perfectly fine to modify the node in-place.
const s: *Split = @constCast(&self.nodes[at].split);
s.ratio = ratio;
}
/// Insert another tree into this tree at the given node in the
/// specified direction. The other tree will be inserted in the
/// new direction. For example, if the direction is "right" then