Add item_focused signal to OptionButton

And id_focused to Popupmenu.
This commit is contained in:
Fabio Alessandrelli 2018-01-12 02:53:35 +01:00
parent 90b9449844
commit ff122a7e1f
3 changed files with 11 additions and 0 deletions

View file

@ -75,6 +75,10 @@ void OptionButton::_notification(int p_what) {
}
}
void OptionButton::_focused(int p_which) {
emit_signal("item_focused", p_which);
}
void OptionButton::_selected(int p_which) {
int selid = -1;
@ -290,6 +294,7 @@ void OptionButton::get_translatable_strings(List<String> *p_strings) const {
void OptionButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("_selected"), &OptionButton::_selected);
ClassDB::bind_method(D_METHOD("_focused"), &OptionButton::_focused);
ClassDB::bind_method(D_METHOD("add_item", "label", "id"), &OptionButton::add_item, DEFVAL(-1));
ClassDB::bind_method(D_METHOD("add_icon_item", "texture", "label", "id"), &OptionButton::add_icon_item);
@ -322,6 +327,7 @@ void OptionButton::_bind_methods() {
// "selected" property must come after "items", otherwise GH-10213 occurs
ADD_PROPERTY(PropertyInfo(Variant::INT, "selected"), "_select_int", "get_selected");
ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "ID")));
ADD_SIGNAL(MethodInfo("item_focused", PropertyInfo(Variant::INT, "ID")));
}
OptionButton::OptionButton() {
@ -336,6 +342,7 @@ OptionButton::OptionButton() {
popup->set_as_toplevel(true);
popup->set_pass_on_modal_close_click(false);
popup->connect("id_pressed", this, "_selected");
popup->connect("id_focused", this, "_focused");
}
OptionButton::~OptionButton() {

View file

@ -43,6 +43,7 @@ class OptionButton : public Button {
PopupMenu *popup;
int current;
void _focused(int p_which);
void _selected(int p_which);
void _select(int p_which, bool p_emit = false);
void _select_int(int p_which);

View file

@ -225,6 +225,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
emit_signal("id_focused", i);
update();
accept_event();
break;
@ -244,6 +245,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
emit_signal("id_focused", i);
update();
accept_event();
break;
@ -1210,6 +1212,7 @@ void PopupMenu::_bind_methods() {
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_state_item_selection"), "set_hide_on_state_item_selection", "is_hide_on_state_item_selection");
ADD_SIGNAL(MethodInfo("id_pressed", PropertyInfo(Variant::INT, "ID")));
ADD_SIGNAL(MethodInfo("id_focused", PropertyInfo(Variant::INT, "ID")));
ADD_SIGNAL(MethodInfo("index_pressed", PropertyInfo(Variant::INT, "index")));
}