@ -7,6 +7,7 @@ local ConfirmBox = require("ui/widget/confirmbox")
local Device = require ( " device " )
local Event = require ( " ui/event " )
local FixedTextWidget = require ( " ui/widget/fixedtextwidget " )
local FocusManager = require ( " ui/widget/focusmanager " )
local Font = require ( " ui/font " )
local FrameContainer = require ( " ui/widget/container/framecontainer " )
local Geom = require ( " ui/geometry " )
@ -59,13 +60,17 @@ function OptionTextItem:init()
doc = " Hold Option Item " ,
} ,
}
else
self.active_key_events = {
Select = { { " Press " } , doc = " chose selected item " } ,
}
end
end
function OptionTextItem : onFocus ( )
self [ 1 ] . color = Blitbuffer.COLOR_BLACK
end
function OptionTextItem : onUnfocus ( )
self [ 1 ] . color = Blitbuffer.COLOR_WHITE
end
function OptionTextItem : onTapSelect ( )
if not self.enabled then return true end
for _ , item in pairs ( self.items ) do
@ -119,6 +124,14 @@ function OptionIconItem:init()
end
end
function OptionIconItem : onFocus ( )
self.icon . invert = true
end
function OptionIconItem : onUnfocus ( )
self.icon . invert = false
end
function OptionIconItem : onTapSelect ( )
if not self.enabled then return true end
for _ , item in pairs ( self.items ) do
@ -455,6 +468,8 @@ function ConfigOption:init()
table.insert ( option_items_group , switch )
end
table.insert ( option_items_container , option_items_group )
--add line of item to the second last place in the focusmanager so the menubar stay at the bottom
table.insert ( self.config . layout , # self.config . layout , self : _itemGroupToLayoutLine ( option_items_group ) )
table.insert ( horizontal_group , option_items_container )
table.insert ( vertical_group , horizontal_group )
end -- if
@ -464,6 +479,23 @@ function ConfigOption:init()
self.dimen = vertical_group : getSize ( )
end
function ConfigOption : _itemGroupToLayoutLine ( option_items_group )
local layout_line = { }
for k , v in pairs ( option_items_group ) do
--pad the beginning of the line in the layout to align it with the current selected tab
if type ( k ) == " number " then
layout_line [ k + self.config . panel_index - 1 ] = v
end
end
for k , v in pairs ( layout_line ) do
--remove item_spacing (all widget have the name property)
if not v.name then
table.remove ( layout_line , k )
end
end
return layout_line
end
local ConfigPanel = FrameContainer : new { background = Blitbuffer.COLOR_WHITE , bordersize = 0 , }
function ConfigPanel : init ( )
local config_options = self.config_dialog . config_options
@ -504,7 +536,7 @@ function MenuBar:init()
}
menu_items [ c ] = menu_icon
end
table.insert ( self.config_dialog . layout , menu_items ) --for the focusmanager
local available_width = Screen : getWidth ( ) - icons_width
-- local padding = math.floor(available_width / #menu_items / 2) -- all for padding
-- local padding = math.floor(available_width / #menu_items / 2 / 2) -- half padding, half spacing ?
@ -612,7 +644,7 @@ Widget that displays config menubar and config panel
--]]
local ConfigDialog = InputContain er: new {
local ConfigDialog = FocusManag er: new {
--is_borderless = false,
panel_index = 1 ,
}
@ -650,10 +682,8 @@ function ConfigDialog:init()
if Device : hasKeys ( ) then
-- set up keyboard events
self.key_events . Close = { { " Back " } , doc = " close config menu " }
-- we won't catch presses to "Right"
self.key_events . FocusRight = nil
end
self.key_events . Select = { { " Press " } , doc = " select current menu item " }
end
end
function ConfigDialog : updateConfigPanel ( index )
@ -661,6 +691,7 @@ function ConfigDialog:updateConfigPanel(index)
end
function ConfigDialog : update ( )
self.layout = { }
self.config_menubar = MenuBar : new {
config_dialog = self ,
panel_index = self.panel_index ,
@ -676,6 +707,9 @@ function ConfigDialog:update()
self.config_menubar ,
} ,
}
--reset the focusmanager cursor
self.selected . y =# self.layout
self.selected . x = self.panel_index
self [ 1 ] = BottomContainer : new {
dimen = Screen : getSize ( ) ,
@ -791,4 +825,9 @@ function ConfigDialog:onClose()
return true
end
function ConfigDialog : onSelect ( )
self : getFocusItem ( ) : handleEvent ( Event : new ( " TapSelect " ) )
return true
end
return ConfigDialog