Add icon_modulate functionality to PopupMenu
This commit is contained in:
parent
9f12e7b52d
commit
a85eef4367
3 changed files with 41 additions and 0 deletions
|
@ -209,6 +209,13 @@
|
|||
Returns the maximum allowed width of the icon for the item at the given [param index].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_item_icon_modulate" qualifiers="const">
|
||||
<return type="Color" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<description>
|
||||
Returns a [Color] modulating the item's icon at the given [param index].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_item_id" qualifiers="const">
|
||||
<return type="int" />
|
||||
<param index="0" name="index" type="int" />
|
||||
|
@ -412,6 +419,14 @@
|
|||
Sets the maximum allowed width of the icon for the item at the given [param index]. This limit is applied on top of the default size of the icon and on top of [theme_item icon_max_width]. The height is adjusted according to the icon's ratio.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_item_icon_modulate">
|
||||
<return type="void" />
|
||||
<param index="0" name="index" type="int" />
|
||||
<param index="1" name="modulate" type="Color" />
|
||||
<description>
|
||||
Sets a modulating [Color] of the item's icon at the given [param index].
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_item_id">
|
||||
<return type="void" />
|
||||
<param index="0" name="index" type="int" />
|
||||
|
|
|
@ -635,6 +635,8 @@ void PopupMenu::_draw_items() {
|
|||
|
||||
Color icon_color(1, 1, 1, items[i].disabled && !items[i].separator ? 0.5 : 1);
|
||||
|
||||
icon_color *= items[i].icon_modulate;
|
||||
|
||||
// For non-separator items, add some padding for the content.
|
||||
item_ofs.x += theme_cache.item_start_padding;
|
||||
|
||||
|
@ -1249,6 +1251,20 @@ 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 (p_idx < 0) {
|
||||
p_idx += get_item_count();
|
||||
}
|
||||
ERR_FAIL_INDEX(p_idx, items.size());
|
||||
|
||||
if (items[p_idx].icon_modulate == p_modulate) {
|
||||
return;
|
||||
}
|
||||
|
||||
items.write[p_idx].icon_modulate = p_modulate;
|
||||
control->queue_redraw();
|
||||
}
|
||||
|
||||
void PopupMenu::set_item_checked(int p_idx, bool p_checked) {
|
||||
if (p_idx < 0) {
|
||||
p_idx += get_item_count();
|
||||
|
@ -1392,6 +1408,11 @@ int PopupMenu::get_item_icon_max_width(int p_idx) const {
|
|||
return items[p_idx].icon_max_width;
|
||||
}
|
||||
|
||||
Color PopupMenu::get_item_icon_modulate(int p_idx) const {
|
||||
ERR_FAIL_INDEX_V(p_idx, items.size(), Color());
|
||||
return items[p_idx].icon_modulate;
|
||||
}
|
||||
|
||||
Key PopupMenu::get_item_accelerator(int p_idx) const {
|
||||
ERR_FAIL_INDEX_V(p_idx, items.size(), Key::NONE);
|
||||
return items[p_idx].accel;
|
||||
|
@ -2102,6 +2123,7 @@ void PopupMenu::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_item_language", "index", "language"), &PopupMenu::set_item_language);
|
||||
ClassDB::bind_method(D_METHOD("set_item_icon", "index", "icon"), &PopupMenu::set_item_icon);
|
||||
ClassDB::bind_method(D_METHOD("set_item_icon_max_width", "index", "width"), &PopupMenu::set_item_icon_max_width);
|
||||
ClassDB::bind_method(D_METHOD("set_item_icon_modulate", "index", "modulate"), &PopupMenu::set_item_icon_modulate);
|
||||
ClassDB::bind_method(D_METHOD("set_item_checked", "index", "checked"), &PopupMenu::set_item_checked);
|
||||
ClassDB::bind_method(D_METHOD("set_item_id", "index", "id"), &PopupMenu::set_item_id);
|
||||
ClassDB::bind_method(D_METHOD("set_item_accelerator", "index", "accel"), &PopupMenu::set_item_accelerator);
|
||||
|
@ -2125,6 +2147,7 @@ void PopupMenu::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_item_language", "index"), &PopupMenu::get_item_language);
|
||||
ClassDB::bind_method(D_METHOD("get_item_icon", "index"), &PopupMenu::get_item_icon);
|
||||
ClassDB::bind_method(D_METHOD("get_item_icon_max_width", "index"), &PopupMenu::get_item_icon_max_width);
|
||||
ClassDB::bind_method(D_METHOD("get_item_icon_modulate", "index"), &PopupMenu::get_item_icon_modulate);
|
||||
ClassDB::bind_method(D_METHOD("is_item_checked", "index"), &PopupMenu::is_item_checked);
|
||||
ClassDB::bind_method(D_METHOD("get_item_id", "index"), &PopupMenu::get_item_id);
|
||||
ClassDB::bind_method(D_METHOD("get_item_index", "id"), &PopupMenu::get_item_index);
|
||||
|
|
|
@ -43,6 +43,7 @@ class PopupMenu : public Popup {
|
|||
struct Item {
|
||||
Ref<Texture2D> icon;
|
||||
int icon_max_width = 0;
|
||||
Color icon_modulate = Color(1, 1, 1, 1);
|
||||
String text;
|
||||
String xl_text;
|
||||
Ref<TextLine> text_buf;
|
||||
|
@ -226,6 +227,7 @@ public:
|
|||
void set_item_language(int p_idx, const String &p_language);
|
||||
void set_item_icon(int p_idx, const Ref<Texture2D> &p_icon);
|
||||
void set_item_icon_max_width(int p_idx, int p_width);
|
||||
void set_item_icon_modulate(int p_idx, const Color &p_modulate);
|
||||
void set_item_checked(int p_idx, bool p_checked);
|
||||
void set_item_id(int p_idx, int p_id);
|
||||
void set_item_accelerator(int p_idx, Key p_accel);
|
||||
|
@ -250,6 +252,7 @@ public:
|
|||
int get_item_idx_from_text(const String &text) const;
|
||||
Ref<Texture2D> get_item_icon(int p_idx) const;
|
||||
int get_item_icon_max_width(int p_idx) const;
|
||||
Color get_item_icon_modulate(int p_idx) const;
|
||||
bool is_item_checked(int p_idx) const;
|
||||
int get_item_id(int p_idx) const;
|
||||
int get_item_index(int p_id) const;
|
||||
|
|
Loading…
Reference in a new issue