Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button event not trigger when child of Panel #37

Closed
MangelMaxime opened this issue Jan 1, 2016 · 7 comments
Closed

Button event not trigger when child of Panel #37

MangelMaxime opened this issue Jan 1, 2016 · 7 comments

Comments

@MangelMaxime
Copy link

Hi,
I am not sure if this is a bug or not. But if I add a button inside a panel then the button don't react to mouse input.
However, if I place it inside a window then it act correctly.

Is it the intended behavior ?

@ruby0x1
Copy link
Member

ruby0x1 commented Jan 2, 2016

How did you add the child specifically?

@MangelMaxime
Copy link
Author

I used this code :

        _panel = new mint.Panel ({
            parent: canvas,
            name: 'panel1',
            x: 10, y: 100, w: 200, h: 200,
            options: {
                color: new Color().rgb(RefColor.CARROT),
            }
        });

        new mint.Button({
            parent: _panel,
            name: 'btn_index2',
            x: 10, y: 52, w: 60, h: 32,
            text: 'Index',
            text_size: 14,
            options: {
                label: { color: new Color().rgb(RefColor.CLOUDS)},
                color_hover: new Color().rgb(RefColor.AMETHYST)
            },
            onclick: function(e,c) { trace('clicked');}
        });

@Blist
Copy link

Blist commented Jan 12, 2016

https://gist.github.com/Blist/e852d419c734418ff202

Is it a piece of code Who isolate the bug. The panel does not transmit its signals(click, focus, input) to these children. Works with the empty_luxe project.

@ImDeity
Copy link

ImDeity commented Jan 12, 2016

Just to add a little info, I had a similar problem before with panels being the parent of an interactive element like Buttons and Sliders.

A discussion with @underscorediscovery revealed that the parent element may not be maintaining a list of children properly when the child element is parented and that telling the container/parent element to set the Button/Slider as a child should work (it didn't for me). Here's @underscorediscovery 's words:

- the pattern in mint (for the most part) is to operate on the container (a lot like luxe)
- this is a thing i'll clarify and maybe there's a way around the parent property telling you
- but you should be doing panel.add(slider)
- not slider.parent = panel
- there's usually a lot of annoying code when you have two endpoints that do the same thing, because - - - they'll call each other
- set_parent -> add to parent -> set_parent
- i prefer to keep the workflow clear and stick to "what you operate on" as being consistent
- always do the action / operate on the container

Parenting the interactive element to something other than a panel, like a Window, is the workaround I ended up using.

@ruby0x1
Copy link
Member

ruby0x1 commented Jan 13, 2016

Thanks @Blist and @ImDeity, the isolated test is exactly all that is needed to fix bugs like this. It's probably something simple.

@ruby0x1
Copy link
Member

ruby0x1 commented Jan 13, 2016

Ok I had a quick look, and my first guess was close:

var panel = new mint.Panel({
    parent:canvas,
    name:"panel1",
    mouse_input: true,
    x:50, y:50, w:200, h:150
});

Note the addition of mouse_input: true to the constructor for the Panel.
I can't remember off hand if the parent prevents children from receiving events explicitly or not, so I'll still have a closer look at the situation.

In the meantime enable mouse input on the panel and it should work.

I should note though, the default mouse_input is false, specific controls that use the mouse (like windows) set it to true, because they expect mouse events for things like moving and closing and so on. (So the behaviour is somewhat expected to not receive mouse events on a panel, I am looking into if that makes sense for its children)

@anissen
Copy link
Contributor

anissen commented May 13, 2016

It looks like this issue would be solved by #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants