Skip to content

Instantly share code, notes, and snippets.

@streetturtle
Last active October 20, 2020 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save streetturtle/39a0e09fff0c14fa610ec8a32085c4ed to your computer and use it in GitHub Desktop.
Save streetturtle/39a0e09fff0c14fa610ec8a32085c4ed to your computer and use it in GitHub Desktop.
Fade effect of text/image widgets
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