Merge pull request #3100 from myk002/myk_htile

support showing a different tile on hover for Labels
develop
Myk 2023-03-25 15:27:20 -07:00 committed by GitHub
commit 9a7daea9f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

@ -64,6 +64,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## API ## API
## Lua ## Lua
- ``widget.Label``: tokens can now specify a ``htile`` property to indicate the tile that should be shown when the Label is hovered over with the mouse
## Removed ## Removed

@ -4731,10 +4731,12 @@ containing newlines, or a table with the following possible fields:
Specifies the number of character positions to advance on the line Specifies the number of character positions to advance on the line
before rendering the token. before rendering the token.
* ``token.tile = pen`` * ``token.tile``, ``token.htile``
Specifies a pen or texture index (or a function that returns a pen or texture Specifies a pen or texture index (or a function that returns a pen or texture
index) to paint as one tile before the main part of the token. index) to paint as one tile before the main part of the token. If ``htile``
is specified, that is used instead of ``tile`` when the Label is hovered over
with the mouse.
* ``token.width = ...`` * ``token.width = ...``
@ -4762,10 +4764,10 @@ containing newlines, or a table with the following possible fields:
Same as the attributes of the label itself, but applies only to the token. Same as the attributes of the label itself, but applies only to the token.
* ``token.pen``, ``token.dpen`` * ``token.pen``, ``token.dpen``, ``token.hpen``
Specify the pen and disabled pen to be used for the token's text. Specify the pen, disabled pen, and hover pen to be used for the token's text.
The field may be either the pen itself, or a callback that returns it. The fields may be either the pen itself, or a callback that returns it.
* ``token.on_activate`` * ``token.on_activate``

@ -1121,10 +1121,10 @@ function render_text(obj,dc,x0,y0,pen,dpen,disabled,hpen,hovered)
end end
end end
if token.tile then if token.tile or (hovered and token.htile) then
x = x + 1 x = x + 1
if dc then if dc then
local tile = getval(token.tile) local tile = hovered and getval(token.htile or token.tile) or getval(token.tile)
local tile_pen = tonumber(tile) and to_pen{tile=tile} or tile local tile_pen = tonumber(tile) and to_pen{tile=tile} or tile
dc:char(nil, tile_pen) dc:char(nil, tile_pen)
if token.width then if token.width then