[DoubleSpinWidget, SpinWidget] change values with page-turn buttons#13208
Conversation
|
Surprised to see @poire-z hasn't shown his visage around here as pear usual, pearhaps he's been busy. door closes. |
|
You're pearobably right. No pear review. But no comment after a quick glance, looks ok, but I'm not really familiar with these widgets. |
|
Not a perfect old code, passing four redundant args. Step only is enough. |
|
want me to do this? function NumberPickerWidget:changeValue(step)
local value
if self.value_index then
self.value_index = self.value_index + step
if self.value_index > #self.value_table then
self.value_index = self.wrap and 1 or #self.value_table
elseif self.value_index < 1 then
self.value_index = self.wrap and #self.value_table or 1
end
value = self.value_table[self.value_index]
else
value = self.value + step
if value > self.value_max then
value = self.wrap and self.value_min or self.value_max
elseif value < self.value_min then
value = self.wrap and self.value_max or self.value_min
end
end
return value
end |
|
Sure, no sense to pass the module's properties within itself. |
| self.value_max = self:getDaysInMonth(self.date_month:getValue(), self.date_year:getValue()) | ||
| end | ||
| self.value = self:changeValue(self.value, self.value_step * -1, self.value_max, self.value_min, self.wrap) | ||
| self.value = self:changeValue(self.value_step * -1) |
There was a problem hiding this comment.
it looks quite rubbish though, I would say it's better this way (step * -1) vs (-step)
|
I added a part 2 to this because that one includes a few other things. |
|
I didn't follow the discussion about |
| } | ||
|
|
||
| local left_widget | ||
| local right_widget |
There was a problem hiding this comment.
I suppose it's better to declare them in the beginning of init() and pass as args instead of the strings.
There was a problem hiding this comment.
Having them as module local means they would be shared by all DoubleSpinWidget instances. In the case we have more than ont usable (which may not happen with koreader), they would be replaced and shit would happen.
So, this is conceptually wrong.
Either they should be hold in self. (the instance that has them), or function local and passed as arguments.
There was a problem hiding this comment.
Passing as args doesn't require additional strings ("left_widget"...) and redundant check in onDoubleSpinButtonPressed.
There was a problem hiding this comment.
Either they should be hold in self. (the instance that has them), or function local and passed as arguments.
just to clarify, they were self before, they were self at the first second commit... I am moving them to init then, but cannot pass them directly to the key_events as arguments because they are nil at that moment.
./luajit: frontend/ui/widget/doublespinwidget.lua:375: attempt to index local 'target_widget' (a nil value)
There was a problem hiding this comment.
and of course
Checking frontend/ui/widget/doublespinwidget.lua 24 warnings
frontend/ui/widget/doublespinwidget.lua:63:11: unused variable left_widget
frontend/ui/widget/doublespinwidget.lua:64:11: unused variable right_widget
frontend/ui/widget/doublespinwidget.lua:105:5: setting non-standard global variable left_widget
frontend/ui/widget/doublespinwidget.lua:116:34: accessing undefined variable left_widget
frontend/ui/widget/doublespinwidget.lua:117:5: setting non-standard global variable right_widget
frontend/ui/widget/doublespinwidget.lua:128:34: accessing undefined variable right_widget
frontend/ui/widget/doublespinwidget.lua:129:5: mutating non-standard global variable left_widget
frontend/ui/widget/doublespinwidget.lua:130:28: accessing undefined variable right_widget
frontend/ui/widget/doublespinwidget.lua:132:5: mutating non-standard global variable right_widget
frontend/ui/widget/doublespinwidget.lua:133:21: accessing undefined variable left_widget
frontend/ui/widget/doublespinwidget.lua:144:9: accessing undefined variable left_widget
frontend/ui/widget/doublespinwidget.lua:152:9: accessing undefined variable right_widget
frontend/ui/widget/doublespinwidget.lua:222:21: mutating non-standard global variable left_widget
frontend/ui/widget/doublespinwidget.lua:223:21: mutating non-standard global variable right_widget
frontend/ui/widget/doublespinwidget.lua:224:21: accessing undefined variable left_widget
frontend/ui/widget/doublespinwidget.lua:225:21: accessing undefined variable right_widget
frontend/ui/widget/doublespinwidget.lua:236:45: accessing undefined variable left_widget
frontend/ui/widget/doublespinwidget.lua:236:69: accessing undefined variable right_widget
frontend/ui/widget/doublespinwidget.lua:257:68: accessing undefined variable left_widget
frontend/ui/widget/doublespinwidget.lua:258:40: accessing undefined variable right_widget
frontend/ui/widget/doublespinwidget.lua:260:35: accessing undefined variable left_widget
frontend/ui/widget/doublespinwidget.lua:261:36: accessing undefined variable right_widget
frontend/ui/widget/doublespinwidget.lua:372:60: accessing undefined variable left_widget
frontend/ui/widget/doublespinwidget.lua:372:75: accessing undefined variable right_widget
Checking frontend/ui/widget/spinwidget.lua 15 warnings
frontend/ui/widget/spinwidget.lua:58:11: unused variable value_widget
frontend/ui/widget/spinwidget.lua:96:5: setting non-standard global variable value_widget
frontend/ui/widget/spinwidget.lua:112:32: accessing undefined variable value_widget
frontend/ui/widget/spinwidget.lua:115:9: accessing undefined variable value_widget
frontend/ui/widget/spinwidget.lua:155:24: accessing undefined variable value_widget
frontend/ui/widget/spinwidget.lua:156:25: mutating non-standard global variable value_widget
frontend/ui/widget/spinwidget.lua:158:25: mutating non-standard global variable value_widget
frontend/ui/widget/spinwidget.lua:160:21: accessing undefined variable value_widget
frontend/ui/widget/spinwidget.lua:170:48: accessing undefined variable value_widget
frontend/ui/widget/spinwidget.lua:182:48: accessing undefined variable value_widget
frontend/ui/widget/spinwidget.lua:209:72: accessing undefined variable value_widget
frontend/ui/widget/spinwidget.lua:211:48: accessing undefined variable value_widget
frontend/ui/widget/spinwidget.lua:351:5: mutating non-standard global variable value_widget
frontend/ui/widget/spinwidget.lua:351:26: accessing undefined variable value_widget
frontend/ui/widget/spinwidget.lua:352:5: accessing undefined variable value_widget
There was a problem hiding this comment.
local a = { x = 0 }
local b = { args = { a, 1 } }
a.x = 1
print(b.args[1].x)1
There was a problem hiding this comment.
I see, later we do not modify self.left_widget, but reassign it, and it breaks the reference.
You are right.
There was a problem hiding this comment.
But we're not doing a.x = 1 in this PR.
We're doing a = { y = 2 }.
There was a problem hiding this comment.
local a = { x = 0 }
local b = { args = { a, 1 } }
a = { x = 1 }
print(b.args[1].x)0
There was a problem hiding this comment.
thank you @poire-z for saying (loquaciously) the same thing I said here #13208 (comment) ;). I guess I wasn't "wrong" after all.
#13208 (comment) should be corrected like so, ;)
Your point is
notcorrect.
But even better: keep it local, and declare in the beginning of init().
poire-z
left a comment
There was a problem hiding this comment.
The stuff I joined the discussion about reads ok.
I'll let others approve the feature and tweaks.
|
Suggesting locals, I forgot about poor architecture of the spin widget. koreader/frontend/ui/widget/titlebar.lua Lines 456 to 461 in 68cfd96 |
I'm not certain it's that "usually". There are lots of places where we rebuild in some :update(), without having to add and use :setXyZ() methods to just not have to recreate a widget. I know you (and @NiLuJe for DictQuickLookup) did that kind of stuff, but it doesn't feel "poor" to not do that, moreover for such minor widgets such as these SpinWidget which are not heavily used. |
|
I'm with poire-z. I don't mind. |
|
Ditto. I conceptually prefer it when that's the case, but it's often not trivial ;). |
|
Fine by me, but I'm not sure if the |
|
I'm not sure that is a legitimate concern though, I mean, the "bad precedent" has existed for a while now ;), nothing to do with me. |
|
Has anyone got any other comments? |

what's new
This pull request includes changes to the
DoubleSpinWidgetandSpinWidgetclasses. The modifications enhance the functionality of these widgets by adding new key events to support value changing using the device's page-turn buttons.enhancements to
DoubleSpinWidget:left_widgetandright_widget.onDoubleSpinButtonPressedmethod to handle page-turn button presses for adjusting widget values.enhancements to
SpinWidget:value_widget.onSpinButtonPressedmethod to handle page-turn button presses for adjusting widget values.others
changeValuemethod ofNumberPickerWidget.This change is