2017-09-13 14:56:20 +00:00
|
|
|
--[[--
|
|
|
|
This module provides a standardized set of sizes for use in widgets.
|
|
|
|
|
|
|
|
There are values for borders, margins, paddings, radii, and lines. Have a look
|
|
|
|
at the code for full details. If you are considering to deviate from one of the
|
|
|
|
defaults, please take a second to consider:
|
|
|
|
|
|
|
|
1. Why you want to differ in the first place. We consciously strive toward
|
|
|
|
consistency in the UI, which is typically valued higher than one pixel more
|
|
|
|
or less in a specific context.
|
|
|
|
2. If there really isn't anything close to what you want, whether it should be
|
|
|
|
added to the arsenal of default sizes rather than as a local exception.
|
|
|
|
|
|
|
|
@usage
|
|
|
|
local Size = require("ui/size")
|
|
|
|
local frame -- just an example widget
|
|
|
|
frame = FrameContainer:new{
|
|
|
|
radius = Size.radius.window,
|
|
|
|
bordersize = Size.border.window,
|
|
|
|
padding = Size.padding.default,
|
|
|
|
margin = Size.margin.default,
|
|
|
|
VerticalGroup:new{
|
|
|
|
-- etc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]]
|
|
|
|
|
|
|
|
local dbg = require("dbg")
|
|
|
|
local Screen = require("device").screen
|
|
|
|
|
|
|
|
local Size = {
|
|
|
|
border = {
|
2017-09-28 14:25:00 +00:00
|
|
|
default = Screen:scaleBySize(1),
|
|
|
|
thin = Screen:scaleBySize(0.5),
|
|
|
|
button = Screen:scaleBySize(1.5),
|
|
|
|
window = Screen:scaleBySize(1.5),
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
inputtext = Screen:scaleBySize(2),
|
2017-09-13 14:56:20 +00:00
|
|
|
},
|
|
|
|
margin = {
|
|
|
|
default = Screen:scaleBySize(5),
|
|
|
|
tiny = Screen:scaleBySize(1),
|
|
|
|
small = Screen:scaleBySize(2),
|
|
|
|
title = Screen:scaleBySize(2),
|
2019-09-26 09:46:23 +00:00
|
|
|
fine_tune = Screen:scaleBySize(3),
|
2017-09-13 14:56:20 +00:00
|
|
|
button = 0,
|
|
|
|
},
|
|
|
|
padding = {
|
|
|
|
default = Screen:scaleBySize(5),
|
|
|
|
tiny = Screen:scaleBySize(1),
|
|
|
|
small = Screen:scaleBySize(2),
|
|
|
|
large = Screen:scaleBySize(10),
|
|
|
|
button = Screen:scaleBySize(2),
|
2019-11-01 00:52:05 +00:00
|
|
|
buttontable = Screen:scaleBySize(4),
|
2017-09-13 14:56:20 +00:00
|
|
|
fullscreen = Screen:scaleBySize(15),
|
|
|
|
},
|
|
|
|
radius = {
|
|
|
|
default = Screen:scaleBySize(2),
|
|
|
|
window = Screen:scaleBySize(7),
|
|
|
|
button = Screen:scaleBySize(15),
|
|
|
|
},
|
|
|
|
line = {
|
|
|
|
thin = Screen:scaleBySize(0.5),
|
|
|
|
medium = Screen:scaleBySize(1),
|
|
|
|
thick = Screen:scaleBySize(1.5),
|
2019-11-10 20:27:49 +00:00
|
|
|
progress = Screen:scaleBySize(7),
|
2017-09-13 14:56:20 +00:00
|
|
|
},
|
|
|
|
item = {
|
|
|
|
height_default = Screen:scaleBySize(30),
|
2019-09-17 12:50:03 +00:00
|
|
|
height_big = Screen:scaleBySize(40),
|
2017-09-13 14:56:20 +00:00
|
|
|
height_large = Screen:scaleBySize(50),
|
|
|
|
},
|
|
|
|
span = {
|
|
|
|
horizontal_default = Screen:scaleBySize(10),
|
|
|
|
horizontal_small = Screen:scaleBySize(5),
|
|
|
|
vertical_default = Screen:scaleBySize(2),
|
|
|
|
vertical_large = Screen:scaleBySize(5),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if dbg.is_on then
|
|
|
|
local mt = {
|
|
|
|
__index = function(t, k)
|
|
|
|
local prop_value = rawget(t, k)
|
|
|
|
local prop_exists = prop_value ~= nil
|
|
|
|
if not prop_exists then
|
|
|
|
local warning = rawget(t, "_name") and string.format("Size.%s.%s", rawget(t, "_name"), k)
|
|
|
|
or string.format("Size.%s", k)
|
|
|
|
error("Size: this property does not exist: " .. warning)
|
|
|
|
end
|
|
|
|
assert(prop_exists)
|
|
|
|
return prop_value
|
|
|
|
end
|
|
|
|
}
|
|
|
|
setmetatable(Size, mt)
|
|
|
|
for el, table in pairs(Size) do
|
|
|
|
table._name = el
|
|
|
|
setmetatable(Size[el], mt)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return Size
|