Nested Components Challenge:
I have encountered an issue while attempting to add a background color to GtkComboBoxText.
In my approach, I obtain the widget's context and apply CSS styling to it:
* { background: red }
Surprisingly, this method does not alter the color of GtkComboBoxText. However, it successfully affects GtkButton and GtkLabel components.
Upon inspection with GtkInspector, it appears that GtkComboBoxText contains nested controls such as GtkToggleButton and GtkEntry which are not affected by the previously applied CSS. I have tried manually traversing through all the nested components using gtk_container_forall(..), selecting the specific elements, and then applying background coloring. While this workaround works, I am unable to find a way to globally apply the CSS to GtkComboBoxText and have it automatically cascade down to all its children.
Is there a method to achieve this?
Test Snippet Overview
A test snippet can be accessed in the repository: https://github.com/LeoUfimtsev/LeoGtk3/tree/3_GtkCombo_background
To execute the snippet:
git clone https://github.com/LeoUfimtsev/LeoGtk3.git
make
./main
Potential Solutions Attempted:
* {background:red}
* {background-color:red} // no visible change
GtkComboBoxText * { background: red}
GtkComboBoxText * { background-color: red}
Note to Consider:
If I run the snippet, access the CSS inspector, and individually apply:
* {background: red}
To each separate sub-widget:
GtkComboBoxText
- GtkToggleButton <<
- GtkTreeMenu <<
the background coloring is successful.
Edit - Implementing Style Classes?
One potential solution involves adding a style class to a specific widget and subsequently selecting it from the global CSS. A reference example can be found here: https://github.com/LeoUfimtsev/LeoGtk3/blob/057884368bf38a626dbaac5c575c15a5e1c93f2f/main.c#L35
However, this approach may prove impractical when implementing a graphics library on top of GTK due to the large number of classes that would need to be managed.