support showing a different tile on hover for Labels

develop
Myk Taylor 2023-03-25 15:19:24 -07:00
parent 4108c57c0d
commit 0ba4225d85
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
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
## 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

@ -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
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
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 = ...``
@ -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.
* ``token.pen``, ``token.dpen``
* ``token.pen``, ``token.dpen``, ``token.hpen``
Specify the pen and disabled pen to be used for the token's text.
The field may be either the pen itself, or a callback that returns it.
Specify the pen, disabled pen, and hover pen to be used for the token's text.
The fields may be either the pen itself, or a callback that returns it.
* ``token.on_activate``

@ -1121,10 +1121,10 @@ function render_text(obj,dc,x0,y0,pen,dpen,disabled,hpen,hovered)
end
end
if token.tile then
if token.tile or (hovered and token.htile) then
x = x + 1
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
dc:char(nil, tile_pen)
if token.width then