Skip to content
Snippets Groups Projects
Commit 6d122cf9 authored by DarkGod's avatar DarkGod
Browse files

Merge branch 'uifix' into 'master'

Fix UI left, right, etc. calculations

While working on statusbox, I've discovered that:
- absolutely everything dependent adds self.ix, self.iy twice. or thrice. this was masking top= bug, for example.
- right=ui sets right to ui.x, which usually sets an object flying to the opposite side of the dialog,
- top=ui sets top edge to be equal to the top edge of the ui, which is probably not what's desired (see left=)
- bottom=ui has similar problem to right,
- hcenter=ui sends a ui element flying half a dialog width to the right,
- vcenter=ui, likewise,
- and hcenter_left=ui I didn't understand what it's supposed to do.

This commit fixes all of the above, sans the last, and also adds 3 pixels of padding between everything to compensate for buggy yet sometimes desired previous results.
parents 08f7300e daf37876
No related branches found
No related tags found
No related merge requests found
......@@ -384,6 +384,8 @@ end
function _M:setupUI(resizex, resizey, on_resize, addmw, addmh)
local mw, mh = nil, nil
local padding = 3 -- to not glue stuff to each other
-- resizex, resizey = true, true
if resizex or resizey then
mw, mh = 0, 0
......@@ -427,24 +429,36 @@ function _M:setupUI(resizex, resizey, on_resize, addmw, addmh)
ux, uy = self.ix, self.iy
if ui.top then
if type(ui.top) == "table" then ui.top = self.ui_by_ui[ui.top].y end
if type(ui.top) == "table" then ui.top = self.ui_by_ui[ui.top].y - self.iy + ui.top.h + padding end
uy = uy + ui.top
elseif ui.bottom then
if type(ui.bottom) == "table" then ui.bottom = self.ui_by_ui[ui.bottom].y end
if type(ui.bottom) == "table" then
local top = self.ui_by_ui[ui.bottom].y - self.iy - padding
ui.bottom = self.ih - top - ui.ui.h
end
uy = uy + self.ih - ui.bottom - ui.ui.h
elseif ui.vcenter then
if type(ui.vcenter) == "table" then ui.vcenter = self.ui_by_ui[ui.vcenter].y + ui.vcenter.h end
if type(ui.vcenter) == "table" then
local vcenter = self.ui_by_ui[ui.vcenter].y + ui.vcenter.h
ui.vcenter = = math.floor(vcenter - self.ih / 2)
end
uy = uy + math.floor(self.ih / 2) + ui.vcenter - ui.ui.h / 2
end
if ui.left then
if type(ui.left) == "table" then ui.left = self.ui_by_ui[ui.left].x + ui.left.w end
if type(ui.left) == "table" then ui.left = self.ui_by_ui[ui.left].x - self.ix + ui.left.w + padding end
ux = ux + ui.left
elseif ui.right then
if type(ui.right) == "table" then ui.right = self.ui_by_ui[ui.right].x end
if type(ui.right) == "table" then
local left = self.ui_by_ui[ui.right].x - self.ix - padding
ui.right = self.iw - left - ui.ui.w
end
ux = ux + self.iw - ui.right - ui.ui.w
elseif ui.hcenter then
if type(ui.hcenter) == "table" then ui.hcenter = self.ui_by_ui[ui.hcenter].x + ui.hcenter.w end
if type(ui.hcenter) == "table" then
local hcenter = self.ui_by_ui[ui.hcenter].x - self.ix + ui.hcenter.w / 2
ui.hcenter = math.floor(hcenter - self.iw / 2)
end
ux = ux + math.floor(self.iw / 2) + ui.hcenter - ui.ui.w / 2
elseif ui.hcenter_left then
if type(ui.hcenter_left) == "table" then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment