mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
frontlightwidget: Add widgets for changing 'warmth' if available
If the device supports natural light (currently only KA1), extend the frontlight widget to also allow for changing the 'warmth' value. We more or less duplicate the widget for 'brightness', with the exception that we drop the 'toggle' button, which does not make much sense for the frontlight's warmth. Also, we add captions 'Brightness' and 'Warmth' for clarity.
This commit is contained in:
committed by
Frans de Jonge
parent
95951953f2
commit
78284e13d9
@@ -47,6 +47,7 @@ function FrontLightWidget:init()
|
||||
self.steps = self.steps + 1
|
||||
end
|
||||
self.steps = math.min(self.steps , steps_fl)
|
||||
self.natural_light = Device:isKobo() and Device:hasNaturalLight()
|
||||
|
||||
-- button width to fit screen size
|
||||
local button_margin = Size.margin.tiny
|
||||
@@ -95,7 +96,7 @@ function FrontLightWidget:generateProgressGroup(width, height, fl_level, step)
|
||||
return self.fl_container
|
||||
end
|
||||
|
||||
function FrontLightWidget:setProgress(num, step)
|
||||
function FrontLightWidget:setProgress(num, step, num_warmth)
|
||||
self.fl_container:clear()
|
||||
local padding_span = VerticalSpan:new{ width = self.span }
|
||||
local button_group_down = HorizontalGroup:new{ align = "center" }
|
||||
@@ -107,6 +108,9 @@ function FrontLightWidget:setProgress(num, step)
|
||||
local enable_button_minus = true
|
||||
local step_num = math.floor(num / step)
|
||||
local step_min = math.floor(self.fl_min / step)
|
||||
if self.natural_light then
|
||||
num_warmth = num_warmth or self.powerd.fl_warmth
|
||||
end
|
||||
if num then
|
||||
self.fl_cur = num
|
||||
set_fl = math.min(self.fl_cur, self.fl_max)
|
||||
@@ -147,6 +151,13 @@ function FrontLightWidget:setProgress(num, step)
|
||||
callback = function() self:setProgress(i * step, step) end
|
||||
})
|
||||
end
|
||||
local text_br = TextBoxWidget:new{
|
||||
text = _("Brightness"),
|
||||
face = self.medium_font_face,
|
||||
bold = true,
|
||||
alignment = "center",
|
||||
width = self.screen_width * 0.95
|
||||
}
|
||||
local button_minus = Button:new{
|
||||
text = "-1",
|
||||
margin = Size.margin.small,
|
||||
@@ -217,6 +228,11 @@ function FrontLightWidget:setProgress(num, step)
|
||||
empty_space,
|
||||
button_max,
|
||||
}
|
||||
if self.natural_light then
|
||||
-- Only insert 'brightness' caption if we also add 'warmth'
|
||||
-- widgets below.
|
||||
table.insert(vertical_group,text_br)
|
||||
end
|
||||
table.insert(button_group_up, button_table_up)
|
||||
table.insert(button_group_down, button_table_down)
|
||||
table.insert(vertical_group,padding_span)
|
||||
@@ -226,6 +242,10 @@ function FrontLightWidget:setProgress(num, step)
|
||||
table.insert(vertical_group,padding_span)
|
||||
table.insert(vertical_group,button_group_down)
|
||||
table.insert(vertical_group,padding_span)
|
||||
if self.natural_light then
|
||||
-- If the device supports natural light, add the widgets for 'warmth'.
|
||||
self:addWarmthWidgets(num_warmth, step, vertical_group)
|
||||
end
|
||||
table.insert(self.fl_container, vertical_group)
|
||||
-- Reset container height to what it actually contains
|
||||
self.fl_container.dimen.h = vertical_group:getSize().h
|
||||
@@ -234,6 +254,120 @@ function FrontLightWidget:setProgress(num, step)
|
||||
return true
|
||||
end
|
||||
|
||||
-- Currently, we are assuming the 'warmth' has the same min/max limits
|
||||
-- as 'brightness'.
|
||||
function FrontLightWidget:addWarmthWidgets(num_warmth, step, vertical_group)
|
||||
local button_group_down = HorizontalGroup:new{ align = "center" }
|
||||
local button_group_up = HorizontalGroup:new{ align = "center" }
|
||||
local warmth_group = HorizontalGroup:new{ align = "center" }
|
||||
local padding_span = VerticalSpan:new{ width = self.span }
|
||||
local enable_button_plus = true
|
||||
local enable_button_minus = true
|
||||
|
||||
if self[1] then
|
||||
self.powerd:setWarmth(num_warmth)
|
||||
end
|
||||
|
||||
if self.natural_light and num_warmth then
|
||||
for i = 0, math.floor(num_warmth / step) do
|
||||
table.insert(warmth_group, self.fl_prog_button:new{
|
||||
text = "",
|
||||
preselect = true,
|
||||
callback = function()
|
||||
self:setProgress(self.fl_cur, step, i * step)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
for i = math.floor(num_warmth / step) + 1, self.steps - 1 do
|
||||
table.insert(warmth_group, self.fl_prog_button:new{
|
||||
text="",
|
||||
callback = function()
|
||||
self:setProgress(self.fl_cur, step, i * step)
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
if num_warmth == self.fl_max then enable_button_plus = false end
|
||||
if num_warmth == self.fl_min then enable_button_minus = false end
|
||||
|
||||
local text_warmth = TextBoxWidget:new{
|
||||
text = "\n" .. _("Warmth"),
|
||||
face = self.medium_font_face,
|
||||
bold = true,
|
||||
alignment = "center",
|
||||
width = self.screen_width * 0.95
|
||||
}
|
||||
local button_minus = Button:new{
|
||||
text = "-1",
|
||||
margin = Size.margin.small,
|
||||
radius = 0,
|
||||
enabled = enable_button_minus,
|
||||
width = self.screen_width * 0.20,
|
||||
show_parent = self,
|
||||
callback = function() self:setProgress(self.fl_cur, step, num_warmth - 1) end,
|
||||
}
|
||||
local button_plus = Button:new{
|
||||
text = "+1",
|
||||
margin = Size.margin.small,
|
||||
radius = 0,
|
||||
enabled = enable_button_plus,
|
||||
width = self.screen_width * 0.20,
|
||||
show_parent = self,
|
||||
callback = function() self:setProgress(self.fl_cur, step, num_warmth + 1) end,
|
||||
}
|
||||
local item_level = TextBoxWidget:new{
|
||||
text = num_warmth,
|
||||
face = self.medium_font_face,
|
||||
alignment = "center",
|
||||
width = self.screen_width * 0.95 - 1.275 * button_minus.width - 1.275 * button_plus.width,
|
||||
}
|
||||
local button_min = Button:new{
|
||||
text = _("Min"),
|
||||
margin = Size.margin.small,
|
||||
radius = 0,
|
||||
enabled = true,
|
||||
width = self.screen_width * 0.20,
|
||||
show_parent = self,
|
||||
callback = function() self:setProgress(self.fl_cur, step, self.fl_min) end,
|
||||
}
|
||||
local button_max = Button:new{
|
||||
text = _("Max"),
|
||||
margin = Size.margin.small,
|
||||
radius = 0,
|
||||
enabled = true,
|
||||
width = self.screen_width * 0.20,
|
||||
show_parent = self,
|
||||
callback = function() self:setProgress(self.fl_cur, step, self.fl_max) end,
|
||||
}
|
||||
local empty_space = HorizontalSpan:new{
|
||||
width = (self.screen_width * 0.95 - 1.2 * button_minus.width - 1.2 * button_plus.width) / 2,
|
||||
}
|
||||
local button_table_up = HorizontalGroup:new{
|
||||
align = "center",
|
||||
button_minus,
|
||||
item_level,
|
||||
button_plus,
|
||||
}
|
||||
local button_table_down = HorizontalGroup:new{
|
||||
align = "center",
|
||||
button_min,
|
||||
empty_space,
|
||||
button_max,
|
||||
}
|
||||
table.insert(vertical_group,text_warmth)
|
||||
table.insert(button_group_up, button_table_up)
|
||||
table.insert(button_group_down, button_table_down)
|
||||
table.insert(vertical_group,padding_span)
|
||||
table.insert(vertical_group,button_group_up)
|
||||
table.insert(vertical_group,padding_span)
|
||||
table.insert(vertical_group,warmth_group)
|
||||
table.insert(vertical_group,padding_span)
|
||||
table.insert(vertical_group,button_group_down)
|
||||
table.insert(vertical_group,padding_span)
|
||||
end
|
||||
|
||||
function FrontLightWidget:update()
|
||||
-- header
|
||||
self.light_title = FrameContainer:new{
|
||||
|
||||
Reference in New Issue
Block a user