Skip to content
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

Merged
merged 1 commit into from
May 9, 2023

Conversation

the-sink
Copy link
Contributor

Copies the get_item_icon_modulate and set_item_icon_modulate functionality already present in the ItemList class over to PopupMenu. 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?

image

Copy link
Member

@bruvzg bruvzg left a 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);

scene/gui/popup_menu.cpp Outdated Show resolved Hide resolved
@the-sink the-sink requested a review from a team as a code owner December 19, 2022 06:23
@Chaosus Chaosus added this to the 4.0 milestone Dec 19, 2022
@Chaosus
Copy link
Member

Chaosus commented Dec 19, 2022

@the-sink the-sink force-pushed the popupmenu_icon_modulate branch from c304dd7 to 1705a54 Compare December 19, 2022 08:10
@the-sink
Copy link
Contributor Author

@Chaosus Rebased, and... reading through all the contributing docs is probably in order! Appreciate it.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Multiply icon color by the custom modulate color
// Multiply icon color by the custom modulate color.

Although I think this comment isn't necessary.

Copy link
Contributor Author

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.

@KoBeWi
Copy link
Member

KoBeWi commented Dec 21, 2022

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.

@YuriSizov
Copy link
Contributor

The PR looks ok functionality-wise, but it's not linked to any proposal

It's for godotengine/godot-proposals#768, to at least unlock that ability so the proposal can be implemented as a plugin.

@the-sink
Copy link
Contributor Author

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.

Referring to the icon_modulate for individual PopupMenu items? I agree that would be good to expose to the inspector, although as far as I can tell ItemList doesn't expose that option either. Do you think it would be better to expose the parameter for both classes in a separate PR or just do it here?

@KoBeWi
Copy link
Member

KoBeWi commented Dec 22, 2022

Do you think it would be better to expose the parameter for both classes in a separate PR or just do it here?

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.

Copy link
Member

@KoBeWi KoBeWi left a 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.

@the-sink the-sink force-pushed the popupmenu_icon_modulate branch from 1705a54 to cba440c Compare December 23, 2022 00:21
@akien-mga akien-mga modified the milestones: 4.0, 4.x Feb 10, 2023
@akien-mga
Copy link
Member

Needs a rebase, then it should be ready to merge :)

@the-sink the-sink force-pushed the popupmenu_icon_modulate branch 5 times, most recently from 34e7961 to 09deeb0 Compare April 30, 2023 06:11
@the-sink
Copy link
Contributor Author

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) {
Copy link
Member

@akien-mga akien-mga May 8, 2023

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)

Copy link
Contributor Author

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!

@the-sink the-sink force-pushed the popupmenu_icon_modulate branch from 09deeb0 to cac92c9 Compare May 8, 2023 22:23
@the-sink the-sink force-pushed the popupmenu_icon_modulate branch from cac92c9 to a85eef4 Compare May 8, 2023 22:25
@akien-mga akien-mga merged commit e0df3be into godotengine:master May 9, 2023
@akien-mga
Copy link
Member

Thanks!

@the-sink the-sink deleted the popupmenu_icon_modulate branch May 9, 2023 15:47
@akien-mga akien-mga changed the title Add icon_modulate set/get functionality to PopupMenu Add icon_modulate set/get functionality to PopupMenu May 10, 2023
@akien-mga akien-mga modified the milestones: 4.x, 4.1 May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants