Merge branch 'develop' into automelt

develop
eamondo2 2023-01-23 13:35:38 -05:00
commit 63de2ac9ec
3 changed files with 8 additions and 3 deletions

@ -47,6 +47,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## API ## API
## Lua ## Lua
- ``widgets.Label``: ``label.scroll()`` now understands ``home`` and ``end`` keywords for scrolling to the top or bottom
## Removed ## Removed

@ -4684,8 +4684,8 @@ The Label widget implements the following methods:
This method takes the number of lines to scroll as positive or negative This method takes the number of lines to scroll as positive or negative
integers or one of the following keywords: ``+page``, ``-page``, integers or one of the following keywords: ``+page``, ``-page``,
``+halfpage``, or ``-halfpage``. It returns the number of lines that were ``+halfpage``, ``-halfpage``, ``home``, or ``end``. It returns the number of
actually scrolled (negative for scrolling up). lines that were actually scrolled (negative for scrolling up).
WrappedLabel class WrappedLabel class
------------------ ------------------

@ -1315,6 +1315,7 @@ end
function Label:scroll(nlines) function Label:scroll(nlines)
if not nlines then return end if not nlines then return end
local text_height = math.max(1, self:getTextHeight())
if type(nlines) == 'string' then if type(nlines) == 'string' then
if nlines == '+page' then if nlines == '+page' then
nlines = self.frame_body.height nlines = self.frame_body.height
@ -1324,12 +1325,15 @@ function Label:scroll(nlines)
nlines = math.ceil(self.frame_body.height/2) nlines = math.ceil(self.frame_body.height/2)
elseif nlines == '-halfpage' then elseif nlines == '-halfpage' then
nlines = -math.ceil(self.frame_body.height/2) nlines = -math.ceil(self.frame_body.height/2)
elseif nlines == 'home' then
nlines = 1 - self.start_line_num
elseif nlines == 'end' then
nlines = text_height
else else
error(('unhandled scroll keyword: "%s"'):format(nlines)) error(('unhandled scroll keyword: "%s"'):format(nlines))
end end
end end
local n = self.start_line_num + nlines local n = self.start_line_num + nlines
local text_height = math.max(1, self:getTextHeight())
n = math.min(n, text_height - self.frame_body.height + 1) n = math.min(n, text_height - self.frame_body.height + 1)
n = math.max(n, 1) n = math.max(n, 1)
nlines = n - self.start_line_num nlines = n - self.start_line_num