Last active
October 20, 2020 15:04
-
-
Save streetturtle/39a0e09fff0c14fa610ec8a32085c4ed to your computer and use it in GitHub Desktop.
Fade effect of text/image widgets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local fade_widget = wibox.widget { | |
{ | |
id = 'icon', | |
image = '/usr/share/icons/Yaru/24x24/apps/org.gnome.PowerStats.png', | |
widget = wibox.widget.imagebox | |
}, | |
{ | |
id = 'text', | |
text = 'Click to fade', | |
widget = wibox.widget.textbox | |
}, | |
spacing = 4, | |
layout = wibox.layout.fixed.horizontal, | |
toggle_fade = function(self, is_fade) | |
self:get_children_by_id('icon')[1]:set_opacity(is_fade and 0.2 or 1) | |
self:get_children_by_id('icon')[1]:emit_signal('widget::redraw_needed') | |
self:get_children_by_id('text')[1]:set_opacity(is_fade and 0.2 or 1) | |
self:get_children_by_id('text')[1]:emit_signal('widget::redraw_needed') | |
end | |
} | |
-- on click | |
local faded = true | |
fade_widget:connect_signal('button::press', function(c) | |
faded = not faded | |
c:toggle_fade(not faded) | |
end) | |
-- on hover | |
fade_widget:toggle_fade(true) | |
fade_widget:connect_signal('mouse::enter', function(c) c:toggle_fade(false) end) | |
fade_widget:connect_signal('mouse::leave', function(c) c:toggle_fade(true) end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment