Page 1 of 1

[Solved] Something's odd with hover_alpha and tooltips

Posted: Thu Mar 07, 2024 8:46 am
by goldo
Okay, i think I might be misunderstanding something but I can't make 'hover_alpha' work properly with tooltips in screens.

Whenever I have multiple elements using 'hover_alpha' and tooltip on the same screen, they all change alpha at the same time when hovering any one of them.

Here is an easy screen to reproduce it, using any picture as 'pic':

Code: Select all

screen hover_test:

    modal True

    frame align (0.5, 0.5):
        grid 5 1:
            for i in range(3):
                button action NullAction():
                    tooltip "Picture" # If you comment this line out, hover_alpha will work fine
                    add "pic" hover_alpha 1.0 idle_alpha 0.5 insensitive_alpha 0.2
            for t in ("Hello", "World"):
                textbutton t text_hover_underline True action NullAction() tooltip t
As you can see if you try it, all three image buttons change their alpha value simultaneously. It doesn't happen for text_hover_underline in the textbuttons, so it seems specific to hover_alpha.

If you remove the tooltip, hover_alpha works fine.

What am I missing? Thank you!

Re: Something's odd with hover_alpha and tooltips

Posted: Thu Mar 07, 2024 11:55 am
by jeffster
I guess it's because you have three buttons inside of another button. And when your small buttons are hovered, that hover effect also goes to the large button. It's similar to how events are "bubbling" in HTML / CSS.

PS. I mean, I don't understand the whole process but that's a guess, off the top of my head.

Re: Something's odd with hover_alpha and tooltips

Posted: Thu Mar 07, 2024 12:51 pm
by m_from_space
goldo wrote: Thu Mar 07, 2024 8:46 am What am I missing? Thank you!
I must say that I've never seen a statement like "hover_alpha" before, and therefore I am surprised it even works. But the usual way would be something like this:

Code: Select all

image mybutton_idle:
    "pic"
    alpha 0.5

image mybutton_hover:
    "pic"

image mybutton_insensitive:
    "pic"
    alpha 0.2

screen hover_test():
    grid 3 1:
        for i in range(3):
            imagebutton auto "mybutton_%s":
                action NullAction()
                tooltip "Picture"
On the other hand, your outer button (which is weird in my opinion) doesn't have a defined action - not even a NullAction() - this shouldn't make it receive any events, since it is considered insensitive. But even when removing your outer button, your method doesn't quite work well. I would avoid this "hover_alpha" method.

Re: Something's odd with hover_alpha and tooltips

Posted: Fri Mar 08, 2024 10:09 am
by goldo
Sorry about the nested button, but you can see the exact same behavior if you replace the parent button with a frame (I updated the code above).

m_from_space's solution works, however having to define three images for each picture is going to be a pain (as I have a couple hundreds of such images). Like I'd have an inventory full of items, and each item is supposed to light up when it is hovered.

Is there a solution that would work for heavier duty?

Re: Something's odd with hover_alpha and tooltips

Posted: Fri Mar 08, 2024 11:34 am
by jeffster
goldo wrote: Fri Mar 08, 2024 10:09 am Sorry about the nested button, but you can see the exact same behavior if you replace the parent button with a frame (I updated the code above).
I checked it and it looks like hovering 2nd or 3rd button also causes 1st button become hovered.
Then of course unhovering 2nd or 3rd button does not make the 1st button unhovered.
It must be a bug, and you are welcome to report it at the bug tracker:
https://github.com/renpy/renpy/issues
m_from_space's solution works, however having to define three images for each picture is going to be a pain (as I have a couple hundreds of such images). Like I'd have an inventory full of items, and each item is supposed to light up when it is hovered.

Is there a solution that would work for heavier duty?
There are actions for "hovered" and "unhovered"
https://renpy.org/doc/html/screens.html#button

and we can use them to set some screen variable, used as the button's alpha value.

Here's one way (not sure if it's the most elegant solution, but it should work).

Code: Select all

screen hover_test:
    default unhovers = [0.5, 0.5, 0.5]
    default hovers = [[1.0, 0.5, 0.5], [0.5, 1.0, 0.5], [0.5, 0.5, 1.0]]
    default alphas = unhovers
    modal True
    frame align (0.5, 0.5):
        hbox:
            for i in range(3):
                button action NullAction():
                    tooltip "Picture"
                    add "pic" alpha alphas[i]
                    hovered SetScreenVariable("alphas", hovers[i])
                    unhovered SetScreenVariable("alphas", unhovers)

Re: Something's odd with hover_alpha and tooltips

Posted: Fri Mar 22, 2024 12:11 pm
by goldo
Thank you! This set me in the right direction.

Here is what I ended up implementing:

Code: Select all

screen hover():

    modal True

    default alpha_unhover = 0.6
    default alpha_hover = 1.0
    default alpha_dict = {k: 0.6 for k in button_list}

    for but in button_list:
         button background None action NullAction():
              hovered SetDict(alpha_dict, but, alpha_hover)
              unhovered SetDict(alpha_dict, but, alpha_unhover)
              add img alpha alpha_dict[but]
And it works without glitches! Marking the topic as solved, thank you.