-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Add icon_modulate
set/get functionality to PopupMenu
#70286
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New methods should be exposed to the GDScript (add the following code to the PopupMenu::_bind_methods
) and documented (see Contributing to the class reference).
ClassDB::bind_method(D_METHOD("set_item_icon_modulate", "index", "modulate"), &PopupMenu::set_item_icon_modulate);
ClassDB::bind_method(D_METHOD("get_item_icon_modulate", "index"), &PopupMenu::get_item_icon_modulate);
@the-sink You need to squash the commits (see https://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html#modifying-a-pull-request) |
c304dd7
to
1705a54
Compare
@Chaosus Rebased, and... reading through all the contributing docs is probably in order! Appreciate it. |
scene/gui/popup_menu.cpp
Outdated
@@ -612,6 +612,9 @@ void PopupMenu::_draw_items() { | |||
|
|||
Color icon_color(1, 1, 1, items[i].disabled && !items[i].separator ? 0.5 : 1); | |||
|
|||
// Multiply icon color by the custom modulate color |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Multiply icon color by the custom modulate color | |
// Multiply icon color by the custom modulate color. |
Although I think this comment isn't necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I agree the comment is unnecessary - will go ahead and remove it.
The PR looks ok functionality-wise, but it's not linked to any proposal (although I get how parity with ItemList somewhat justifies it). I think it's missing being exposed to the inspector; you can only set modulate from code. Check how other properties are exposed and you could do the same. |
It's for godotengine/godot-proposals#768, to at least unlock that ability so the proposal can be implemented as a plugin. |
Referring to the |
I remember ItemList has many properties that were not exposed to not bloat the list, so maybe it's better to not do it at all. I'd wait until there is some actual demand. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine, aside from the comment I commented about.
1705a54
to
cba440c
Compare
Needs a rebase, then it should be ready to merge :) |
34e7961
to
09deeb0
Compare
Should be good now! |
@@ -1249,6 +1251,15 @@ void PopupMenu::set_item_icon_max_width(int p_idx, int p_width) { | |||
_menu_changed(); | |||
} | |||
|
|||
void PopupMenu::set_item_icon_modulate(int p_idx, const Color &p_modulate) { | |||
if (items[p_idx].icon_modulate == p_modulate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to validate the index like in all other PopupMenu setters:
if (p_idx < 0) {
p_idx += get_item_count();
}
ERR_FAIL_INDEX(p_idx, items.size());
The CI caught a crash here:
GDSCRIPT CODE: PopupMenu.new().set_item_icon_modulate(100, Color(100, 100, 100, 1))
ERROR: FATAL: Index p_index = 100 is out of bounds (size() = 0).
at: get (./core/templates/cowdata.h:155)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, didn't notice during the rebase, thanks!
09deeb0
to
cac92c9
Compare
cac92c9
to
a85eef4
Compare
Thanks! |
icon_modulate
set/get functionality to PopupMenu
Copies the
get_item_icon_modulate
andset_item_icon_modulate
functionality already present in theItemList
class over toPopupMenu
. I need this to be able to give different colors to items that have the same icon in a dropdown, so I'm guessing others may find the functionality useful as well?