Fix sliders allowing values outside their number of stops#5749
Conversation
Clicking left and right only did -1 & +1 without checking the validity of the result.
| ---@field ATTRS widgets.Slider.attrs|fun(attributes: widgets.Slider.attrs.partial) | ||
| ---@overload fun(init_table: widgets.Slider.initTable): self | ||
| Slider = defclass(Slider, slide_core) | ||
| Slider = defclass(Slider, core) |
There was a problem hiding this comment.
why is slide_core changed to core here?
There was a problem hiding this comment.
Because otherwise local core in line 1 is pointless.
There was a problem hiding this comment.
This is the wrong way to do it. revert the change here, and change line 1 to
local slide_core = require('gui.widgets.slide_core')
or things just get too confusing.
the class's name is slide_core, it should be named exactly that by all code that uses it. this is realSquidCoder's mistake, not yours, but this is a good time to fix it.
this is especially important because every script has a global variable named slide_core that is a reference to the slide_core class, so the existing code does work as written, despite that unused local variable core.
per our conventions, slide_core should also be named using CamelCase. _SliderCore maybe? i.e. starting the class name with a single underscore to hopefully flag that it's not intended to be instantiated. that's out of scope of the intended fix, but it's a good time to make the change.
Clicking left and right only recorded -1 or +1 based on mouse position without any safeguard against potential larger frame than the slider itself. EDIT: Dragging was affected too.
If this PR makes an externally-visible change in behavior or API, please add an appropriate line to
docs/changelog.txt.