rubywm/geom.rb

42 lines
773 B
Ruby
Raw Normal View History

2024-01-03 06:12:18 +01:00
module X11
module Form
class Geometry
def inspect = "<Geometry x=#{x.to_i} y=#{y.to_i} width=#{width.to_i} height=#{height.to_i}>"
end
end
end
2024-01-03 06:12:18 +01:00
def gap(geom,g)
geom = geom.dup
geom.x += g
geom.width -= g*2
geom.y += g
geom.height -= g*2
geom
end
2024-01-14 22:09:00 +01:00
def split_geom(geom, dir, node, gap, ratio)
2024-01-03 06:12:18 +01:00
geom = geom.dup
case dir
when :lr
2024-01-14 22:09:00 +01:00
lw = (geom.width-gap)*ratio
if node == 0
geom.width = lw
else
geom.width = (geom.width-gap)*(1.0-ratio)
geom.x += lw + gap
end
2024-01-03 06:12:18 +01:00
return geom
when :tb
2024-01-14 22:09:00 +01:00
th = (geom.height-gap)*ratio
if node == 0
geom.height = th
else
geom.height = (geom.height-gap)*(1.0-ratio)
geom.y += th + gap
end
2024-01-03 06:12:18 +01:00
return geom
else raise "Invalid direction"
end
end