[travis] Add protection against unscaled sizes

As pointed out by @poire-z

* [fix, UX] SkimToWidget scaling

* [fix] Button scaling

* [fix, UX] Scale ProgressWidget

* [fix, UX] Scale confirmbox

* [fix, UX] Scale just about everything
pull/3251/head
Frans de Jonge 7 years ago
parent 8babe57106
commit 9eb073a524

@ -4,15 +4,29 @@ CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=/dev/null # shellcheck source=/dev/null
source "${CI_DIR}/common.sh" source "${CI_DIR}/common.sh"
echo -e "\n${ANSI_GREEN}make fetchthirdparty" echo -e "\\n${ANSI_GREEN}make fetchthirdparty"
travis_retry make fetchthirdparty travis_retry make fetchthirdparty
"${CI_DIR}/helper_shellchecks.sh" "${CI_DIR}/helper_shellchecks.sh"
echo -e "\n${ANSI_GREEN}Luacheck results" echo -e "\\n${ANSI_GREEN}Checking for unscaled sizes"
# stick `|| true` at the end to prevent Travis exit on failed command
unscaled_size_check=$(grep -nr --include=*.lua --exclude=koptoptions.lua --exclude-dir=base --exclude-dir=install --exclude-dir=keyboardlayouts --exclude-dir=*arm* "\\(padding\\|margin\\|bordersize\\|width\\|height\\|radius\\|linesize\\) = [0-9]\\{1,2\\}" | grep -v '= 0' | grep -v '= [0-9]/[0-9]' | grep -Ev '(default_option_height|default_option_padding)' | grep -v scaleBySize || true)
# Also check Geom objects; for legibility two regular expressions rather than
# one enormous indecipharable blob.
unscaled_size_check_geom=$(grep -E -nr --include=*.lua --exclude=gesturerange_spec.lua --exclude-dir=base --exclude-dir=*arm* 'Geom:new{.+ [wh] = [0-9]{1,4}' | grep -Ev '[wh] = 0' | grep -v '= [0-9]/[0-9]' | grep -v scaleBySize || true)
if [ "${unscaled_size_check}" ] || [ "${unscaled_size_check_geom}" ]; then
echo -e "\\n${ANSI_RED}Warning: it looks like you might be using unscaled sizes.\\nIt is almost always preferable to defer to one of the predefined sizes in ui.elements.commonui in the following files:"
echo "${unscaled_size_check}"
echo "${unscaled_size_check_geom}"
exit 1
fi
echo -e "\\n${ANSI_GREEN}Luacheck results"
luajit "$(which luacheck)" --no-color -q {reader,setupkoenv,datastorage}.lua frontend plugins spec luajit "$(which luacheck)" --no-color -q {reader,setupkoenv,datastorage}.lua frontend plugins spec
echo -e "\n${ANSI_GREEN}make all" echo -e "\\n${ANSI_GREEN}make all"
make all make all
echo -e "\n${ANSI_GREEN}make testfront" echo -e "\\n${ANSI_GREEN}make testfront"
make testfront make testfront

@ -12,7 +12,6 @@ local FileManagerHistory = require("apps/filemanager/filemanagerhistory")
local FileManagerMenu = require("apps/filemanager/filemanagermenu") local FileManagerMenu = require("apps/filemanager/filemanagermenu")
local Font = require("ui/font") local Font = require("ui/font")
local FrameContainer = require("ui/widget/container/framecontainer") local FrameContainer = require("ui/widget/container/framecontainer")
local Geom = require("ui/geometry")
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog") local InputDialog = require("ui/widget/inputdialog")
@ -42,8 +41,6 @@ end
local FileManager = InputContainer:extend{ local FileManager = InputContainer:extend{
title = _("KOReader File Browser"), title = _("KOReader File Browser"),
root_path = lfs.currentdir(), root_path = lfs.currentdir(),
-- our own size
dimen = Geom:new{ w = 400, h = 600 },
onExit = function() end, onExit = function() end,
mv_bin = Device:isAndroid() and "/system/bin/mv" or "/bin/mv", mv_bin = Device:isAndroid() and "/system/bin/mv" or "/bin/mv",

@ -1,18 +1,18 @@
local InputContainer = require("ui/widget/container/inputcontainer") local BBoxWidget = require("ui/widget/bboxwidget")
local UIManager = require("ui/uimanager") local Blitbuffer = require("ffi/blitbuffer")
local Geom = require("ui/geometry") local Button = require("ui/widget/button")
local Event = require("ui/event") local Event = require("ui/event")
local Screen = require("device").screen
local LeftContainer = require("ui/widget/container/leftcontainer")
local RightContainer = require("ui/widget/container/rightcontainer")
local FrameContainer = require("ui/widget/container/framecontainer") local FrameContainer = require("ui/widget/container/framecontainer")
local VerticalGroup = require("ui/widget/verticalgroup") local Geom = require("ui/geometry")
local InputContainer = require("ui/widget/container/inputcontainer")
local HorizontalGroup = require("ui/widget/horizontalgroup") local HorizontalGroup = require("ui/widget/horizontalgroup")
local BBoxWidget = require("ui/widget/bboxwidget")
local HorizontalSpan = require("ui/widget/horizontalspan") local HorizontalSpan = require("ui/widget/horizontalspan")
local Button = require("ui/widget/button") local LeftContainer = require("ui/widget/container/leftcontainer")
local Math = require("optmath") local Math = require("optmath")
local Blitbuffer = require("ffi/blitbuffer") local RightContainer = require("ui/widget/container/rightcontainer")
local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup")
local Screen = require("device").screen
local PageCropDialog = VerticalGroup:new{ local PageCropDialog = VerticalGroup:new{
ok_text = "OK", ok_text = "OK",
@ -28,8 +28,6 @@ function PageCropDialog:init()
text = self.ok_text, text = self.ok_text,
callback = self.ok_callback, callback = self.ok_callback,
width = self.button_width, width = self.button_width,
bordersize = 2,
radius = 7,
text_font_face = "cfont", text_font_face = "cfont",
text_font_size = 20, text_font_size = 20,
show_parent = self, show_parent = self,
@ -38,8 +36,6 @@ function PageCropDialog:init()
text = self.cancel_text, text = self.cancel_text,
callback = self.cancel_callback, callback = self.cancel_callback,
width = self.button_width, width = self.button_width,
bordersize = 2,
radius = 7,
text_font_face = "cfont", text_font_face = "cfont",
text_font_size = 20, text_font_size = 20,
show_parent = self, show_parent = self,

@ -12,7 +12,6 @@ local DocumentRegistry = require("document/documentregistry")
local Event = require("ui/event") local Event = require("ui/event")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo") local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local FileManagerHistory = require("apps/filemanager/filemanagerhistory") local FileManagerHistory = require("apps/filemanager/filemanagerhistory")
local Geom = require("ui/geometry")
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog") local InputDialog = require("ui/widget/inputdialog")
@ -60,8 +59,6 @@ local ReaderUI = InputContainer:new{
}, },
active_widgets = {}, active_widgets = {},
-- our own size
dimen = Geom:new{ w = 400, h = 600 },
-- if we have a parent container, it must be referenced for now -- if we have a parent container, it must be referenced for now
dialog = nil, dialog = nil,

@ -33,6 +33,9 @@ function SkimToWidget:init()
self.screen_height = Screen:getSize().h self.screen_height = Screen:getSize().h
self.span = math.ceil(self.screen_height * 0.01) self.span = math.ceil(self.screen_height * 0.01)
self.width = self.screen_width * 0.95 self.width = self.screen_width * 0.95
self.button_bordersize = Screen:scaleBySize(2)
self.button_margin = self.button_bordersize
self.button_width = self.screen_width * 0.16 - (2*self.button_margin)
if Device:hasKeys() then if Device:hasKeys() then
self.key_events = { self.key_events = {
Close = { {"Back"}, doc = "close skimto page" } Close = { {"Back"}, doc = "close skimto page" }
@ -110,11 +113,11 @@ function SkimToWidget:init()
} }
self.button_minus = Button:new{ self.button_minus = Button:new{
text = "-1", text = "-1",
bordersize = 2, bordersize = self.button_bordersize,
margin = 2, margin = self.button_margin,
radius = 0, radius = 0,
enabled = true, enabled = true,
width = self.screen_width * 0.16, width = self.button_width,
show_parent = self, show_parent = self,
callback = function() callback = function()
self.curr_page = self.curr_page - 1 self.curr_page = self.curr_page - 1
@ -124,11 +127,11 @@ function SkimToWidget:init()
} }
self.button_minus_ten = Button:new{ self.button_minus_ten = Button:new{
text = "-10", text = "-10",
bordersize = 2, bordersize = self.button_bordersize,
margin = 2, margin = self.button_margin,
radius = 0, radius = 0,
enabled = true, enabled = true,
width = self.screen_width * 0.16, width = self.button_width,
show_parent = self, show_parent = self,
callback = function() callback = function()
self.curr_page = self.curr_page - 10 self.curr_page = self.curr_page - 10
@ -138,11 +141,11 @@ function SkimToWidget:init()
} }
self.button_plus = Button:new{ self.button_plus = Button:new{
text = "+1", text = "+1",
bordersize = 2, bordersize = self.button_bordersize,
margin = 2, margin = self.button_margin,
radius = 0, radius = 0,
enabled = true, enabled = true,
width = self.screen_width * 0.16, width = self.button_width,
show_parent = self, show_parent = self,
callback = function() callback = function()
self.curr_page = self.curr_page + 1 self.curr_page = self.curr_page + 1
@ -152,11 +155,11 @@ function SkimToWidget:init()
} }
self.button_plus_ten = Button:new{ self.button_plus_ten = Button:new{
text = "+10", text = "+10",
bordersize = 2, bordersize = self.button_bordersize,
margin = 2, margin = self.button_margin,
radius = 0, radius = 0,
enabled = true, enabled = true,
width = self.screen_width * 0.16, width = self.button_width,
show_parent = self, show_parent = self,
callback = function() callback = function()
self.curr_page = self.curr_page + 10 self.curr_page = self.curr_page + 10
@ -167,10 +170,10 @@ function SkimToWidget:init()
local current_page_text = Button:new{ local current_page_text = Button:new{
text = self.curr_page, text = self.curr_page,
bordersize = 0, bordersize = 0,
margin = 2, margin = self.button_margin,
radius = 0, radius = 0,
enabled = true, enabled = true,
width = self.screen_width * 0.2, width = self.screen_width * 0.2 - (2*self.button_margin),
show_parent = self, show_parent = self,
callback = function() callback = function()
self.callback_switch_to_goto() self.callback_switch_to_goto()
@ -193,8 +196,8 @@ function SkimToWidget:init()
table.insert(vertical_group_control,padding_span) table.insert(vertical_group_control,padding_span)
self.skimto_frame = FrameContainer:new{ self.skimto_frame = FrameContainer:new{
radius = 5, radius = Screen:scaleBySize(5),
bordersize = 3, bordersize = Screen:scaleBySize(3),
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
@ -256,10 +259,10 @@ function SkimToWidget:update()
local current_page_text = Button:new{ local current_page_text = Button:new{
text = self.curr_page, text = self.curr_page,
bordersize = 0, bordersize = 0,
margin = 2, margin = self.button_margin,
radius = 0, radius = 0,
enabled = true, enabled = true,
width = self.screen_width * 0.2, width = self.screen_width * 0.2 - (2*self.button_margin),
show_parent = self, show_parent = self,
callback = function() callback = function()
self.callback_switch_to_goto() self.callback_switch_to_goto()
@ -282,8 +285,8 @@ function SkimToWidget:update()
table.insert(vertical_group_control,padding_span) table.insert(vertical_group_control,padding_span)
self.skimto_frame = FrameContainer:new{ self.skimto_frame = FrameContainer:new{
radius = 5, radius = Screen:scaleBySize(5),
bordersize = 3, bordersize = Screen:scaleBySize(3),
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -1,5 +1,5 @@
local Screen = require("device").screen
local S = require("ui/data/strings") local S = require("ui/data/strings")
local Screen = require("device").screen
local _ = require("gettext") local _ = require("gettext")

@ -1,6 +1,6 @@
local Screen = require("device").screen
local S = require("ui/data/strings") local S = require("ui/data/strings")
local _ = require("gettext") local _ = require("gettext")
local Screen = require("device").screen
local function enable_if_equals(configurable, option, value) local function enable_if_equals(configurable, option, value)
return configurable[option] == value return configurable[option] == value
@ -29,7 +29,6 @@ local KoptOptions = {
{ {
name = "trim_page", name = "trim_page",
name_text = S.PAGE_CROP, name_text = S.PAGE_CROP,
width = 261,
toggle = {S.MANUAL, S.AUTO, S.SEMIAUTO}, toggle = {S.MANUAL, S.AUTO, S.SEMIAUTO},
alternate = false, alternate = false,
values = {0, 1, 2}, values = {0, 1, 2},

@ -4,7 +4,7 @@
All of these apply to full rectangles: All of these apply to full rectangles:
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
Geom:new{ x = 1, y = 0, w = 100, h = 200, } Geom:new{ x = 1, y = 0, w = Screen:scaleBySize(100), h = Screen:scaleBySize(200), }
Some behaviour is defined for points: Some behaviour is defined for points:
@ -12,7 +12,7 @@ Some behaviour is defined for points:
Some behaviour is defined for dimensions: Some behaviour is defined for dimensions:
Geom:new{ w = 600, h = 800, } Geom:new{ w = Screen:scaleBySize(600), h = Screen:scaleBySize(800), }
Just use it on simple tables that have x, y and/or w, h Just use it on simple tables that have x, y and/or w, h
or define your own types using this as a metatable or define your own types using this as a metatable

@ -9,11 +9,12 @@ local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange") local GestureRange = require("ui/gesturerange")
local Math = require("optmath") local Math = require("optmath")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local Screen = Device.screen
local BBoxWidget = InputContainer:new{ local BBoxWidget = InputContainer:new{
page_bbox = nil, page_bbox = nil,
screen_bbox = nil, screen_bbox = nil,
linesize = 2, linesize = Screen:scaleBySize(2),
fine_factor = 10, fine_factor = 10,
dimen = Geom:new(), dimen = Geom:new(),
} }

@ -22,10 +22,10 @@ local ToggleSwitch = require("ui/widget/toggleswitch")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup") local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan") local VerticalSpan = require("ui/widget/verticalspan")
local Screen = require("device").screen
local template = require("ffi/util").template
local util = require("util") local util = require("util")
local _ = require("gettext") local _ = require("gettext")
local Screen = require("device").screen
local template = require("ffi/util").template
local stats_book = {} local stats_book = {}
@ -246,7 +246,7 @@ function BookStatusWidget:genBookInfoGroup()
local text_author = TextWidget:new{ local text_author = TextWidget:new{
text = self.props.authors, text = self.props.authors,
face = self.small_font_face, face = self.small_font_face,
padding = 2, padding = Screen:scaleBySize(2),
} }
table.insert(book_meta_info_group, table.insert(book_meta_info_group,
CenterContainer:new{ CenterContainer:new{
@ -391,14 +391,14 @@ function BookStatusWidget:genSummaryGroup(width)
height = Screen:scaleBySize(130) height = Screen:scaleBySize(130)
end end
local text_padding = 5 local text_padding = Screen:scaleBySize(5)
self.input_note = InputText:new{ self.input_note = InputText:new{
text = self.summary.note, text = self.summary.note,
face = self.medium_font_face, face = self.medium_font_face,
width = width - self.padding * 3, width = width - self.padding * 3,
height = height * 0.75, height = height * 0.75,
scroll = true, scroll = true,
bordersize = 2, bordersize = Screen:scaleBySize(2),
focused = false, focused = false,
padding = text_padding, padding = text_padding,
parent = self, parent = self,

@ -1,5 +1,18 @@
--[[-- --[[--
A button widget that shows text or a icon and handles callback when tapped. A button widget that shows text or an icon and handles callback when tapped.
@usage
local Button = require("ui/widget/button")
local button = Button:new{
text = _("Press me!"),
enabled = false, -- defaults to true
callback = some_callback_function,
width = Screen:scaleBySize(50),
max_width = Screen:scaleBySize(100),
bordersize = Screen:scaleBySize(3),
margin = 0,
padding = Screen:scaleBySize(2),
}
--]] --]]
local Blitbuffer = require("ffi/blitbuffer") local Blitbuffer = require("ffi/blitbuffer")
@ -14,6 +27,7 @@ local InputContainer = require("ui/widget/container/inputcontainer")
local TextWidget = require("ui/widget/textwidget") local TextWidget = require("ui/widget/textwidget")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local _ = require("gettext") local _ = require("gettext")
local Screen = Device.screen
local Button = InputContainer:new{ local Button = InputContainer:new{
text = nil, -- mandatory text = nil, -- mandatory
@ -22,10 +36,10 @@ local Button = InputContainer:new{
callback = nil, callback = nil,
enabled = true, enabled = true,
margin = 0, margin = 0,
bordersize = 3, bordersize = Screen:scaleBySize(3),
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
radius = 15, radius = Screen:scaleBySize(15),
padding = 2, padding = Screen:scaleBySize(2),
width = nil, width = nil,
max_width = nil, max_width = nil,
text_font_face = "cfont", text_font_face = "cfont",

@ -1,14 +1,14 @@
local Blitbuffer = require("ffi/blitbuffer")
local ButtonTable = require("ui/widget/buttontable") local ButtonTable = require("ui/widget/buttontable")
local InputContainer = require("ui/widget/container/inputcontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local CenterContainer = require("ui/widget/container/centercontainer") local CenterContainer = require("ui/widget/container/centercontainer")
local Device = require("device") local Device = require("device")
local GestureRange = require("ui/gesturerange") local FrameContainer = require("ui/widget/container/framecontainer")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local Screen = require("device").screen local GestureRange = require("ui/gesturerange")
local InputContainer = require("ui/widget/container/inputcontainer")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local _ = require("gettext") local _ = require("gettext")
local Blitbuffer = require("ffi/blitbuffer") local Screen = require("device").screen
local ButtonDialog = InputContainer:new{ local ButtonDialog = InputContainer:new{
buttons = nil, buttons = nil,
@ -42,9 +42,9 @@ function ButtonDialog:init()
show_parent = self, show_parent = self,
}, },
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
bordersize = 2, bordersize = Screen:scaleBySize(2),
radius = 7, radius = Screen:scaleBySize(7),
padding = 2, padding = Screen:scaleBySize(2),
} }
} }
end end

@ -47,7 +47,7 @@ function ButtonDialogTitle:init()
FrameContainer:new{ FrameContainer:new{
VerticalGroup:new{ VerticalGroup:new{
align = "center", align = "center",
VerticalSpan:new{ width = 2 }, VerticalSpan:new{ width = Screen:scaleBySize(2) },
TextBoxWidget:new{ TextBoxWidget:new{
text = self.title, text = self.title,
width = Screen:getWidth() * 0.8 , width = Screen:getWidth() * 0.8 ,
@ -55,14 +55,14 @@ function ButtonDialogTitle:init()
bold = true, bold = true,
alignment = self.title_align or "left", alignment = self.title_align or "left",
}, },
VerticalSpan:new{ width = 2 }, VerticalSpan:new{ width = Screen:scaleBySize(2) },
LineWidget:new{ LineWidget:new{
dimen = Geom:new{ dimen = Geom:new{
w = Screen:getWidth() * 0.9, w = Screen:getWidth() * 0.9,
h = 1, h = Screen:scaleBySize(1),
} }
}, },
VerticalSpan:new{ width = 2 }, VerticalSpan:new{ width = Screen:scaleBySize(2) },
ButtonTable:new{ ButtonTable:new{
width = Screen:getWidth() * 0.9, width = Screen:getWidth() * 0.9,
buttons = self.buttons, buttons = self.buttons,
@ -70,9 +70,9 @@ function ButtonDialogTitle:init()
}, },
}, },
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
bordersize = 2, bordersize = Screen:scaleBySize(2),
radius = 7, radius = Screen:scaleBySize(7),
padding = 2, padding = Screen:scaleBySize(2),
} }
} }
end end

@ -283,7 +283,7 @@ function ConfigOption:init()
face = Font:getFace(item_font_face, item_font_size[d]), face = Font:getFace(item_font_face, item_font_size[d]),
fgcolor = Blitbuffer.gray(enabled and 1.0 or 0.5), fgcolor = Blitbuffer.gray(enabled and 1.0 or 0.5),
}, },
padding = 3, padding = Screen:scaleBySize(3),
color = d == current_item and Blitbuffer.gray(enabled and 1.0 or 0.5) or Blitbuffer.COLOR_WHITE, color = d == current_item and Blitbuffer.gray(enabled and 1.0 or 0.5) or Blitbuffer.COLOR_WHITE,
enabled = enabled, enabled = enabled,
} }

@ -45,8 +45,8 @@ local ConfirmBox = InputContainer:new{
ok_callback = function() end, ok_callback = function() end,
cancel_callback = function() end, cancel_callback = function() end,
other_buttons = nil, other_buttons = nil,
margin = 5, margin = Screen:scaleBySize(5),
padding = 5, padding = Screen:scaleBySize(5),
} }
function ConfirmBox:init() function ConfirmBox:init()
@ -70,9 +70,10 @@ function ConfirmBox:init()
local content = HorizontalGroup:new{ local content = HorizontalGroup:new{
align = "center", align = "center",
ImageWidget:new{ ImageWidget:new{
file = "resources/info-i.png" file = "resources/info-i.png",
scale_for_dpi = true,
}, },
HorizontalSpan:new{ width = 10 }, HorizontalSpan:new{ width = Screen:scaleBySize(10) },
TextBoxWidget:new{ TextBoxWidget:new{
text = self.text, text = self.text,
face = self.face, face = self.face,

@ -10,9 +10,9 @@ Example:
FrameContainer:new{ FrameContainer:new{
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
bordersize = 1, bordersize = Screen:scaleBySize(1),
margin = 0, margin = 0,
padding = 1 padding = Screen:scaleBySize(1)
} }
} }
--]] --]]

@ -6,8 +6,8 @@ Example:
local frame local frame
frame = FrameContainer:new{ frame = FrameContainer:new{
radius = 8, radius = Screen:scaleBySize(8),
bordersize = 3, bordersize = Screen:scaleBySize(3),
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -7,10 +7,11 @@ a line under its child node.
local Blitbuffer = require("ffi/blitbuffer") local Blitbuffer = require("ffi/blitbuffer")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local WidgetContainer = require("ui/widget/container/widgetcontainer") local WidgetContainer = require("ui/widget/container/widgetcontainer")
local Screen = require("device").screen
local UnderlineContainer = WidgetContainer:new{ local UnderlineContainer = WidgetContainer:new{
linesize = 2, linesize = Screen:scaleBySize(2),
padding = 1, padding = Screen:scaleBySize(1),
-- TODO: shouldn't this default to black instead? -- TODO: shouldn't this default to black instead?
color = Blitbuffer.COLOR_WHITE, color = Blitbuffer.COLOR_WHITE,
vertical_align = "top", vertical_align = "top",

@ -418,8 +418,8 @@ function DictQuickLookup:update()
} }
self.dict_frame = FrameContainer:new{ self.dict_frame = FrameContainer:new{
radius = 8, radius = Screen:scaleBySize(8),
bordersize = 3, bordersize = Screen:scaleBySize(3),
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -51,9 +51,9 @@ function FrontLightWidget:init()
self.fl_prog_button = Button:new{ self.fl_prog_button = Button:new{
text = "", text = "",
bordersize = 3, bordersize = Screen:scaleBySize(3),
radius = 0, radius = 0,
margin = 1, margin = Screen:scaleBySize(1),
enabled = true, enabled = true,
width = self.button_width, width = self.button_width,
show_parent = self, show_parent = self,
@ -124,7 +124,7 @@ function FrontLightWidget:setProgress(num, step)
for i = step_min, step_num do for i = step_min, step_num do
table.insert(fl_group, self.fl_prog_button:new{ table.insert(fl_group, self.fl_prog_button:new{
text= "", text= "",
margin = 1, margin = Screen:scaleBySize(1),
preselect = true, preselect = true,
width = self.button_width, width = self.button_width,
callback = function() callback = function()
@ -145,8 +145,8 @@ function FrontLightWidget:setProgress(num, step)
end end
local button_minus = Button:new{ local button_minus = Button:new{
text = "-1", text = "-1",
bordersize = 2, bordersize = Screen:scaleBySize(2),
margin = 2, margin = Screen:scaleBySize(2),
radius = 0, radius = 0,
enabled = enable_button_minus, enabled = enable_button_minus,
width = self.screen_width * 0.20, width = self.screen_width * 0.20,
@ -155,8 +155,8 @@ function FrontLightWidget:setProgress(num, step)
} }
local button_plus = Button:new{ local button_plus = Button:new{
text = "+1", text = "+1",
bordersize = 2, bordersize = Screen:scaleBySize(2),
margin = 2, margin = Screen:scaleBySize(2),
radius = 0, radius = 0,
enabled = enable_button_plus, enabled = enable_button_plus,
width = self.screen_width * 0.20, width = self.screen_width * 0.20,
@ -171,8 +171,8 @@ function FrontLightWidget:setProgress(num, step)
} }
local button_min = Button:new{ local button_min = Button:new{
text = _("Min"), text = _("Min"),
bordersize = 2, bordersize = Screen:scaleBySize(2),
margin = 2, margin = Screen:scaleBySize(2),
radius = 0, radius = 0,
enabled = true, enabled = true,
width = self.screen_width * 0.20, width = self.screen_width * 0.20,
@ -181,8 +181,8 @@ function FrontLightWidget:setProgress(num, step)
} }
local button_max = Button:new{ local button_max = Button:new{
text = _("Max"), text = _("Max"),
bordersize = 2, bordersize = Screen:scaleBySize(2),
margin = 2, margin = Screen:scaleBySize(2),
radius = 0, radius = 0,
enabled = true, enabled = true,
width = self.screen_width * 0.20, width = self.screen_width * 0.20,
@ -191,8 +191,8 @@ function FrontLightWidget:setProgress(num, step)
} }
local button_toggle = Button:new{ local button_toggle = Button:new{
text = _("Toggle"), text = _("Toggle"),
bordersize = 2, bordersize = Screen:scaleBySize(2),
margin = 2, margin = Screen:scaleBySize(2),
radius = 0, radius = 0,
enabled = true, enabled = true,
width = self.screen_width * 0.20, width = self.screen_width * 0.20,
@ -266,8 +266,8 @@ function FrontLightWidget:update()
CloseButton:new{ window = self, }, CloseButton:new{ window = self, },
} }
self.light_frame = FrameContainer:new{ self.light_frame = FrameContainer:new{
radius = 5, radius = Screen:scaleBySize(5),
bordersize = 3, bordersize = Screen:scaleBySize(3),
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -258,7 +258,6 @@ function ImageViewer:update()
end end
self.main_frame = FrameContainer:new{ self.main_frame = FrameContainer:new{
radius = not self.fullscreen and 8 or nil, radius = not self.fullscreen and 8 or nil,
bordersize = 3,
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -6,13 +6,14 @@ It vanishes on key press or after a given timeout.
Example: Example:
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local _ = require("gettext") local _ = require("gettext")
local Screen = require("device").screen
local sample local sample
sample = InfoMessage:new{ sample = InfoMessage:new{
text = _("Some message"), text = _("Some message"),
-- Usually the hight of a InfoMessage is self-adaptive. If this field is actively set, a -- Usually the hight of a InfoMessage is self-adaptive. If this field is actively set, a
-- scrollbar may be shown. This variable is usually helpful to display a large chunk of text -- scrollbar may be shown. This variable is usually helpful to display a large chunk of text
-- which may exceed the height of the screen. -- which may exceed the height of the screen.
height = 400, height = Screen:scaleBySize(400),
-- Set to false to hide the icon, and also the span between the icon and text. -- Set to false to hide the icon, and also the span between the icon and text.
show_icon = false, show_icon = false,
timeout = 5, -- This widget will vanish in 5 seconds. timeout = 5, -- This widget will vanish in 5 seconds.
@ -91,6 +92,7 @@ function InfoMessage:init()
else else
image_widget = ImageWidget:new{ image_widget = ImageWidget:new{
file = "resources/info-i.png", file = "resources/info-i.png",
scale_for_dpi = true,
} }
end end
else else
@ -127,12 +129,12 @@ function InfoMessage:init()
self[1] = CenterContainer:new{ self[1] = CenterContainer:new{
dimen = Screen:getSize(), dimen = Screen:getSize(),
FrameContainer:new{ FrameContainer:new{
margin = 2, margin = Screen:scaleBySize(2),
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
HorizontalGroup:new{ HorizontalGroup:new{
align = "center", align = "center",
image_widget, image_widget,
HorizontalSpan:new{ width = (self.show_icon and 10 or 0) }, HorizontalSpan:new{ width = (self.show_icon and Screen:scaleBySize(10) or 0) },
text_widget, text_widget,
} }
} }

@ -164,8 +164,7 @@ function InputDialog:init()
} }
self.dialog_frame = FrameContainer:new{ self.dialog_frame = FrameContainer:new{
radius = 8, radius = Screen:scaleBySize(8),
bordersize = 3,
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -74,7 +74,7 @@ function KeyValueTitle:init()
}) })
-- page count and separation line -- page count and separation line
self.page_cnt = FrameContainer:new{ self.page_cnt = FrameContainer:new{
padding = 4, padding = Screen:scaleBySize(4),
margin = 0, margin = 0,
bordersize = 0, bordersize = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -10,7 +10,7 @@ local LinkBox = InputContainer:new{
box = nil, box = nil,
color = Blitbuffer.COLOR_GREY, color = Blitbuffer.COLOR_GREY,
radius = 0, radius = 0,
bordersize = 2, bordersize = Screen:scaleBySize(2),
} }
function LinkBox:init() function LinkBox:init()
@ -60,4 +60,3 @@ function LinkBox:onTapClose()
end end
return LinkBox return LinkBox

@ -4,8 +4,8 @@ Widget component that handles pagination for a list of items.
Example: Example:
local list_view = ListView:new{ local list_view = ListView:new{
height = 400, height = Screen:scaleBySize(400),
width = 200, width = Screen:scaleBySize(200),
page_update_cb = function(curr_page_num, total_pages) page_update_cb = function(curr_page_num, total_pages)
-- This callback function will be called whenever a page -- This callback function will be called whenever a page
-- turn event is triggered. You can use it to update -- turn event is triggered. You can use it to update

@ -1,13 +1,13 @@
local FrameContainer = require("ui/widget/container/framecontainer") local Blitbuffer = require("ffi/blitbuffer")
local CenterContainer = require("ui/widget/container/centercontainer") local CenterContainer = require("ui/widget/container/centercontainer")
local VerticalGroup = require("ui/widget/verticalgroup") local FrameContainer = require("ui/widget/container/framecontainer")
local Geom = require("ui/geometry")
local InputDialog = require("ui/widget/inputdialog") local InputDialog = require("ui/widget/inputdialog")
local InputText = require("ui/widget/inputtext") local InputText = require("ui/widget/inputtext")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local Geom = require("ui/geometry") local VerticalGroup = require("ui/widget/verticalgroup")
local Screen = require("device").screen
local _ = require("gettext") local _ = require("gettext")
local Blitbuffer = require("ffi/blitbuffer") local Screen = require("device").screen
local LoginDialog = InputDialog:extend{ local LoginDialog = InputDialog:extend{
username = "", username = "",
@ -41,8 +41,7 @@ function LoginDialog:init()
} }
self.dialog_frame = FrameContainer:new{ self.dialog_frame = FrameContainer:new{
radius = 8, radius = Screen:scaleBySize(8),
bordersize = 3,
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -33,9 +33,9 @@ local getMenuText = require("util").getMenuText
Widget that displays a shortcut icon for menu item Widget that displays a shortcut icon for menu item
--]] --]]
local ItemShortCutIcon = WidgetContainer:new{ local ItemShortCutIcon = WidgetContainer:new{
dimen = Geom:new{ w = 22, h = 22 }, dimen = Geom:new{ w = Screen:scaleBySize(22), h = Screen:scaleBySize(22) },
key = nil, key = nil,
bordersize = 2, bordersize = Screen:scaleBySize(2),
radius = 0, radius = 0,
style = "square", style = "square",
} }
@ -245,13 +245,13 @@ function MenuItem:init()
padding = 0, padding = 0,
HorizontalGroup:new{ HorizontalGroup:new{
align = "center", align = "center",
HorizontalSpan:new{ width = 5 }, HorizontalSpan:new{ width = Screen:scaleBySize(5) },
ItemShortCutIcon:new{ ItemShortCutIcon:new{
dimen = shortcut_icon_dimen, dimen = shortcut_icon_dimen,
key = self.shortcut, key = self.shortcut,
style = self.shortcut_style, style = self.shortcut_style,
}, },
HorizontalSpan:new{ width = 10 }, HorizontalSpan:new{ width = Screen:scaleBySize(10) },
self._underline_container self._underline_container
} }
} }
@ -332,7 +332,7 @@ local Menu = FocusManager:new{
title = "No Title", title = "No Title",
-- default width and height -- default width and height
width = 500, width = nil,
-- height will be calculated according to item number if not given -- height will be calculated according to item number if not given
height = nil, height = nil,
header_padding = Screen:scaleBySize(10), header_padding = Screen:scaleBySize(10),

@ -1,5 +1,5 @@
--[[-- --[[--
Widget that shows a message and choice1/choice2/Cancel buttons Widget that shows a message and cancel/choice1/choice2 buttons
Example: Example:
@ -42,8 +42,8 @@ local MultiConfirmBox = InputContainer:new{
choice1_callback = function() end, choice1_callback = function() end,
choice2_callback = function() end, choice2_callback = function() end,
cancel_callback = function() end, cancel_callback = function() end,
margin = 5, margin = Screen:scaleBySize(5),
padding = 5, padding = Screen:scaleBySize(5),
} }
function MultiConfirmBox:init() function MultiConfirmBox:init()
@ -52,7 +52,7 @@ function MultiConfirmBox:init()
ImageWidget:new{ ImageWidget:new{
file = "resources/info-i.png" file = "resources/info-i.png"
}, },
HorizontalSpan:new{ width = 10 }, HorizontalSpan:new{ width = Screen:scaleBySize(10) },
TextBoxWidget:new{ TextBoxWidget:new{
text = self.text, text = self.text,
face = self.face, face = self.face,

@ -84,8 +84,8 @@ function MultiInputDialog:init()
}) })
self.dialog_frame = FrameContainer:new{ self.dialog_frame = FrameContainer:new{
radius = 8, radius = Screen:scaleBySize(8),
bordersize = 3, bordersize = Screen:scaleBySize(3),
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -30,33 +30,31 @@ Example:
]] ]]
local FrameContainer = require("ui/widget/container/framecontainer") local Blitbuffer = require("ffi/blitbuffer")
local InputContainer = require("ui/widget/container/inputcontainer")
local LeftContainer = require("ui/widget/container/leftcontainer")
local CenterContainer = require("ui/widget/container/centercontainer") local CenterContainer = require("ui/widget/container/centercontainer")
local RightContainer = require("ui/widget/container/rightcontainer") local Device = require("device")
local Font = require("ui/font")
local Geom = require("ui/geometry")
local FrameContainer = require("ui/widget/container/framecontainer")
local GestureRange = require("ui/gesturerange")
local HorizontalGroup = require("ui/widget/horizontalgroup") local HorizontalGroup = require("ui/widget/horizontalgroup")
local HorizontalSpan = require("ui/widget/horizontalspan") local HorizontalSpan = require("ui/widget/horizontalspan")
local VerticalGroup = require("ui/widget/verticalgroup") local ImageWidget = require("ui/widget/imagewidget")
local OverlapGroup = require("ui/widget/overlapgroup")
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog") local InputDialog = require("ui/widget/inputdialog")
local NetworkMgr = require("ui/network/manager") local LeftContainer = require("ui/widget/container/leftcontainer")
local ListView = require("ui/widget/listview") local ListView = require("ui/widget/listview")
local ImageWidget = require("ui/widget/imagewidget") local RightContainer = require("ui/widget/container/rightcontainer")
local Widget = require("ui/widget/widget") local NetworkMgr = require("ui/network/manager")
local OverlapGroup = require("ui/widget/overlapgroup")
local TextWidget = require("ui/widget/textwidget") local TextWidget = require("ui/widget/textwidget")
local GestureRange = require("ui/gesturerange")
local Blitbuffer = require("ffi/blitbuffer")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local Geom = require("ui/geometry") local VerticalGroup = require("ui/widget/verticalgroup")
local Device = require("device") local Widget = require("ui/widget/widget")
local Screen = Device.screen
local Font = require("ui/font")
local T = require("ffi/util").template
local _ = require("gettext") local _ = require("gettext")
local T = require("ffi/util").template
local Screen = Device.screen
local function obtainIP() local function obtainIP()
-- TODO: check for DHCP result -- TODO: check for DHCP result
@ -421,7 +419,7 @@ function NetworkSetting:init()
self.popup = FrameContainer:new{ self.popup = FrameContainer:new{
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
padding = 0, padding = 0,
bordersize = 3, bordersize = Screen:scaleBySize(3),
VerticalGroup:new{ VerticalGroup:new{
align = "left", align = "left",
self.pagination, self.pagination,

@ -18,8 +18,8 @@ local Notification = InputContainer:new{
face = Font:getFace("x_smallinfofont"), face = Font:getFace("x_smallinfofont"),
text = "Null Message", text = "Null Message",
timeout = nil, timeout = nil,
margin = 5, margin = Screen:scaleBySize(5),
padding = 5, padding = Screen:scaleBySize(5),
} }
function Notification:init() function Notification:init()

@ -27,7 +27,7 @@ local PhysicalNumericKey = WidgetContainer:new{
width = nil, width = nil,
height = nil, height = nil,
bordersize = 2, bordersize = Screen:scaleBySize(2),
face = Font:getFace("infont"), face = Font:getFace("infont"),
pkey_face = Font:getFace("infont", 14), pkey_face = Font:getFace("infont", 14),
} }
@ -41,7 +41,7 @@ function PhysicalNumericKey:init()
margin = 0, margin = 0,
bordersize = self.bordersize, bordersize = self.bordersize,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
radius = 5, radius = Screen:scaleBySize(5),
padding = 0, padding = 0,
CenterContainer:new{ CenterContainer:new{
dimen = Geom:new{ dimen = Geom:new{
@ -69,8 +69,8 @@ end
local PhysicalKeyboard = InputContainer:new{ local PhysicalKeyboard = InputContainer:new{
is_always_active = true, is_always_active = true,
inputbox = nil, -- expect ui/widget/inputtext instance inputbox = nil, -- expect ui/widget/inputtext instance
bordersize = 2, bordersize = Screen:scaleBySize(2),
padding = 2, padding = Screen:scaleBySize(2),
height = math.max(Screen:getWidth(), Screen:getHeight())*0.33, height = math.max(Screen:getWidth(), Screen:getHeight())*0.33,
key_padding = Screen:scaleBySize(6), key_padding = Screen:scaleBySize(6),
} }
@ -124,7 +124,7 @@ end
function PhysicalKeyboard:setupNumericMappingUI() function PhysicalKeyboard:setupNumericMappingUI()
local key_rows = VerticalGroup:new{} local key_rows = VerticalGroup:new{}
local key_margin = 1 local key_margin = Screen:scaleBySize(1)
local row_len = #self.mapping[1] local row_len = #self.mapping[1]
local base_key_width = math.floor((self.width - row_len*(self.key_padding+2*key_margin) - 2*self.padding)/10) local base_key_width = math.floor((self.width - row_len*(self.key_padding+2*key_margin) - 2*self.padding)/10)
local base_key_height = math.floor((self.height - self.key_padding - 2*self.padding)/4) local base_key_height = math.floor((self.height - self.key_padding - 2*self.padding)/4)

@ -19,31 +19,32 @@ Configurable attributes:
Example: Example:
local foo_bar = ProgressWidget:new{ local foo_bar = ProgressWidget:new{
width = 400, width = Screen:scaleBySize(400),
height = 10, height = Screen:scaleBySize(10),
percentage = 50/100, percentage = 50/100,
} }
UIManager:show(foo_bar) UIManager:show(foo_bar)
]] ]]
local Widget = require("ui/widget/widget")
local Geom = require("ui/geometry")
local Blitbuffer = require("ffi/blitbuffer") local Blitbuffer = require("ffi/blitbuffer")
local Geom = require("ui/geometry")
local Widget = require("ui/widget/widget")
local Screen = require("device").screen
local ProgressWidget = Widget:new{ local ProgressWidget = Widget:new{
width = nil, width = nil,
height = nil, height = nil,
margin_h = 3, margin_h = Screen:scaleBySize(3),
margin_v = 1, margin_v = Screen:scaleBySize(1),
radius = 2, radius = Screen:scaleBySize(2),
bordersize = 1, bordersize = Screen:scaleBySize(1),
bordercolor = Blitbuffer.COLOR_BLACK, bordercolor = Blitbuffer.COLOR_BLACK,
bgcolor = Blitbuffer.COLOR_WHITE, bgcolor = Blitbuffer.COLOR_WHITE,
rectcolor = Blitbuffer.gray(0.7), rectcolor = Blitbuffer.gray(0.7),
percentage = nil, percentage = nil,
ticks = nil, ticks = nil,
tick_width = 3, tick_width = Screen:scaleBySize(3),
last = nil, last = nil,
} }

@ -1,19 +1,20 @@
--[[--
Text widget with vertical scroll bar.
--]]
local Blitbuffer = require("ffi/blitbuffer")
local Device = require("device")
local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local HorizontalSpan = require("ui/widget/horizontalspan")
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local TextBoxWidget = require("ui/widget/textboxwidget") local TextBoxWidget = require("ui/widget/textboxwidget")
local VerticalScrollBar = require("ui/widget/verticalscrollbar") local VerticalScrollBar = require("ui/widget/verticalscrollbar")
local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local Device = require("device")
local Screen = Device.screen
local Input = Device.input local Input = Device.input
local HorizontalGroup = require("ui/widget/horizontalgroup") local Screen = Device.screen
local HorizontalSpan = require("ui/widget/horizontalspan")
local Blitbuffer = require("ffi/blitbuffer")
--[[
Text widget with vertical scroll bar
--]]
local ScrollTextWidget = InputContainer:new{ local ScrollTextWidget = InputContainer:new{
text = nil, text = nil,
charlist = nil, charlist = nil,
@ -22,8 +23,8 @@ local ScrollTextWidget = InputContainer:new{
justified = false, justified = false,
face = nil, face = nil,
fgcolor = Blitbuffer.COLOR_BLACK, fgcolor = Blitbuffer.COLOR_BLACK,
width = 400, width = Screen:scaleBySize(400),
height = 20, height = Screen:scaleBySize(20),
scroll_bar_width = Screen:scaleBySize(6), scroll_bar_width = Screen:scaleBySize(6),
text_scroll_span = Screen:scaleBySize(12), text_scroll_span = Screen:scaleBySize(12),
dialog = nil, dialog = nil,

@ -16,11 +16,11 @@ local Blitbuffer = require("ffi/blitbuffer")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local LineWidget = require("ui/widget/linewidget") local LineWidget = require("ui/widget/linewidget")
local RenderText = require("ui/rendertext") local RenderText = require("ui/rendertext")
local Screen = require("device").screen
local TimeVal = require("ui/timeval") local TimeVal = require("ui/timeval")
local Widget = require("ui/widget/widget") local Widget = require("ui/widget/widget")
local logger = require("logger") local logger = require("logger")
local util = require("util") local util = require("util")
local Screen = require("device").screen
local TextBoxWidget = Widget:new{ local TextBoxWidget = Widget:new{
text = nil, text = nil,
@ -35,7 +35,7 @@ local TextBoxWidget = Widget:new{
bold = nil, bold = nil,
line_height = 0.3, -- in em line_height = 0.3, -- in em
fgcolor = Blitbuffer.COLOR_BLACK, fgcolor = Blitbuffer.COLOR_BLACK,
width = 400, -- in pixels width = Screen:scaleBySize(400), -- in pixels
height = nil, -- nil value indicates unscrollable text widget height = nil, -- nil value indicates unscrollable text widget
virtual_line_num = 1, -- used by scroll bar virtual_line_num = 1, -- used by scroll bar
_bb = nil, _bb = nil,

@ -158,8 +158,7 @@ function TextViewer:init()
} }
self.frame = FrameContainer:new{ self.frame = FrameContainer:new{
radius = 8, radius = Screen:scaleBySize(8),
bordersize = 3,
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -144,8 +144,7 @@ function TimeWidget:update()
} }
self.time_frame = FrameContainer:new{ self.time_frame = FrameContainer:new{
radius = 5, radius = Screen:scaleBySize(5),
bordersize = 3,
padding = 0, padding = 0,
margin = 0, margin = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,

@ -1,18 +1,25 @@
local TextWidget = require("ui/widget/textwidget") --[[--
local InputContainer = require("ui/widget/container/inputcontainer") Displays a button that toggles between states. Used in bottom configuration panel.
local FrameContainer = require("ui/widget/container/framecontainer")
@usage
local ToggleSwitch = require("ui/widget/toggleswitch")
]]
local Blitbuffer = require("ffi/blitbuffer")
local CenterContainer = require("ui/widget/container/centercontainer") local CenterContainer = require("ui/widget/container/centercontainer")
local HorizontalGroup = require("ui/widget/horizontalgroup") local Device = require("device")
local VerticalGroup = require("ui/widget/verticalgroup")
local Font = require("ui/font") local Font = require("ui/font")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local InputContainer = require("ui/widget/container/inputcontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local RenderText = require("ui/rendertext") local RenderText = require("ui/rendertext")
local TextWidget = require("ui/widget/textwidget")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local Screen = require("device").screen local VerticalGroup = require("ui/widget/verticalgroup")
local Device = require("device")
local GestureRange = require("ui/gesturerange")
local Blitbuffer = require("ffi/blitbuffer")
local _ = require("gettext") local _ = require("gettext")
local Screen = Device.screen
local ToggleLabel = TextWidget:new{ local ToggleLabel = TextWidget:new{
bold = true, bold = true,
@ -27,7 +34,7 @@ end
local ToggleSwitch = InputContainer:new{ local ToggleSwitch = InputContainer:new{
width = Screen:scaleBySize(216), width = Screen:scaleBySize(216),
height = Screen:scaleBySize(30), height = Screen:scaleBySize(30),
bgcolor = Blitbuffer.COLOR_WHITE, -- unfoused item color bgcolor = Blitbuffer.COLOR_WHITE, -- unfocused item color
fgcolor = Blitbuffer.COLOR_GREY, -- focused item color fgcolor = Blitbuffer.COLOR_GREY, -- focused item color
font_face = "cfont", font_face = "cfont",
font_size = 16, font_size = 16,
@ -43,9 +50,9 @@ function ToggleSwitch:init()
self.toggle_frame = FrameContainer:new{ self.toggle_frame = FrameContainer:new{
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
color = Blitbuffer.COLOR_GREY, color = Blitbuffer.COLOR_GREY,
radius = 7, radius = Screen:scaleBySize(7),
bordersize = 1, bordersize = Screen:scaleBySize(1),
padding = 2, padding = Screen:scaleBySize(2),
dim = not self.enabled, dim = not self.enabled,
} }
@ -72,8 +79,8 @@ function ToggleSwitch:init()
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
color = Blitbuffer.COLOR_GREY, color = Blitbuffer.COLOR_GREY,
margin = 0, margin = 0,
radius = 5, radius = Screen:scaleBySize(5),
bordersize = 1, bordersize = Screen:scaleBySize(1),
padding = 0, padding = 0,
content, content,
} }

@ -431,7 +431,7 @@ function TouchMenu:init()
self.item_width = self.width - self.padding*2 - self.bordersize*2 self.item_width = self.width - self.padding*2 - self.bordersize*2
self.split_line = HorizontalGroup:new{ self.split_line = HorizontalGroup:new{
-- pad with 10 pixel to align with the up arrow in footer -- pad with 10 pixel to align with the up arrow in footer
HorizontalSpan:new{width = 10}, HorizontalSpan:new{width = Screen:scaleBySize(10)},
LineWidget:new{ LineWidget:new{
background = Blitbuffer.gray(0.33), background = Blitbuffer.gray(0.33),
dimen = Geom:new{ dimen = Geom:new{

@ -1,14 +1,15 @@
local Blitbuffer = require("ffi/blitbuffer") local Blitbuffer = require("ffi/blitbuffer")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local Widget = require("ui/widget/widget") local Widget = require("ui/widget/widget")
local Screen = require("device").screen
local VerticalScrollBar = Widget:new{ local VerticalScrollBar = Widget:new{
enable = true, enable = true,
low = 0, low = 0,
high = 1, high = 1,
width = 6, width = Screen:scaleBySize(6),
height = 50, height = Screen:scaleBySize(50),
bordersize = 1, bordersize = Screen:scaleBySize(1),
bordercolor = Blitbuffer.COLOR_BLACK, bordercolor = Blitbuffer.COLOR_BLACK,
radius = 0, radius = 0,
rectcolor = Blitbuffer.COLOR_BLACK, rectcolor = Blitbuffer.COLOR_BLACK,

@ -27,7 +27,7 @@ local VirtualKey = InputContainer:new{
width = nil, width = nil,
height = math.max(Screen:getWidth(), Screen:getHeight())*0.33, height = math.max(Screen:getWidth(), Screen:getHeight())*0.33,
bordersize = 2, bordersize = Screen:scaleBySize(2),
face = Font:getFace("infont"), face = Font:getFace("infont"),
} }
@ -62,7 +62,7 @@ function VirtualKey:init()
margin = 0, margin = 0,
bordersize = self.bordersize, bordersize = self.bordersize,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
radius = 5, radius = Screen:scaleBySize(5),
padding = 0, padding = 0,
CenterContainer:new{ CenterContainer:new{
dimen = Geom:new{ dimen = Geom:new{

@ -44,9 +44,9 @@ local corner_mark = ImageWidget:new{
-- ItemShortCutIcon (for keyboard navigation) is private to menu.lua and can't be accessed, -- ItemShortCutIcon (for keyboard navigation) is private to menu.lua and can't be accessed,
-- so we need to redefine it -- so we need to redefine it
local ItemShortCutIcon = WidgetContainer:new{ local ItemShortCutIcon = WidgetContainer:new{
dimen = Geom:new{ w = 22, h = 22 }, dimen = Geom:new{ w = Screen:scaleBySize(22), h = Screen:scaleBySize(22) },
key = nil, key = nil,
bordersize = 2, bordersize = Screen:scaleBySize(2),
radius = 0, radius = 0,
style = "square", style = "square",
} }
@ -698,10 +698,8 @@ end
function ListMenu:_updateItemsBuildUI() function ListMenu:_updateItemsBuildUI()
-- Build our list -- Build our list
-- We separate items with a 1px LineWidget (no need for
-- scaleBySize, thin is fine)
table.insert(self.item_group, LineWidget:new{ table.insert(self.item_group, LineWidget:new{
dimen = Geom:new{ w = self.width, h = 1 }, dimen = Geom:new{ w = self.width, h = Screen:scaleBySize(1) },
background = Blitbuffer.COLOR_GREY, background = Blitbuffer.COLOR_GREY,
style = "solid", style = "solid",
}) })
@ -742,7 +740,7 @@ function ListMenu:_updateItemsBuildUI()
} }
table.insert(self.item_group, item_tmp) table.insert(self.item_group, item_tmp)
table.insert(self.item_group, LineWidget:new{ table.insert(self.item_group, LineWidget:new{
dimen = Geom:new{ w = self.width, h = 1 }, dimen = Geom:new{ w = self.width, h = Screen:scaleBySize(1) },
background = Blitbuffer.COLOR_GREY, background = Blitbuffer.COLOR_GREY,
style = "solid", style = "solid",
}) })

@ -13,6 +13,7 @@ local ImageWidget = require("ui/widget/imagewidget")
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local OverlapGroup = require("ui/widget/overlapgroup") local OverlapGroup = require("ui/widget/overlapgroup")
local Size = require("ui/size")
local TextBoxWidget = require("ui/widget/textboxwidget") local TextBoxWidget = require("ui/widget/textboxwidget")
local TextWidget = require("ui/widget/textwidget") local TextWidget = require("ui/widget/textwidget")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
@ -41,9 +42,9 @@ local corner_mark = ImageWidget:new{
-- ItemShortCutIcon (for keyboard navigation) is private to menu.lua and can't be accessed, -- ItemShortCutIcon (for keyboard navigation) is private to menu.lua and can't be accessed,
-- so we need to redefine it -- so we need to redefine it
local ItemShortCutIcon = WidgetContainer:new{ local ItemShortCutIcon = WidgetContainer:new{
dimen = Geom:new{ w = 22, h = 22 }, dimen = Geom:new{ w = Screen:scaleBySize(22), h = Screen:scaleBySize(22) },
key = nil, key = nil,
bordersize = 2, bordersize = Screen:scaleBySize(2),
radius = 0, radius = 0,
style = "square", style = "square",
} }
@ -92,7 +93,7 @@ local FakeCover = FrameContainer:new{
height = nil, height = nil,
margin = 0, margin = 0,
padding = 0, padding = 0,
bordersize = 1, bordersize = Size.line.thin,
dim = nil, dim = nil,
filename = nil, filename = nil,
file_deleted = nil, file_deleted = nil,

@ -53,7 +53,7 @@ function DoubleKeyValueTitle:init()
}) })
-- page count and separation line -- page count and separation line
self.page_cnt = FrameContainer:new{ self.page_cnt = FrameContainer:new{
padding = 4, padding = Screen:scaleBySize(4),
margin = 0, margin = 0,
bordersize = 0, bordersize = 0,
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
@ -129,31 +129,31 @@ function DoubleKeyValueItem:init()
local h = self.dimen.h / 2 local h = self.dimen.h / 2
local w = self.dimen.w local w = self.dimen.w
self[1] = FrameContainer:new{ self[1] = FrameContainer:new{
padding = 10, padding = Screen:scaleBySize(10),
bordersize = 0, bordersize = 0,
VerticalGroup:new{ VerticalGroup:new{
dimen = Geom:new{ h = h, w = w }, dimen = Geom:new{ h = h, w = w },
padding = 10, padding = Screen:scaleBySize(10),
LeftContainer:new{ LeftContainer:new{
padding = 10, padding = Screen:scaleBySize(10),
dimen = Geom:new{ h = h, w = w }, dimen = Geom:new{ h = h, w = w },
TextWidget:new{ TextWidget:new{
text = self.show_value, text = self.show_value,
padding = 10, padding = Screen:scaleBySize(10),
face = self.cface_up, face = self.cface_up,
} }
}, },
LeftContainer:new{ LeftContainer:new{
padding = 10, padding = Screen:scaleBySize(10),
dimen = Geom:new{ h = h / 5 , w = w }, dimen = Geom:new{ h = h / 5 , w = w },
HorizontalSpan:new{ width = Screen:scaleBySize(15), height = 3 } HorizontalSpan:new{ width = Screen:scaleBySize(15), height = 3 }
}, },
LeftContainer:new{ LeftContainer:new{
padding = 10, padding = Screen:scaleBySize(10),
dimen = Geom:new{ h = h, w = w }, dimen = Geom:new{ h = h, w = w },
TextWidget:new{ TextWidget:new{
text = self.show_key, text = self.show_key,
padding = 10, padding = Screen:scaleBySize(10),
face = self.cface_down, face = self.cface_down,
} }
} }

@ -112,7 +112,7 @@ function GoodreadsBook:genBookInfoGroup()
TextBoxWidget:new{ TextBoxWidget:new{
text = self.dates.title, text = self.dates.title,
face = self.medium_font_face, face = self.medium_font_face,
padding = 2, padding = Screen:scaleBySize(2),
alignment = "center", alignment = "center",
width = width, width = width,
}, },
@ -142,7 +142,7 @@ function GoodreadsBook:genBookInfoGroup()
local text_series = TextWidget:new{ local text_series = TextWidget:new{
text = T(_("Series: %1"), self.dates.series), text = T(_("Series: %1"), self.dates.series),
face = self.small_font_face, face = self.small_font_face,
padding = 2, padding = Screen:scaleBySize(2),
} }
table.insert(book_meta_info_group, table.insert(book_meta_info_group,
CenterContainer:new{ CenterContainer:new{
@ -154,7 +154,7 @@ function GoodreadsBook:genBookInfoGroup()
local text_rating = TextWidget:new{ local text_rating = TextWidget:new{
text = T(_("Rating: %1"), self.dates.rating), text = T(_("Rating: %1"), self.dates.rating),
face = self.small_font_face, face = self.small_font_face,
padding = 2, padding = Screen:scaleBySize(2),
} }
table.insert(book_meta_info_group, table.insert(book_meta_info_group,
CenterContainer:new{ CenterContainer:new{
@ -166,7 +166,7 @@ function GoodreadsBook:genBookInfoGroup()
local text_pages = TextWidget:new{ local text_pages = TextWidget:new{
text = T(_("Pages: %1"), self.dates.pages), text = T(_("Pages: %1"), self.dates.pages),
face = self.small_font_face, face = self.small_font_face,
padding = 2, padding = Screen:scaleBySize(2),
} }
table.insert(book_meta_info_group, table.insert(book_meta_info_group,
CenterContainer:new{ CenterContainer:new{
@ -178,7 +178,7 @@ function GoodreadsBook:genBookInfoGroup()
local text_release = TextWidget:new{ local text_release = TextWidget:new{
text = T(_("Release date: %1"), self.dates.release), text = T(_("Release date: %1"), self.dates.release),
face = self.small_font_face, face = self.small_font_face,
padding = 2, padding = Screen:scaleBySize(2),
} }
table.insert(book_meta_info_group, table.insert(book_meta_info_group,
CenterContainer:new{ CenterContainer:new{

@ -210,11 +210,11 @@ function ReaderProgress:genWeekStats(stats_day)
date_format_show = dayOfWeekTranslation[os.date("%A", diff_time)] .. os.date(" (%d.%m)", diff_time) date_format_show = dayOfWeekTranslation[os.date("%A", diff_time)] .. os.date(" (%d.%m)", diff_time)
local total_group = HorizontalGroup:new{ local total_group = HorizontalGroup:new{
align = "center", align = "center",
padding = 2, padding = Screen:scaleBySize(2),
LeftContainer:new{ LeftContainer:new{
dimen = Geom:new{ w = self.screen_width , h = height / 3 }, dimen = Geom:new{ w = self.screen_width , h = height / 3 },
TextWidget:new{ TextWidget:new{
padding = 2, padding = Screen:scaleBySize(2),
text = date_format_show .. " - " .. util.secondsToClock(select_day_time, true), text = date_format_show .. " - " .. util.secondsToClock(select_day_time, true),
face = Font:getFace("smallffont"), face = Font:getFace("smallffont"),
}, },
@ -353,7 +353,7 @@ function ReaderProgress:genSummaryWeek(width)
CenterContainer:new{ CenterContainer:new{
dimen = Geom:new{ w = tile_width, h = tile_height }, dimen = Geom:new{ w = tile_width, h = tile_height },
TextWidget:new{ TextWidget:new{
padding = 5, padding = Screen:scaleBySize(5),
text = _("Total"), text = _("Total"),
face = self.small_font_face, face = self.small_font_face,
}, },

@ -8,8 +8,8 @@ describe("ProgressWidget widget", function()
it("should not crash with nil self.last", function() it("should not crash with nil self.last", function()
local progress = ProgressWidget:new{ local progress = ProgressWidget:new{
width = 100, width = Screen:scaleBySize(100),
height = 50, height = Screen:scaleBySize(50),
percentage = 5/100, percentage = 5/100,
ticks = {1}, ticks = {1},
} }

@ -172,9 +172,9 @@ Clock = AlphaContainer:new{
FrameContainer:new{ FrameContainer:new{
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
bordersize = 1, bordersize = Screen:scaleBySize(1),
margin = 0, margin = 0,
padding = 1 padding = Screen:scaleBySize(1),
} }
} }
@ -206,7 +206,7 @@ end
----------------------------------------------------- -----------------------------------------------------
Quiz = ConfirmBox:new{ Quiz = ConfirmBox:new{
text = "Tell me the truth, isn't it COOL?!", text = "Tell me the truth, isn't it COOL?!",
width = 300, width = Screen:scaleBySize(300),
ok_text = "Yes, of course.", ok_text = "Yes, of course.",
cancel_text = "No, it's ugly.", cancel_text = "No, it's ugly.",
cancel_callback = function() cancel_callback = function()
@ -242,8 +242,8 @@ menu_items = {
M = Menu:new{ M = Menu:new{
title = "Test Menu", title = "Test Menu",
item_table = menu_items, item_table = menu_items,
width = 500, width = Screen:scaleBySize(500),
height = 600, height = Screen:scaleBySize(600),
} }
----------------------------------------------------- -----------------------------------------------------
@ -329,7 +329,7 @@ touch_menu = TouchMenu:new{
-- input box widget -- input box widget
----------------------------------------------------- -----------------------------------------------------
local TestInputText = InputText:new{ local TestInputText = InputText:new{
width = 400, width = Screen:scaleBySize(400),
enter_callback = function() print("Entered") end, enter_callback = function() print("Entered") end,
scroll = false, scroll = false,
input_type = "number", input_type = "number",

Loading…
Cancel
Save