mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
TouchMenu: use radio buttons for single choice menu items (#8757)
This commit is contained in:
@@ -299,7 +299,7 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
text = _("Highlight style"),
|
||||
sub_item_table = {},
|
||||
}
|
||||
for _, v in ipairs(highlight_style) do
|
||||
for i, v in ipairs(highlight_style) do
|
||||
table.insert(menu_items.highlight_options.sub_item_table, {
|
||||
text_func = function()
|
||||
local text = v[1]
|
||||
@@ -311,6 +311,7 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
checked_func = function()
|
||||
return self.view.highlight.saved_drawer == v[2]
|
||||
end,
|
||||
radio = true,
|
||||
callback = function()
|
||||
self.view.highlight.saved_drawer = v[2]
|
||||
end,
|
||||
@@ -318,6 +319,7 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
G_reader_settings:saveSetting("highlight_drawing_style", v[2])
|
||||
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||
end,
|
||||
separator = i == #highlight_style,
|
||||
})
|
||||
end
|
||||
table.insert(menu_items.highlight_options.sub_item_table, {
|
||||
@@ -388,6 +390,7 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
checked_func = function()
|
||||
return G_reader_settings:readSetting("default_highlight_action", "ask") == v[2]
|
||||
end,
|
||||
radio = true,
|
||||
callback = function()
|
||||
G_reader_settings:saveSetting("default_highlight_action", v[2])
|
||||
self.view.highlight.disabled = v[2] == "nothing"
|
||||
|
||||
@@ -88,6 +88,7 @@ for k, v in pairs(page_overlap_styles) do
|
||||
checked_func = function()
|
||||
return ReaderUI.instance.view.page_overlap_style == k
|
||||
end,
|
||||
radio = true,
|
||||
callback = function()
|
||||
ReaderUI.instance.view.page_overlap_style = k
|
||||
end,
|
||||
|
||||
@@ -72,6 +72,7 @@ When unchecked, the default rotation of the file browser and the default/saved r
|
||||
checked_func = function()
|
||||
return Screen:getRotationMode() == Screen.ORIENTATION_LANDSCAPE_ROTATED
|
||||
end,
|
||||
radio = true,
|
||||
callback = function(touchmenu_instance)
|
||||
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE_ROTATED))
|
||||
if touchmenu_instance then touchmenu_instance:closeMenu() end
|
||||
@@ -92,6 +93,7 @@ When unchecked, the default rotation of the file browser and the default/saved r
|
||||
checked_func = function()
|
||||
return Screen:getRotationMode() == Screen.ORIENTATION_PORTRAIT
|
||||
end,
|
||||
radio = true,
|
||||
callback = function(touchmenu_instance)
|
||||
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT))
|
||||
if touchmenu_instance then touchmenu_instance:closeMenu() end
|
||||
@@ -112,6 +114,7 @@ When unchecked, the default rotation of the file browser and the default/saved r
|
||||
checked_func = function()
|
||||
return Screen:getRotationMode() == Screen.ORIENTATION_LANDSCAPE
|
||||
end,
|
||||
radio = true,
|
||||
callback = function(touchmenu_instance)
|
||||
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.ORIENTATION_LANDSCAPE))
|
||||
if touchmenu_instance then touchmenu_instance:closeMenu() end
|
||||
@@ -132,6 +135,7 @@ When unchecked, the default rotation of the file browser and the default/saved r
|
||||
checked_func = function()
|
||||
return Screen:getRotationMode() == Screen.ORIENTATION_PORTRAIT_ROTATED
|
||||
end,
|
||||
radio = true,
|
||||
callback = function(touchmenu_instance)
|
||||
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.ORIENTATION_PORTRAIT_ROTATED))
|
||||
if touchmenu_instance then touchmenu_instance:closeMenu() end
|
||||
|
||||
28
frontend/ui/widget/radiomark.lua
Normal file
28
frontend/ui/widget/radiomark.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
local BD = require("ui/bidi")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local Font = require("ui/font")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
|
||||
local RadioMark = InputContainer:new{
|
||||
checkable = true, -- empty space when false
|
||||
checked = false,
|
||||
enabled = true,
|
||||
face = Font:getFace("smallinfofont"),
|
||||
baseline = 0,
|
||||
_mirroredUI = BD.mirroredUILayout(),
|
||||
}
|
||||
|
||||
function RadioMark:init()
|
||||
local widget = TextWidget:new{
|
||||
text = self.checkable and (self.checked and "◉ " or "◯ ") or "",
|
||||
face = self.face,
|
||||
fgcolor = self.enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
|
||||
para_direction_rtl = self._mirroredUI,
|
||||
}
|
||||
self.baseline = widget:getBaseline()
|
||||
self[1] = widget
|
||||
self.dimen = widget:getSize()
|
||||
end
|
||||
|
||||
return RadioMark
|
||||
@@ -20,6 +20,7 @@ local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local LeftContainer = require("ui/widget/container/leftcontainer")
|
||||
local LineWidget = require("ui/widget/linewidget")
|
||||
local RadioMark = require("ui/widget/radiomark")
|
||||
local RightContainer = require("ui/widget/container/rightcontainer")
|
||||
local Size = require("ui/size")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
@@ -74,11 +75,20 @@ function TouchMenuItem:init()
|
||||
item_checkable = true
|
||||
item_checked = self.item.checked_func()
|
||||
end
|
||||
local checkmark_widget = CheckMark:new{
|
||||
checkable = item_checkable,
|
||||
checked = item_checked,
|
||||
enabled = item_enabled,
|
||||
}
|
||||
local checkmark_widget
|
||||
if self.item.radio then
|
||||
checkmark_widget = RadioMark:new{
|
||||
checkable = item_checkable,
|
||||
checked = item_checked,
|
||||
enabled = item_enabled,
|
||||
}
|
||||
else
|
||||
checkmark_widget = CheckMark:new{
|
||||
checkable = item_checkable,
|
||||
checked = item_checked,
|
||||
enabled = item_enabled,
|
||||
}
|
||||
end
|
||||
|
||||
local checked_widget = CheckMark:new{ -- for layout, to :getSize()
|
||||
checked = true,
|
||||
|
||||
Reference in New Issue
Block a user