Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TouchMenu: keep hamburger menu on the right #2679

Merged
merged 1 commit into from
Mar 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions frontend/ui/widget/touchmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ 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 +212,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 +225,52 @@ 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, last_icon
if k == #self.icons then
current_icon = false
last_icon = i == k
else
current_icon = i == k - 1 or i == k
last_icon = false
end

-- if the active icon is the 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
}
}
sep.style = "solid"
-- regular behavior
else
sep.style = current_icon and "solid" or "none"
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