Spinwidgets: can now get width or width_factor (#8269)

This commit is contained in:
hius07
2021-10-01 21:32:16 +03:00
committed by GitHub
parent 2b87b1d8ed
commit 4c9d1ac3f8
4 changed files with 19 additions and 2 deletions

View File

@@ -25,6 +25,7 @@ local SpinWidget = InputContainer:new{
title_face = Font:getFace("x_smalltfont"),
info_text = nil,
width = nil,
width_factor = nil, -- number between 0 and 1, factor to the smallest of screen width and height
height = nil,
value_table = nil,
value_index = nil,
@@ -50,7 +51,12 @@ local SpinWidget = InputContainer:new{
function SpinWidget:init()
self.screen_width = Screen:getWidth()
self.screen_height = Screen:getHeight()
self.width = self.width or math.floor(math.min(self.screen_width, self.screen_height) * 0.6)
if not self.width then
if not self.width_factor then
self.width_factor = 0.6 -- default if no width speficied
end
self.width = math.floor(math.min(self.screen_width, self.screen_height) * self.width_factor)
end
if Device:hasKeys() then
self.key_events = {
Close = { {"Back"}, doc = "close spin widget" }