Merge pull request #15046 from YeldhamDev/optionbutton_changes
Added "get_popup" method for OptionButton
This commit is contained in:
commit
07d0f2e72b
3 changed files with 49 additions and 35 deletions
|
@ -91,6 +91,13 @@
|
|||
Return the text of the item at index "idx".
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_popup" qualifiers="const">
|
||||
<return type="PopupMenu">
|
||||
</return>
|
||||
<description>
|
||||
Return the [PopupMenu] contained in this button.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_selected_id" qualifiers="const">
|
||||
<return type="int">
|
||||
</return>
|
||||
|
|
|
@ -42,38 +42,35 @@ Size2 OptionButton::get_minimum_size() const {
|
|||
|
||||
void OptionButton::_notification(int p_what) {
|
||||
|
||||
switch (p_what) {
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
if (!has_icon("arrow"))
|
||||
return;
|
||||
|
||||
if (!has_icon("arrow"))
|
||||
return;
|
||||
RID ci = get_canvas_item();
|
||||
Ref<Texture> arrow = Control::get_icon("arrow");
|
||||
Ref<StyleBox> normal = get_stylebox("normal");
|
||||
Color clr = Color(1, 1, 1);
|
||||
if (get_constant("modulate_arrow")) {
|
||||
switch (get_draw_mode()) {
|
||||
case DRAW_PRESSED:
|
||||
clr = get_color("font_color_pressed");
|
||||
break;
|
||||
case DRAW_HOVER:
|
||||
clr = get_color("font_color_hover");
|
||||
break;
|
||||
case DRAW_DISABLED:
|
||||
clr = get_color("font_color_disabled");
|
||||
break;
|
||||
default:
|
||||
clr = get_color("font_color");
|
||||
}
|
||||
}
|
||||
|
||||
RID ci = get_canvas_item();
|
||||
Ref<Texture> arrow = Control::get_icon("arrow");
|
||||
Ref<StyleBox> normal = get_stylebox("normal");
|
||||
Color clr = Color(1, 1, 1);
|
||||
if (get_constant("modulate_arrow"))
|
||||
switch (get_draw_mode()) {
|
||||
case DRAW_PRESSED:
|
||||
clr = get_color("font_color_pressed");
|
||||
break;
|
||||
case DRAW_HOVER:
|
||||
clr = get_color("font_color_hover");
|
||||
break;
|
||||
case DRAW_DISABLED:
|
||||
clr = get_color("font_color_disabled");
|
||||
break;
|
||||
default:
|
||||
clr = get_color("font_color");
|
||||
}
|
||||
Size2 size = get_size();
|
||||
|
||||
Size2 size = get_size();
|
||||
|
||||
Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
|
||||
arrow->draw(ci, ofs, clr);
|
||||
|
||||
} break;
|
||||
Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
|
||||
arrow->draw(ci, ofs, clr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,6 +241,11 @@ void OptionButton::remove_item(int p_idx) {
|
|||
popup->remove_item(p_idx);
|
||||
}
|
||||
|
||||
PopupMenu *OptionButton::get_popup() const {
|
||||
|
||||
return popup;
|
||||
}
|
||||
|
||||
Array OptionButton::_get_items() const {
|
||||
|
||||
Array items;
|
||||
|
@ -310,6 +312,8 @@ void OptionButton::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("remove_item", "idx"), &OptionButton::remove_item);
|
||||
ClassDB::bind_method(D_METHOD("_select_int"), &OptionButton::_select_int);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_popup"), &OptionButton::get_popup);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_set_items"), &OptionButton::_set_items);
|
||||
ClassDB::bind_method(D_METHOD("_get_items"), &OptionButton::_get_items);
|
||||
|
||||
|
@ -320,15 +324,16 @@ void OptionButton::_bind_methods() {
|
|||
|
||||
OptionButton::OptionButton() {
|
||||
|
||||
popup = memnew(PopupMenu);
|
||||
popup->hide();
|
||||
popup->set_as_toplevel(true);
|
||||
popup->set_pass_on_modal_close_click(false);
|
||||
add_child(popup);
|
||||
popup->connect("id_pressed", this, "_selected");
|
||||
|
||||
current = -1;
|
||||
set_text_align(ALIGN_LEFT);
|
||||
set_action_mode(ACTION_MODE_BUTTON_PRESS);
|
||||
|
||||
popup = memnew(PopupMenu);
|
||||
popup->hide();
|
||||
add_child(popup);
|
||||
popup->set_as_toplevel(true);
|
||||
popup->set_pass_on_modal_close_click(false);
|
||||
popup->connect("id_pressed", this, "_selected");
|
||||
}
|
||||
|
||||
OptionButton::~OptionButton() {
|
||||
|
|
|
@ -85,6 +85,8 @@ public:
|
|||
|
||||
void remove_item(int p_idx);
|
||||
|
||||
PopupMenu *get_popup() const;
|
||||
|
||||
virtual void get_translatable_strings(List<String> *p_strings) const;
|
||||
|
||||
OptionButton();
|
||||
|
|
Loading…
Reference in a new issue