changed from ints to floats for internal math
This commit is contained in:
37
src/root.zig
37
src/root.zig
@@ -8,7 +8,7 @@ const std = @import("std");
|
||||
|
||||
// sissor
|
||||
pub const VERSON = "0.0.1";
|
||||
pub const Real = i32;
|
||||
pub const Real = f32;
|
||||
const Spaceing = 4;
|
||||
|
||||
pub fn TextType(
|
||||
@@ -207,6 +207,21 @@ pub fn Bamboo(
|
||||
// };
|
||||
// }
|
||||
|
||||
pub inline fn ElementWborder(boarder_width: Padding, boarder_colour: Colour, ele: Ele) Node {
|
||||
return Node{
|
||||
.element = .{
|
||||
.name = ele.name ++ "_boarder",
|
||||
.style = .{
|
||||
.padding = boarder_width,
|
||||
.background_colour = boarder_colour,
|
||||
},
|
||||
.children = &[_]Node{
|
||||
Element(ele),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn Element(ele: Ele) Node {
|
||||
return Node{
|
||||
.element = ele,
|
||||
@@ -431,8 +446,8 @@ pub fn Bamboo(
|
||||
std.debug.print("remaining_width : {d}\n", .{remaining_width});
|
||||
std.debug.print("remaining_hieght : {d}\n", .{remaining_height});
|
||||
|
||||
remaining_width -|= node.element.style.padding.left + node.element.style.padding.right;
|
||||
remaining_height -|= node.element.style.padding.top + node.element.style.padding.bottom;
|
||||
remaining_width -= node.element.style.padding.left + node.element.style.padding.right;
|
||||
remaining_height -= node.element.style.padding.top + node.element.style.padding.bottom;
|
||||
|
||||
if (node.element.children.len == 0) return .{
|
||||
0,
|
||||
@@ -455,11 +470,11 @@ pub fn Bamboo(
|
||||
.texture => {
|
||||
switch (node.element.style.layout) {
|
||||
.top_to_bottom => {
|
||||
remaining_height -|= child.texture.rect.h;
|
||||
remaining_height -= child.texture.rect.h;
|
||||
remaining_width = @max(remaining_width, child.texture.rect.w);
|
||||
},
|
||||
.right_to_left => {
|
||||
remaining_width -|= child.texture.rect.w;
|
||||
remaining_width -= child.texture.rect.w;
|
||||
remaining_height = @max(remaining_height, child.texture.rect.h);
|
||||
},
|
||||
}
|
||||
@@ -469,8 +484,8 @@ pub fn Bamboo(
|
||||
}
|
||||
std.debug.print("remaining_width : {d}\n", .{remaining_width});
|
||||
std.debug.print("remaining_hieght : {d}\n", .{remaining_height});
|
||||
remaining_width -|= (@as(Real, @intCast(node.element.children.len -| 1)) * node.element.style.child_gap);
|
||||
remaining_height -|= (@as(Real, @intCast(node.element.children.len -| 1)) * node.element.style.child_gap);
|
||||
remaining_width -= (@as(Real, @floatFromInt(node.element.children.len -| 1)) * node.element.style.child_gap);
|
||||
remaining_height -= (@as(Real, @floatFromInt(node.element.children.len -| 1)) * node.element.style.child_gap);
|
||||
std.debug.print("remaining_width : {d}\n", .{remaining_width});
|
||||
std.debug.print("remaining_hieght : {d}\n", .{remaining_height});
|
||||
|
||||
@@ -540,8 +555,8 @@ pub fn Bamboo(
|
||||
var find_next_smallest_index: usize = 0;
|
||||
var smallest = filterGrowableChildren(&find_next_smallest_index, node) orelse return;
|
||||
var second_smallest = &Ele{ .rect = .{
|
||||
.h = std.math.maxInt(Real),
|
||||
.w = std.math.maxInt(Real),
|
||||
.h = std.math.floatMax(Real),
|
||||
.w = std.math.floatMax(Real),
|
||||
} };
|
||||
var width_to_add = remaining;
|
||||
var next_smallest_index: usize = 0;
|
||||
@@ -556,7 +571,7 @@ pub fn Bamboo(
|
||||
width_to_add = getAxis(second_smallest) - getAxis(smallest);
|
||||
}
|
||||
}
|
||||
width_to_add = @min(width_to_add, @divTrunc(remaining, @as(Real, @intCast(total_growable))));
|
||||
width_to_add = @min(width_to_add, remaining / @as(Real, @floatFromInt(total_growable)));
|
||||
if (width_to_add == 0) return;
|
||||
var grow_em: usize = 0;
|
||||
std.debug.print("smallest ; {}\n", .{smallest.rect});
|
||||
@@ -566,7 +581,7 @@ pub fn Bamboo(
|
||||
if (getSizing(growable) == .grow)
|
||||
addToAxis(growable, width_to_add);
|
||||
std.debug.print("after growable : {}\n", .{growable.rect});
|
||||
remaining -|= width_to_add;
|
||||
remaining -= width_to_add;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user