gtk: use f64 everywhere instead of i16/f16/c_int

This commit is contained in:
Thorsten Ball
2023-12-13 05:38:34 +01:00
parent e67fa7abe0
commit 47b0592c73
2 changed files with 6 additions and 9 deletions

View File

@ -178,27 +178,24 @@ pub fn moveDivider(self: *Split, direction: input.SplitResizeDirection, amount:
/// It works recursively by equalizing the children of each split. /// It works recursively by equalizing the children of each split.
/// ///
/// It returns this split's weight. /// It returns this split's weight.
pub fn equalize(self: *Split) i16 { pub fn equalize(self: *Split) f64 {
// Calculate weights of top_left/bottom_right // Calculate weights of top_left/bottom_right
const top_left_weight = self.top_left.equalize(); const top_left_weight = self.top_left.equalize();
const bottom_right_weight = self.bottom_right.equalize(); const bottom_right_weight = self.bottom_right.equalize();
const weight = top_left_weight + bottom_right_weight; const weight = top_left_weight + bottom_right_weight;
// Ratio of top_left weight to overall weight, which gives the split ratio // Ratio of top_left weight to overall weight, which gives the split ratio
const ratio = @as(f16, @floatFromInt(top_left_weight)) / @as(f16, @floatFromInt(weight)); const ratio = top_left_weight / weight;
// Convert split ratio into new position for divider // Convert split ratio into new position for divider
const max: f16 = @floatFromInt(self.maxPosition()); c.gtk_paned_set_position(self.paned, @intFromFloat(self.maxPosition() * ratio));
const new: c_int = @intFromFloat(max * ratio);
c.gtk_paned_set_position(self.paned, new);
return weight; return weight;
} }
// maxPosition returns the maximum position of the GtkPaned, which is the // maxPosition returns the maximum position of the GtkPaned, which is the
// "max-position" attribute. // "max-position" attribute.
fn maxPosition(self: *Split) c_int { fn maxPosition(self: *Split) f64 {
var value: c.GValue = std.mem.zeroes(c.GValue); var value: c.GValue = std.mem.zeroes(c.GValue);
defer c.g_value_unset(&value); defer c.g_value_unset(&value);
@ -209,7 +206,7 @@ fn maxPosition(self: *Split) c_int {
&value, &value,
); );
return c.g_value_get_int(&value); return @floatFromInt(c.g_value_get_int(&value));
} }
// This replaces the element at the given pointer with a new element. // This replaces the element at the given pointer with a new element.

View File

@ -96,7 +96,7 @@ pub const Container = union(enum) {
} }
} }
pub fn equalize(self: Elem) i16 { pub fn equalize(self: Elem) f64 {
return switch (self) { return switch (self) {
.surface => 1, .surface => 1,
.split => |s| s.equalize(), .split => |s| s.equalize(),