Address PR comments, and remove BG fill

BG fill eats up a lot of cycles anyway, and there's not a real tangible
benefit in all cases, as it relies on the text label being sized
appropriately (width-wise) to the container, or would otherwise require
padding.
develop
Kelvie Wong 2023-02-18 16:06:03 -08:00
parent 61227eeca1
commit 697f15224c
2 changed files with 17 additions and 16 deletions

@ -4662,7 +4662,9 @@ It has the following attributes:
:text_pen: Specifies the pen for active text. :text_pen: Specifies the pen for active text.
:text_dpen: Specifies the pen for disabled text. :text_dpen: Specifies the pen for disabled text.
:text_hpen: Specifies the pen for text hovered over by the mouse, if a click handler is registered. :text_hpen: Specifies the pen for text hovered over by the mouse, if a click
handler is registered. By default, this will invert the foreground
and background colors.
:disabled: Boolean or a callback; if true, the label is disabled. :disabled: Boolean or a callback; if true, the label is disabled.
:enabled: Boolean or a callback; if false, the label is disabled. :enabled: Boolean or a callback; if false, the label is disabled.
:auto_height: Sets self.frame.h from the text height. :auto_height: Sets self.frame.h from the text height.
@ -4769,6 +4771,18 @@ The Label widget implements the following methods:
``+halfpage``, ``-halfpage``, ``home``, or ``end``. It returns the number of ``+halfpage``, ``-halfpage``, ``home``, or ``end``. It returns the number of
lines that were actually scrolled (negative for scrolling up). lines that were actually scrolled (negative for scrolling up).
* ``label:shouldHover()``
This method returns whether or not this widget should show a hover effect,
generally you want to return ``true`` if there is some type of mouse handler
present. For example, for a ``HotKeyLabel``::
function HotkeyLabel:shouldHover()
-- When on_activate is set, text should also hover on mouseover
return HotkeyLabel.super.shouldHover(self) or self.on_activate
end
WrappedLabel class WrappedLabel class
------------------ ------------------

@ -1232,7 +1232,7 @@ Label = defclass(Label, Widget)
Label.ATTRS{ Label.ATTRS{
text_pen = COLOR_WHITE, text_pen = COLOR_WHITE,
text_dpen = COLOR_DARKGREY, -- disabled text_dpen = COLOR_DARKGREY, -- disabled
text_hpen = DEFAULT_NIL, -- highlight - default is text_pen with reversed brightness text_hpen = DEFAULT_NIL, -- hover - default is to invert the fg/bg colors
disabled = DEFAULT_NIL, disabled = DEFAULT_NIL,
enabled = DEFAULT_NIL, enabled = DEFAULT_NIL,
auto_height = true, auto_height = true,
@ -1250,8 +1250,6 @@ function Label:init(args)
self:addviews{self.scrollbar} self:addviews{self.scrollbar}
self:setText(args.text or self.text) self:setText(args.text or self.text)
-- self.text_hpen = make_hpen(self.text_pen, self.text_hpen)
end end
local function update_label_scrollbar(label) local function update_label_scrollbar(label)
@ -1305,15 +1303,6 @@ function Label:shouldHover()
return self.on_click or self.on_rclick return self.on_click or self.on_rclick
end end
function Label:onRenderFrame(dc, rect)
Label.super.onRenderFrame(self, dc, rect)
-- Fill the background with text_hpen on hover
if self:getMousePos() and self:shouldHover() then
local hpen = make_hpen(self.text_pen, self.text_hpen)
dc:fill(rect, hpen)
end
end
function Label:onRenderBody(dc) function Label:onRenderBody(dc)
local text_pen = self.text_pen local text_pen = self.text_pen
local hovered = self:getMousePos() and self:shouldHover() local hovered = self:getMousePos() and self:shouldHover()
@ -1614,7 +1603,7 @@ List = defclass(List, Widget)
List.ATTRS{ List.ATTRS{
text_pen = COLOR_CYAN, text_pen = COLOR_CYAN,
text_hpen = DEFAULT_NIL, -- pen to render list item when mouse is hovered over; defaults to text_pen with inverted brightness text_hpen = DEFAULT_NIL, -- hover color, defaults to inverting the FG/BG pens for each text object
cursor_pen = COLOR_LIGHTCYAN, cursor_pen = COLOR_LIGHTCYAN,
inactive_pen = DEFAULT_NIL, inactive_pen = DEFAULT_NIL,
on_select = DEFAULT_NIL, on_select = DEFAULT_NIL,
@ -1644,8 +1633,6 @@ function List:init(info)
end end
self.last_select_click_ms = 0 -- used to track double-clicking on an item self.last_select_click_ms = 0 -- used to track double-clicking on an item
-- self.text_hpen = make_hpen(self.text_pen, self.text_hpen)
end end
function List:setChoices(choices, selected) function List:setChoices(choices, selected)