Jump to content

[SOLVED] WidgetComboBox


photo

Recommended Posts

Hi,

 

I'm trying to highlight the background of my WidgetComboBox (when it gets clicked on) by creating a Widgetsprite and adding it the parent widget using GUI_ALIGN_OVERLAP | GUI_ALIGN_BACKGROUND.  I then assign the sprite widget callback GUI_CLICKED to my own callback to draw the highlighting when the sprite is clicked. 

 

It works fine and highlights ok, the problem is as soon as I assign a callback to the sprite using    sprite.setCallback(GUI_CLICKED...    then the combobox stops picking up clicks and never updates.  The fact that I assign my own GUI_CLICKED callback to the sprite seems to be the culprit but I'm not sure why?

 

Any ideas/suggestions would be welcome.

 

Thanks,

Simon 

 

 

 

 

Link to comment

Unfortunately there's a lot of code in our code base and it's all quite complex and interconnected.  Very time consuming to pull out into a sample scene :(

Link to comment

Ok, so the following code snippet says it best (it works fine):

 

WidgetSprite sprite = new WidgetSprite(gui,"core/editor/gui/color_white.png");
 

m_hBox.addChild( sprite, GUI_ALIGN_OVERLAP | GUI_ALIGN_BACKGROUND );

 

//

//  While the following code below is commented out, the checkbox can be checked and receives mouse clicks

//

//sprite.setCallback(GUI_CLICKED, "OnRowClickedCB", this, m_rowSprites.size(), GUI_CLICKED);
 

//

//  The following code adds a checkbox over the top of the sprite - it works fine while the previous code is commented out

//

WidgetCheckBox checkbox = new WidgetCheckBox(engine.getGui(), "");

m_hBox.addChild(checkbox);

 

 

And the following code doesn't work:

 

WidgetSprite sprite = new WidgetSprite(gui,"core/editor/gui/color_white.png");

m_hBox.addChild( sprite, GUI_ALIGN_OVERLAP | GUI_ALIGN_BACKGROUND );

//
//  While the following code below is commented out, the checkbox can be checked and receives mouse clicks
//
sprite.setCallback(GUI_CLICKED, "OnRowClickedCB", this, m_rowSprites.size(), GUI_CLICKED);
 

//
//  The following checkbox DOESN'T work - it displays but doesn't receive clicks and never gets checked because the call to "setCallback" above
//
WidgetCheckBox checkbox = new WidgetCheckBox(engine.getGui(), "");
m_hBox.addChild(checkbox);

 

 

setting the GUI_CLICKED is the reason the clicks don't work.  This seems to be the case for all widgets (not just checkboxes).  

 

Is there any way around this or is this a bug?

 

Thanks,

Simon 

Link to comment

Hi there,

 

ok - just paste this init() code into your scene file and you'll see what I mean:

 

int init() {
    Player player = new PlayerSpectator();
    player.setDirection(Vec3(0.755f, -1.0f, 0.25f));
    engine.game.setPlayer(player);

    Gui gui = engine.getGui();

    WidgetHBox m_hBox = new WidgetHBox(gui, 0, 0);

    // Empty string should still load with a red background
    WidgetSprite sprite = new WidgetSprite(gui, "" );
    sprite.setWidth(200);
    sprite.setHeight(200);
    m_hBox.addChild(sprite, GUI_ALIGN_OVERLAP | GUI_ALIGN_BACKGROUND );

    // This causes the checkbox to ignore any mouse clicks
    sprite.setCallback(GUI_CLICKED, "OnRowClickedCB");

    WidgetCheckBox checkbox = new WidgetCheckBox(gui, "combobox");
    m_hBox.addChild(checkbox);

    gui.addChild(m_hBox, GUI_ALIGN_CENTER);

    return 1;
}

 

Basically, All I'm after is a way to change the background colour of my base/bottom containers that contain my widgets that sit on top. 

 

This is quite urgent for us - it would be great if you could get back to me asap.

 

Cheers!

Simon

Link to comment

Hi, Simon,

 

yes, its a known issue. You have 2 options:

 

1) Set checkboxes as GUI_ALIGN_OVERLAP and set their positions manually

2) Don't set callback to sprite, and manually checks for sprite clicked instead:

WidgetSprite sprite;

/*
 */
int init() {
    Player player = new PlayerSpectator();
    player.setDirection(Vec3(0.755f, -1.0f, 0.25f));
    engine.game.setPlayer(player);

    Gui gui = engine.getGui();
    
    WidgetHBox m_hBox = new WidgetHBox(gui, 0, 0);
    
    sprite = new WidgetSprite(gui, "" );
    sprite.setWidth(200);
    sprite.setHeight(200);
    m_hBox.addChild(sprite, GUI_ALIGN_OVERLAP | GUI_ALIGN_BACKGROUND);
    
    WidgetCheckBox checkbox = new WidgetCheckBox(gui, "combobox");
    m_hBox.addChild(checkbox);
    
    gui.addChild(m_hBox,GUI_ALIGN_CENTER);
    return 1;
}

/*
 */
int update() {
    //check for sprite clicked
    int x = engine.gui.getMouseX();
    int y = engine.gui.getMouseY();
    
    if(x > sprite.getScreenPositionX() && x < (sprite.getScreenPositionX() + sprite.getWidth()) &&
       y > sprite.getScreenPositionY() && y < (sprite.getScreenPositionY() +  sprite.getHeight())) {
        
        if(engine.gui.getMouseButton() == APP_BUTTON_LEFT) {
            //change color ets
        }
    }
    return 1;
}
Link to comment
  • 5 weeks later...
×
×
  • Create New...