vrld/suit

Buttons with the same text "chained together"

Closed this issue · 2 comments

This behavior is really weird, but at least seems consistent. The following code:

    if suit.Button("i", 550, 200, 40, 40).hit then
        --...
    end
    if suit.Button("i", 570, 20, 40, 40).hit then
        --...
    end

Creates two buttons that do not overlap each other at all. However, when hovering over the one created first (the one with y = 200), the second one changes to "hovered" color as well! And when I click the first one, the second one gets a click event too. But, when I hover/click the second one, the first one does not react in any weird way, so this is a one-way relationship.

Guess what fixes this behavior? Using different texts. This code:

    if suit.Button("i", 550, 200, 40, 40).hit then
        --...
    end
    if suit.Button("a", 570, 20, 40, 40).hit then
        --...
    end

(Only changed the text on the second button) works just as you'd expect, and creates to totally separate buttons, that do not react to each others events in any way.

Plz fix, this is really frustrating and took a long while to figure out how to make the weird "dependency" go away.

Bonus: if I create three buttons with the same label, they will also depend on each other in this chained way.

vrld commented

That is expected behaviour, see the documentation. Two buttons with the same id will share user interaction. If you want two buttons with the same label, but different ids, use the id option:

if suit.Button("i", {id=1}, 550,200,40,40).hit then
    -- ..
end
if suit.Button("i", {id=2}, 570,200,40,40).hit then
    -- ..
end

Hm, allright, I guess this is unavoidable. Thanks.