2017-04-29 08:38:09 +00:00
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
|
local Button = require("ui/widget/button")
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local ButtonProgressWidget = require("ui/widget/buttonprogresswidget")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
|
local Device = require("device")
|
2022-03-04 20:20:00 +00:00
|
|
|
|
local FocusManager = require("ui/widget/focusmanager")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local Geom = require("ui/geometry")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local Font = require("ui/font")
|
|
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
2019-09-26 22:38:44 +00:00
|
|
|
|
local Math = require("optmath")
|
2018-03-08 21:23:05 +00:00
|
|
|
|
local NaturalLight = require("ui/widget/naturallightwidget")
|
2019-09-26 22:38:44 +00:00
|
|
|
|
local ProgressWidget = require("ui/widget/progresswidget")
|
2017-09-13 14:56:20 +00:00
|
|
|
|
local Size = require("ui/size")
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2022-02-03 11:03:33 +00:00
|
|
|
|
local TitleBar = require("ui/widget/titlebar")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2022-05-05 19:00:22 +00:00
|
|
|
|
local time = require("ui/time")
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local _ = require("gettext")
|
2022-05-23 22:25:50 +00:00
|
|
|
|
local C_ = _.pgettext
|
2017-04-29 08:38:09 +00:00
|
|
|
|
local Screen = Device.screen
|
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
|
local FrontLightWidget = FocusManager:extend{
|
2022-05-09 06:36:13 +00:00
|
|
|
|
name = "FrontLightWidget",
|
2016-12-01 17:58:06 +00:00
|
|
|
|
width = nil,
|
|
|
|
|
height = nil,
|
2018-03-08 21:23:05 +00:00
|
|
|
|
-- This should stay active during natural light configuration
|
|
|
|
|
is_always_active = true,
|
2019-09-26 22:38:44 +00:00
|
|
|
|
rate = Screen.low_pan_rate and 3 or 30, -- Widget update rate.
|
2022-05-05 19:00:22 +00:00
|
|
|
|
last_time = 0, -- Tracks last update time to prevent update spamming.
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:init()
|
2022-03-14 18:56:18 +00:00
|
|
|
|
-- Layout constants
|
2017-04-29 08:38:09 +00:00
|
|
|
|
self.medium_font_face = Font:getFace("ffont")
|
2017-09-13 14:56:20 +00:00
|
|
|
|
self.screen_width = Screen:getWidth()
|
|
|
|
|
self.screen_height = Screen:getHeight()
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.span = Math.round(self.screen_height * 0.01)
|
2020-06-12 23:56:36 +00:00
|
|
|
|
self.width = math.floor(self.screen_width * 0.95)
|
2022-03-14 18:56:18 +00:00
|
|
|
|
|
|
|
|
|
-- State constants
|
2018-02-08 21:13:59 +00:00
|
|
|
|
self.powerd = Device:getPowerDevice()
|
2022-03-14 18:56:18 +00:00
|
|
|
|
|
|
|
|
|
-- Frontlight
|
|
|
|
|
self.fl = {}
|
|
|
|
|
self.fl.min = self.powerd.fl_min
|
|
|
|
|
self.fl.max = self.powerd.fl_max
|
|
|
|
|
self.fl.cur = self.powerd:frontlightIntensity()
|
|
|
|
|
local fl_steps = self.fl.max - self.fl.min + 1
|
2022-10-10 20:21:27 +00:00
|
|
|
|
self.fl.stride = math.ceil(fl_steps * (1/25))
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.fl.steps = math.ceil(fl_steps / self.fl.stride)
|
|
|
|
|
if (self.fl.steps - 1) * self.fl.stride < self.fl.max - self.fl.min then
|
|
|
|
|
self.fl.steps = self.fl.steps + 1
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.fl.steps = math.min(self.fl.steps, fl_steps)
|
|
|
|
|
|
|
|
|
|
-- Warmth
|
|
|
|
|
self.has_nl = Device:hasNaturalLight()
|
2019-04-12 20:46:10 +00:00
|
|
|
|
self.has_nl_mixer = Device:hasNaturalLightMixer()
|
2020-08-19 20:41:10 +00:00
|
|
|
|
self.has_nl_api = Device:hasNaturalLightApi()
|
2022-03-14 18:56:18 +00:00
|
|
|
|
if self.has_nl then
|
|
|
|
|
self.nl = {}
|
|
|
|
|
self.nl.min = self.powerd.fl_warmth_min
|
|
|
|
|
self.nl.max = self.powerd.fl_warmth_max
|
|
|
|
|
self.nl.cur = self.powerd:toNativeWarmth(self.powerd:frontlightWarmth())
|
|
|
|
|
|
|
|
|
|
local nl_steps = self.nl.max - self.nl.min + 1
|
2022-10-10 20:21:27 +00:00
|
|
|
|
self.nl.stride = math.ceil(nl_steps * (1/25))
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.nl.steps = math.ceil(nl_steps / self.nl.stride)
|
|
|
|
|
if (self.nl.steps - 1) * self.nl.stride < self.nl.max - self.nl.min then
|
|
|
|
|
self.nl.steps = self.nl.steps + 1
|
|
|
|
|
end
|
|
|
|
|
self.nl.steps = math.min(self.nl.steps, nl_steps)
|
2018-12-28 03:32:42 +00:00
|
|
|
|
end
|
2017-10-08 15:53:25 +00:00
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
|
-- Input
|
2016-12-01 17:58:06 +00:00
|
|
|
|
if Device:hasKeys() then
|
2022-10-27 00:01:51 +00:00
|
|
|
|
self.key_events.Close = { { Device.input.group.Back } }
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end
|
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
|
self.ges_events = {
|
2019-09-26 22:38:44 +00:00
|
|
|
|
TapProgress = {
|
2016-12-01 17:58:06 +00:00
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "tap",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = self.screen_width,
|
|
|
|
|
h = self.screen_height,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-09-26 22:38:44 +00:00
|
|
|
|
PanProgress = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "pan",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = self.screen_width,
|
|
|
|
|
h = self.screen_height,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
|
-- Widget layout
|
|
|
|
|
self:layout()
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
|
function FrontLightWidget:layout()
|
|
|
|
|
self.layout = {}
|
2017-08-29 15:37:08 +00:00
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local main_container = CenterContainer:new{
|
|
|
|
|
dimen = Geom:new{
|
|
|
|
|
w = self.width,
|
|
|
|
|
h = math.floor(self.screen_height * 0.2),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- Frontlight
|
|
|
|
|
-- Bigger spans, as ProgressWidget appears to be ever so slightly smaller than ButtonProgressWidget ;).
|
|
|
|
|
local fl_padding_span = VerticalSpan:new{ width = Math.round(self.span * 1.5) }
|
|
|
|
|
local fl_group_above = HorizontalGroup:new{ align = "center" }
|
|
|
|
|
local fl_group_below = HorizontalGroup:new{ align = "center" }
|
|
|
|
|
local main_group = VerticalGroup:new{ align = "center" }
|
2016-12-01 17:58:06 +00:00
|
|
|
|
|
2019-09-26 22:38:44 +00:00
|
|
|
|
local ticks = {}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
for i = 1, self.fl.steps - 2 do
|
|
|
|
|
table.insert(ticks, i * self.fl.stride)
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end
|
2019-09-26 22:38:44 +00:00
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.fl_progress = ProgressWidget:new{
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.9),
|
2019-09-26 22:38:44 +00:00
|
|
|
|
height = Size.item.height_big,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
percentage = self.fl.cur / self.fl.max,
|
2019-09-26 22:38:44 +00:00
|
|
|
|
ticks = ticks,
|
|
|
|
|
tick_width = Screen:scaleBySize(0.5),
|
2022-03-14 18:56:18 +00:00
|
|
|
|
last = self.fl.max,
|
2019-09-26 22:38:44 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local fl_header = TextWidget:new{
|
2018-02-08 21:14:57 +00:00
|
|
|
|
text = _("Brightness"),
|
|
|
|
|
face = self.medium_font_face,
|
|
|
|
|
bold = true,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
max_width = math.floor(self.screen_width * 0.95),
|
2018-02-08 21:14:57 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.fl_minus = Button:new{
|
|
|
|
|
text = "−",
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
radius = 0,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
enabled = self.fl.cur ~= self.fl.min,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2016-12-01 17:58:06 +00:00
|
|
|
|
show_parent = self,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
callback = function()
|
|
|
|
|
self:setBrightness(self.fl.cur - 1)
|
|
|
|
|
end,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.fl_plus = Button:new{
|
|
|
|
|
text = "+",
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
radius = 0,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
enabled = self.fl.cur ~= self.fl.max,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2016-12-01 17:58:06 +00:00
|
|
|
|
show_parent = self,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
callback = function()
|
|
|
|
|
self:setBrightness(self.fl.cur + 1)
|
|
|
|
|
end,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.fl_level = TextWidget:new{
|
|
|
|
|
text = tostring(self.fl.cur),
|
2016-12-01 17:58:06 +00:00
|
|
|
|
face = self.medium_font_face,
|
2022-10-10 20:21:27 +00:00
|
|
|
|
max_width = math.floor(self.screen_width * 0.95 - 1.275 * (self.fl_minus.width + self.fl_plus.width)),
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local fl_level_container = CenterContainer:new{
|
|
|
|
|
dimen = Geom:new{
|
|
|
|
|
w = self.fl_level.max_width,
|
|
|
|
|
h = self.fl_level:getSize().h
|
|
|
|
|
},
|
|
|
|
|
self.fl_level,
|
|
|
|
|
}
|
|
|
|
|
local fl_min = Button:new{
|
2022-05-23 22:25:50 +00:00
|
|
|
|
text = C_("Extrema", "Min"),
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
radius = 0,
|
2020-08-06 11:14:29 +00:00
|
|
|
|
enabled = true,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2016-12-01 17:58:06 +00:00
|
|
|
|
show_parent = self,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
callback = function()
|
|
|
|
|
self:setBrightness(self.fl.min + 1)
|
|
|
|
|
end, -- min is 1 (We use 0 to mean "toggle")
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local fl_max = Button:new{
|
2022-05-23 22:25:50 +00:00
|
|
|
|
text = C_("Extrema", "Max"),
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
radius = 0,
|
2020-08-06 11:14:29 +00:00
|
|
|
|
enabled = true,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2016-12-01 17:58:06 +00:00
|
|
|
|
show_parent = self,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
callback = function()
|
|
|
|
|
self:setBrightness(self.fl.max)
|
|
|
|
|
end,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local fl_toggle = Button:new{
|
2016-12-01 17:58:06 +00:00
|
|
|
|
text = _("Toggle"),
|
2017-09-13 14:56:20 +00:00
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
radius = 0,
|
2020-08-06 11:14:29 +00:00
|
|
|
|
enabled = true,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2016-12-01 17:58:06 +00:00
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function()
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self:setBrightness(self.fl.min)
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end,
|
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local fl_spacer = HorizontalSpan:new{
|
2022-10-10 20:21:27 +00:00
|
|
|
|
width = math.floor((self.screen_width * 0.95 - 1.2 * (self.fl_minus.width + self.fl_plus.width + fl_toggle.width)) / 2),
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local fl_buttons_above = HorizontalGroup:new{
|
2016-12-01 17:58:06 +00:00
|
|
|
|
align = "center",
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.fl_minus,
|
|
|
|
|
fl_level_container,
|
|
|
|
|
self.fl_plus,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.layout[1] = {self.fl_minus, self.fl_plus}
|
|
|
|
|
local fl_buttons_below = HorizontalGroup:new{
|
2016-12-01 17:58:06 +00:00
|
|
|
|
align = "center",
|
2022-03-14 18:56:18 +00:00
|
|
|
|
fl_min,
|
|
|
|
|
fl_spacer,
|
|
|
|
|
fl_toggle,
|
|
|
|
|
fl_spacer,
|
|
|
|
|
fl_max,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.layout[2] = {fl_min, fl_toggle, fl_max}
|
|
|
|
|
|
|
|
|
|
if self.has_nl then
|
|
|
|
|
-- Only insert a "Brightness" caption if we also add the full set of warmth widgets below,
|
|
|
|
|
-- otherwise, it's implied by the title bar ;).
|
|
|
|
|
table.insert(main_group, fl_header)
|
2018-02-08 21:14:57 +00:00
|
|
|
|
end
|
2022-03-14 18:56:18 +00:00
|
|
|
|
table.insert(fl_group_above, fl_buttons_above)
|
|
|
|
|
table.insert(fl_group_below, fl_buttons_below)
|
|
|
|
|
table.insert(main_group, fl_padding_span)
|
|
|
|
|
table.insert(main_group, fl_group_above)
|
|
|
|
|
table.insert(main_group, fl_padding_span)
|
|
|
|
|
table.insert(main_group, self.fl_progress)
|
|
|
|
|
table.insert(main_group, fl_padding_span)
|
|
|
|
|
table.insert(main_group, fl_group_below)
|
|
|
|
|
table.insert(main_group, fl_padding_span)
|
|
|
|
|
|
|
|
|
|
-- Warmth
|
|
|
|
|
if self.has_nl then
|
|
|
|
|
-- Smaller spans, as ButtonProgressWidget appears to be ever so slightly taller than ProgressWidget ;).
|
|
|
|
|
local nl_padding_span = VerticalSpan:new{ width = self.span }
|
|
|
|
|
local nl_group_above = HorizontalGroup:new{ align = "center" }
|
|
|
|
|
local nl_group_below = HorizontalGroup:new{ align = "center" }
|
|
|
|
|
|
|
|
|
|
self.nl_progress = ButtonProgressWidget:new{
|
|
|
|
|
width = math.floor(self.screen_width * 0.9),
|
|
|
|
|
font_size = 20, -- match Button's default
|
|
|
|
|
padding = 0,
|
|
|
|
|
thin_grey_style = false,
|
|
|
|
|
num_buttons = self.nl.steps - 1, -- no button for step 0
|
|
|
|
|
position = math.floor(self.nl.cur / self.nl.stride),
|
|
|
|
|
default_position = math.floor(self.nl.cur / self.nl.stride),
|
|
|
|
|
callback = function(i)
|
2022-03-22 08:58:29 +00:00
|
|
|
|
self:setWarmth(Math.round(i * self.nl.stride), false)
|
2022-03-14 18:56:18 +00:00
|
|
|
|
end,
|
|
|
|
|
show_parent = self,
|
|
|
|
|
enabled = true,
|
|
|
|
|
}
|
|
|
|
|
-- We want a wider gap between the two sets of widgets
|
|
|
|
|
local nl_span = VerticalSpan:new{ width = Size.span.vertical_large * 4 }
|
|
|
|
|
local nl_header = TextWidget:new{
|
|
|
|
|
text = _("Warmth"),
|
|
|
|
|
face = self.medium_font_face,
|
|
|
|
|
bold = true,
|
|
|
|
|
max_width = math.floor(self.screen_width * 0.95),
|
|
|
|
|
}
|
|
|
|
|
self.nl_minus = Button:new{
|
|
|
|
|
text = "−",
|
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
|
|
|
|
enabled = self.nl.cur ~= self.nl.min,
|
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function()
|
|
|
|
|
self:setWarmth(self.nl.cur - 1, true) end,
|
|
|
|
|
}
|
|
|
|
|
self.nl_plus = Button:new{
|
|
|
|
|
text = "+",
|
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
|
|
|
|
enabled = self.nl.cur ~= self.nl.max,
|
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function()
|
|
|
|
|
self:setWarmth(self.nl.cur + 1, true) end,
|
|
|
|
|
}
|
|
|
|
|
self.nl_level = TextWidget:new{
|
|
|
|
|
text = tostring(self.nl.cur),
|
|
|
|
|
face = self.medium_font_face,
|
2022-10-10 20:21:27 +00:00
|
|
|
|
max_width = math.floor(self.screen_width * 0.95 - 1.275 * (self.nl_minus.width + self.nl_plus.width)),
|
2022-03-14 18:56:18 +00:00
|
|
|
|
}
|
|
|
|
|
local nl_level_container = CenterContainer:new{
|
|
|
|
|
dimen = Geom:new{
|
|
|
|
|
w = self.nl_level.max_width,
|
|
|
|
|
h = self.nl_level:getSize().h
|
|
|
|
|
},
|
|
|
|
|
self.nl_level,
|
|
|
|
|
}
|
|
|
|
|
local nl_min = Button:new{
|
2022-05-23 22:25:50 +00:00
|
|
|
|
text = C_("Extrema", "Min"),
|
2022-03-14 18:56:18 +00:00
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
|
|
|
|
enabled = true,
|
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function()
|
|
|
|
|
self:setWarmth(self.nl.min, true)
|
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
|
local nl_max = Button:new{
|
2022-05-23 22:25:50 +00:00
|
|
|
|
text = C_("Extrema", "Max"),
|
2022-03-14 18:56:18 +00:00
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
|
|
|
|
enabled = true,
|
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function()
|
|
|
|
|
self:setWarmth(self.nl.max, true)
|
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
|
local nl_spacer = HorizontalSpan:new{
|
2022-10-10 20:21:27 +00:00
|
|
|
|
width = math.floor((self.screen_width * 0.95 - 1.2 * (self.nl_minus.width + self.nl_plus.width)) / 2),
|
2022-03-14 18:56:18 +00:00
|
|
|
|
}
|
|
|
|
|
local nl_buttons_above = HorizontalGroup:new{
|
|
|
|
|
align = "center",
|
|
|
|
|
self.nl_minus,
|
|
|
|
|
nl_level_container,
|
|
|
|
|
self.nl_plus,
|
|
|
|
|
}
|
|
|
|
|
self.layout[3] = {self.nl_minus, self.nl_plus}
|
|
|
|
|
local nl_buttons_below = HorizontalGroup:new{
|
|
|
|
|
align = "center",
|
|
|
|
|
nl_min,
|
|
|
|
|
nl_spacer,
|
|
|
|
|
nl_max,
|
|
|
|
|
}
|
|
|
|
|
self.layout[4] = {nl_min, nl_max}
|
|
|
|
|
|
|
|
|
|
table.insert(main_group, nl_span)
|
|
|
|
|
table.insert(main_group, nl_header)
|
|
|
|
|
table.insert(nl_group_above, nl_buttons_above)
|
|
|
|
|
table.insert(nl_group_below, nl_buttons_below)
|
|
|
|
|
|
|
|
|
|
table.insert(main_group, nl_padding_span)
|
|
|
|
|
table.insert(main_group, nl_group_above)
|
|
|
|
|
table.insert(main_group, nl_padding_span)
|
|
|
|
|
table.insert(main_group, self.nl_progress)
|
|
|
|
|
table.insert(main_group, nl_padding_span)
|
|
|
|
|
table.insert(main_group, nl_group_below)
|
|
|
|
|
table.insert(main_group, nl_padding_span)
|
|
|
|
|
|
|
|
|
|
-- Aura One R/G/B widget
|
2020-08-19 20:41:10 +00:00
|
|
|
|
if not self.has_nl_mixer and not self.has_nl_api then
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local nl_setup = Button:new{
|
2019-04-12 20:46:10 +00:00
|
|
|
|
text = _("Configure"),
|
|
|
|
|
margin = Size.margin.small,
|
|
|
|
|
radius = 0,
|
2020-06-12 23:56:36 +00:00
|
|
|
|
width = math.floor(self.screen_width * 0.2),
|
2019-04-12 20:46:10 +00:00
|
|
|
|
show_parent = self,
|
|
|
|
|
callback = function()
|
|
|
|
|
UIManager:show(NaturalLight:new{fl_widget = self})
|
|
|
|
|
end,
|
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
table.insert(main_group, nl_setup)
|
|
|
|
|
self.layout[5] = {nl_setup}
|
2019-09-26 22:38:44 +00:00
|
|
|
|
end
|
2018-02-08 21:14:57 +00:00
|
|
|
|
end
|
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
|
table.insert(main_container, main_group)
|
|
|
|
|
-- Reset container height to what it actually contains
|
|
|
|
|
main_container.dimen.h = main_group:getSize().h
|
2019-09-26 22:38:44 +00:00
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
|
-- Common
|
2022-02-03 11:03:33 +00:00
|
|
|
|
local title_bar = TitleBar:new{
|
|
|
|
|
title = _("Frontlight"),
|
|
|
|
|
width = self.width,
|
|
|
|
|
align = "left",
|
|
|
|
|
with_bottom_line = true,
|
|
|
|
|
bottom_v_padding = 0,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
close_callback = function()
|
|
|
|
|
self:onClose()
|
|
|
|
|
end,
|
2022-02-03 11:03:33 +00:00
|
|
|
|
show_parent = self,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local inner_frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
|
padding = Size.padding.button,
|
|
|
|
|
margin = Size.margin.small,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
bordersize = 0,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
main_container,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
2022-03-14 18:56:18 +00:00
|
|
|
|
local center_container = CenterContainer:new{
|
|
|
|
|
dimen = Geom:new{
|
|
|
|
|
w = self.width,
|
|
|
|
|
h = inner_frame:getSize().h,
|
|
|
|
|
},
|
|
|
|
|
inner_frame,
|
|
|
|
|
}
|
|
|
|
|
self.frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
|
radius = Size.radius.window,
|
|
|
|
|
bordersize = Size.border.window,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
padding = 0,
|
|
|
|
|
margin = 0,
|
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
|
VerticalGroup:new{
|
|
|
|
|
align = "left",
|
2022-02-03 11:03:33 +00:00
|
|
|
|
title_bar,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
center_container,
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self[1] = WidgetContainer:new{
|
|
|
|
|
align = "center",
|
2022-03-14 18:56:18 +00:00
|
|
|
|
dimen = Geom:new{
|
2016-12-01 17:58:06 +00:00
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = self.screen_width,
|
|
|
|
|
h = self.screen_height,
|
|
|
|
|
},
|
2022-02-22 12:48:55 +00:00
|
|
|
|
FrameContainer:new{
|
|
|
|
|
bordersize = 0,
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.frame,
|
2022-02-22 12:48:55 +00:00
|
|
|
|
},
|
2016-12-01 17:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
|
function FrontLightWidget:update()
|
|
|
|
|
self:refocusWidget()
|
|
|
|
|
|
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
|
return "ui", self.frame.dimen
|
|
|
|
|
end)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:updateBrightnessWidgets()
|
|
|
|
|
self.fl_progress:setPercentage(self.fl.cur / self.fl.max)
|
|
|
|
|
self.fl_level:setText(tostring(self.fl.cur))
|
|
|
|
|
if self.fl.cur == self.fl.min then
|
|
|
|
|
self.fl_minus:disable()
|
|
|
|
|
else
|
|
|
|
|
self.fl_minus:enable()
|
|
|
|
|
end
|
|
|
|
|
if self.fl.cur == self.fl.max then
|
|
|
|
|
self.fl_plus:disable()
|
|
|
|
|
else
|
|
|
|
|
self.fl_plus:enable()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:refreshBrightnessWidgets()
|
|
|
|
|
self:updateBrightnessWidgets()
|
|
|
|
|
self:update()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:setBrightness(intensity)
|
|
|
|
|
-- Let fl.min through, as that's what we use for the Toggle button ;).
|
|
|
|
|
if intensity ~= self.fl.min and intensity == self.fl.cur then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Set brightness
|
|
|
|
|
self:setFrontLightIntensity(intensity)
|
|
|
|
|
|
|
|
|
|
-- Update the progress bar
|
|
|
|
|
self:updateBrightnessWidgets()
|
|
|
|
|
|
|
|
|
|
-- Refresh widget
|
|
|
|
|
self:update()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:setWarmth(warmth, update_position)
|
|
|
|
|
if warmth == self.nl.cur then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Set warmth
|
2022-03-22 08:58:29 +00:00
|
|
|
|
self.powerd:setWarmth(self.powerd:fromNativeWarmth(warmth))
|
|
|
|
|
-- Retrieve the value PowerD actually set, in case there were rounding shenanigans and we blew the range...
|
|
|
|
|
self.nl.cur = self.powerd:toNativeWarmth(self.powerd:frontlightWarmth())
|
2022-03-14 18:56:18 +00:00
|
|
|
|
|
2022-03-22 08:58:29 +00:00
|
|
|
|
-- If we were not called by ButtonProgressWidget's callback, we'll have to update its progress bar ourselves.
|
2022-03-14 18:56:18 +00:00
|
|
|
|
if update_position then
|
2022-03-22 08:58:29 +00:00
|
|
|
|
self.nl_progress:setPosition(math.floor(self.nl.cur / self.nl.stride), self.nl_progress.default_position)
|
2022-03-14 18:56:18 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
self.nl_level:setText(tostring(self.nl.cur))
|
|
|
|
|
if self.nl.cur == self.nl.min then
|
|
|
|
|
self.nl_minus:disable()
|
|
|
|
|
else
|
|
|
|
|
self.nl_minus:enable()
|
|
|
|
|
end
|
|
|
|
|
if self.nl.cur == self.nl.max then
|
|
|
|
|
self.nl_plus:disable()
|
|
|
|
|
else
|
|
|
|
|
self.nl_plus:enable()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Refresh widget
|
|
|
|
|
self:update()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:setFrontLightIntensity(intensity)
|
|
|
|
|
self.fl.cur = intensity
|
|
|
|
|
|
|
|
|
|
-- min (which is always 0) means toggle
|
|
|
|
|
if self.fl.cur == self.fl.min then
|
|
|
|
|
self.powerd:toggleFrontlight()
|
|
|
|
|
else
|
|
|
|
|
self.powerd:setIntensity(self.fl.cur)
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-22 08:58:29 +00:00
|
|
|
|
-- Retrieve the real level set by PowerD (will be different from `intensity` on toggle)
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self.fl.cur = self.powerd:frontlightIntensity()
|
|
|
|
|
end
|
|
|
|
|
|
2016-12-01 17:58:06 +00:00
|
|
|
|
function FrontLightWidget:onCloseWidget()
|
|
|
|
|
UIManager:setDirty(nil, function()
|
2022-03-14 18:56:18 +00:00
|
|
|
|
return "flashui", self.frame.dimen
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:onShow()
|
2018-06-02 16:10:55 +00:00
|
|
|
|
-- NOTE: Keep this one as UI, it'll get coalesced...
|
2016-12-01 17:58:06 +00:00
|
|
|
|
UIManager:setDirty(self, function()
|
2022-03-14 18:56:18 +00:00
|
|
|
|
return "ui", self.frame.dimen
|
2016-12-01 17:58:06 +00:00
|
|
|
|
end)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FrontLightWidget:onClose()
|
|
|
|
|
UIManager:close(self)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2019-09-26 22:38:44 +00:00
|
|
|
|
function FrontLightWidget:onTapProgress(arg, ges_ev)
|
2021-04-15 23:06:00 +00:00
|
|
|
|
-- The throttling has a tendency to wreak a bit of a havoc,
|
|
|
|
|
-- so, if the widget hasn't been repainted yet, go away.
|
2022-03-14 18:56:18 +00:00
|
|
|
|
if not self.fl_progress.dimen or not self.frame.dimen then
|
2021-04-15 23:06:00 +00:00
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
|
if ges_ev.pos:intersectWith(self.fl_progress.dimen) then
|
|
|
|
|
local perc = self.fl_progress:getPercentageFromPosition(ges_ev.pos)
|
2019-12-06 21:55:39 +00:00
|
|
|
|
if not perc then
|
|
|
|
|
return true
|
|
|
|
|
end
|
2022-10-13 23:50:03 +00:00
|
|
|
|
-- Unschedule any pending updates.
|
|
|
|
|
UIManager:unschedule(self.refreshBrightnessWidgets)
|
2019-09-26 22:38:44 +00:00
|
|
|
|
|
2022-10-13 23:50:03 +00:00
|
|
|
|
local num = Math.round(perc * self.fl.max)
|
2019-09-26 22:38:44 +00:00
|
|
|
|
-- Always set the frontlight intensity.
|
|
|
|
|
self:setFrontLightIntensity(num)
|
|
|
|
|
|
|
|
|
|
-- But limit the widget update frequency on E Ink.
|
|
|
|
|
if Screen.low_pan_rate then
|
2022-05-05 19:00:22 +00:00
|
|
|
|
local current_time = time.now()
|
|
|
|
|
local last_time = self.last_time or 0
|
|
|
|
|
if current_time - last_time > time.s(1 / self.rate) then
|
2019-09-26 22:38:44 +00:00
|
|
|
|
self.last_time = current_time
|
|
|
|
|
else
|
|
|
|
|
-- Schedule a final update after we stop panning.
|
2022-03-14 18:56:18 +00:00
|
|
|
|
UIManager:scheduleIn(0.075, self.refreshBrightnessWidgets, self)
|
2019-09-26 22:38:44 +00:00
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
|
self:refreshBrightnessWidgets()
|
|
|
|
|
elseif not ges_ev.pos:intersectWith(self.frame.dimen) and ges_ev.ges == "tap" then
|
|
|
|
|
-- Close when tapping outside.
|
2019-09-26 22:38:44 +00:00
|
|
|
|
self:onClose()
|
|
|
|
|
end
|
2022-03-14 18:56:18 +00:00
|
|
|
|
-- Otherwise, do nothing (it's easy to miss a button).
|
2019-09-26 22:38:44 +00:00
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
FrontLightWidget.onPanProgress = FrontLightWidget.onTapProgress
|
|
|
|
|
|
2016-12-01 17:58:06 +00:00
|
|
|
|
return FrontLightWidget
|