Skip to content

Commit

Permalink
TouchMenu: keep hamburger menu on the right
Browse files Browse the repository at this point in the history
  • Loading branch information
Frenzie committed Mar 26, 2017
1 parent f22dceb commit d1cbbb0
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions frontend/ui/widget/touchmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ function TouchMenuBar:init()
-- we asign negative here to offset it in the loop
local start_seg = -icon_sep_width
local end_seg = start_seg
-- self.width is the screen width
-- content_width is the width of the icons
-- (math.min(spacing_width, Screen:scaleBySize(20)) * #self.icons *2) is the combined width of spacing/separators
local stretch_width = self.width - content_width - (math.min(spacing_width, Screen:scaleBySize(20)) * #self.icons * 2) + icon_sep_width


for k, v in ipairs(self.icons) do
local ib = IconButton:new{
show_parent = self.show_parent,
Expand Down Expand Up @@ -207,7 +213,10 @@ function TouchMenuBar:init()
h = self.height,
}
}
table.insert(self.icon_seps, icon_sep)
-- no separator on the right
if k < #self.icons then
table.insert(self.icon_seps, icon_sep)
end

-- callback to set visual style
ib.callback = function()
Expand All @@ -217,15 +226,44 @@ function TouchMenuBar:init()
}
}
for i, sep in ipairs(self.icon_seps) do
local current_icon = i == k - 1 or i == k
self.icon_seps[i].style = current_icon and "solid" or "none"
local current_icon = (i == k - 1 or i == k) and k ~= #self.icons
local last_icon = i == k and k == #self.icons
sep.style = current_icon and "solid" or "none"

-- if this is last icon then the empty bar segment has to move over to the right
-- by the width of a separator and the stretch width
if last_icon then
self.bar_sep.empty_segments = {
{
s = icon_sep_width + stretch_width + _start_seg, e = icon_sep_width + stretch_width + _end_seg
}
}
self.icon_seps[i].style = "solid"
end
end
self.menu:switchMenuTab(k)
end

table.insert(self.bar_icon_group, self.icon_widgets[k])
table.insert(self.bar_icon_group, icon_sep)

-- if we're at the before-last icon, add an extra span and the final separator
if k == #self.icons - 1 then
table.insert(self.bar_icon_group, HorizontalSpan:new{
width = stretch_width
})
-- need to create a new LineWidget otherwise it's just a reference to the same instance
local icon_sep_duplicate = LineWidget:new{
style = "none",
dimen = Geom:new{
w = icon_sep_width,
h = self.height,
}
}
table.insert(self.icon_seps, icon_sep_duplicate)
table.insert(self.bar_icon_group, icon_sep_duplicate)
end

end_seg = _end_seg
end

Expand Down

0 comments on commit d1cbbb0

Please sign in to comment.