From 0ba4225d85924a86c97cad7938fdbfe95827f590 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 25 Mar 2023 15:19:24 -0700 Subject: [PATCH] support showing a different tile on hover for Labels --- docs/changelog.txt | 1 + docs/dev/Lua API.rst | 12 +++++++----- library/lua/gui/widgets.lua | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index b9c31f146..ced0f961e 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -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 diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 9f2386660..862c5bccc 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -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`` diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index b86e31710..b5497f0d0 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -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