centering in bbox

This commit is contained in:
Thomas Breloff 2016-08-31 11:56:20 -04:00
parent 6e3de26477
commit 03a228fbe7

View File

@ -113,9 +113,11 @@ function bbox(x, y, w, h, oarg1::Symbol, originargs::Symbol...)
orighor = :left orighor = :left
origver = :top origver = :top
for oarg in oargs for oarg in oargs
if oarg in (:left, :right) if oarg == :center
orighor = origver = oarg
elseif oarg in (:left, :right, :hcenter)
orighor = oarg orighor = oarg
elseif oarg in (:top, :bottom) elseif oarg in (:top, :bottom, :vcenter)
origver = oarg origver = oarg
else else
warn("Unused origin arg in bbox construction: $oarg") warn("Unused origin arg in bbox construction: $oarg")
@ -132,11 +134,15 @@ function bbox(x, y, width, height; h_anchor = :left, v_anchor = :top)
height = make_measure_vert(height) height = make_measure_vert(height)
left = if h_anchor == :left left = if h_anchor == :left
x x
elseif h_anchor in (:center, :hcenter)
0.5w - 0.5width + x
else else
1w - x - width 1w - x - width
end end
top = if v_anchor == :top top = if v_anchor == :top
y y
elseif v_anchor in (:center, :vcenter)
0.5h - 0.5height + y
else else
1h - y - height 1h - y - height
end end