Set different text colors to ComboBox items

  • 5 Replies
  • 242 Views
Set different text colors to ComboBox items
« on: 10 March 2019, 11:41:25 »
Hi everyone!
Is it possible to set a different color to specific items? I want to add item with grey color, which will mean that the item is not available.

Or how can I hide selected item from items list? Or is there any function like tgui::EditBox::setDefaultText? sorry for my bad English=)

*

texus

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: Set different text colors to ComboBox items
« Reply #1 on: 10 March 2019, 11:54:38 »
Quote
Is it possible to set a different color to specific items?
This is currently not possible.

Quote
I want to add item with grey color, which will mean that the item is not available.
Would you still want the user to be able to select the item? If not then it would be better not to include the item.

Quote
how can I hide selected item from items list?
In order to hide items from a list, just clear the list and fill it again with the items you want to show.

Quote
is there any function like tgui::EditBox::setDefaultText?
What should the function do exactly? Place some text in the ComboBox when none of its items are selected yet?

Re: Set different text colors to ComboBox items
« Reply #2 on: 10 March 2019, 12:32:14 »
I'm making music game which uses MIDI ports. If users were using some port(port 1) and it becomes unavailable, I want to let them know, which port they were using last time
this example I made in Photoshop
https://www.dropbox.com/s/f4fpmsm2lmn1gfm/ComboBox.png?dl=0

Re: Set different text colors to ComboBox items
« Reply #3 on: 10 March 2019, 12:44:53 »
What should the function do exactly? Place some text in the ComboBox when none of its items are selected yet?
Yes

*

texus

  • *****
  • 1463
    • View Profile
    • Texus's Blog
Re: Set different text colors to ComboBox items
« Reply #4 on: 10 March 2019, 18:34:16 »
The top example in your image would be harder to implement as it requires being able to set a different color for each item.
The bottom example can be implemented by just adding a default text. When the port becomes unavailable you just have to deselect the item, remove it from the list and set the default text.

So if it is enough for you then I'll just add a DefaultText property to ComboBox and a DefaultTextColor property to ComboBoxRenderer.

Edit: the default text was added to ComboBox (in the version that can be downloaded on github)
« Last Edit: 10 March 2019, 19:37:29 by texus »

Re: Set different text colors to ComboBox items
« Reply #5 on: 11 March 2019, 04:49:28 »
Thank you very much!