mirror of
https://github.com/minetest/irrlicht.git
synced 2025-06-28 14:26:06 +02:00
ComboBox API additions for minetest#13814
- Allow reliably detecting when the user opens a combobox. - Allow preventing comboboxes from opening. - Allow sending a combobox change event.
This commit is contained in:
@ -22,9 +22,9 @@ namespace gui
|
||||
CGUIComboBox::CGUIComboBox(IGUIEnvironment* environment, IGUIElement* parent,
|
||||
s32 id, core::rect<s32> rectangle)
|
||||
: IGUIComboBox(environment, parent, id, rectangle),
|
||||
ListButton(0), SelectedText(0), ListBox(0), LastFocus(0),
|
||||
ListButton(nullptr), SelectedText(nullptr), ListBox(nullptr), LastFocus(nullptr),
|
||||
Selected(-1), HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_CENTER), MaxSelectionRows(5), HasFocus(false),
|
||||
ActiveFont(0)
|
||||
ActiveFont(nullptr)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CGUIComboBox");
|
||||
@ -185,6 +185,15 @@ void CGUIComboBox::setSelected(s32 idx)
|
||||
}
|
||||
|
||||
|
||||
//! Sets the selected item and emits a change event.
|
||||
/** Set this to -1 if no item should be selected */
|
||||
void CGUIComboBox::setAndSendSelected(s32 idx)
|
||||
{
|
||||
setSelected(idx);
|
||||
sendSelectionChangedEvent();
|
||||
}
|
||||
|
||||
|
||||
//! called if an event happened.
|
||||
bool CGUIComboBox::OnEvent(const SEvent& event)
|
||||
{
|
||||
@ -208,7 +217,7 @@ bool CGUIComboBox::OnEvent(const SEvent& event)
|
||||
openCloseMenu();
|
||||
}
|
||||
|
||||
ListButton->setPressed(ListBox == 0);
|
||||
ListButton->setPressed(ListBox == nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -361,7 +370,7 @@ void CGUIComboBox::sendSelectionChangedEvent()
|
||||
|
||||
event.EventType = EET_GUI_EVENT;
|
||||
event.GUIEvent.Caller = this;
|
||||
event.GUIEvent.Element = 0;
|
||||
event.GUIEvent.Element = nullptr;
|
||||
event.GUIEvent.EventType = EGET_COMBO_BOX_CHANGED;
|
||||
Parent->OnEvent(event);
|
||||
}
|
||||
@ -447,12 +456,23 @@ void CGUIComboBox::openCloseMenu()
|
||||
// close list box
|
||||
Environment->setFocus(this);
|
||||
ListBox->remove();
|
||||
ListBox = 0;
|
||||
ListBox = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Parent)
|
||||
if (Parent) {
|
||||
SEvent event;
|
||||
event.EventType = EET_GUI_EVENT;
|
||||
event.GUIEvent.Caller = this;
|
||||
event.GUIEvent.Element = nullptr;
|
||||
event.GUIEvent.EventType = EGET_LISTBOX_OPENED;
|
||||
|
||||
// Allow to prevent the listbox from opening.
|
||||
if (Parent->OnEvent(event))
|
||||
return;
|
||||
|
||||
Parent->bringToFront(this);
|
||||
}
|
||||
|
||||
IGUISkin* skin = Environment->getSkin();
|
||||
u32 h = Items.size();
|
||||
|
@ -55,6 +55,10 @@ namespace gui
|
||||
//! sets the selected item. Set this to -1 if no item should be selected
|
||||
void setSelected(s32 idx) override;
|
||||
|
||||
//! Sets the selected item and emits a change event.
|
||||
/** Set this to -1 if no item should be selected */
|
||||
void setAndSendSelected(s32 idx) override;
|
||||
|
||||
//! sets the text alignment of the text part
|
||||
void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) override;
|
||||
|
||||
|
Reference in New Issue
Block a user