a question about extending class editbox or other

Started by arturo.tramontini, 30 September 2015, 19:35:57

arturo.tramontini

I would add to the edit box a different text color when they are enabled or disabled.
there is an easy way to add this property to editbox?
(only with the application program, without touching the library TGUI v0.7)

I saw that if the edit boxes are added to a panel, these inherit the enabled / disabled state of the panel.

However, they do not have a visual indication of this state.

currently, I change the color of text one by one.



I saw that you can make a class that inherits the EditBox and add a method (for example add ebxC ())

The compilation does not give error.
But I do not know if / or how it can be added to a panel.

if there was a simple solution and you give me an example I would be grateful.
Anyway thank you very much.

Arturo

(translated from Italian by Google)

texus

QuoteI saw that if the edit boxes are added to a panel, these inherit the enabled / disabled state of the panel.
This is only partly true. Technically they don't inherit it so if you check whether the edit box is enabled or disabled it will still report that it is enabled even though the panel to which it was added is disabled. But all events travel from parent to parent (gui -> panel -> edit box) so when the panel is disabled no events will reach the edit box.

QuoteI saw that you can make a class that inherits the EditBox and add a method
Creating a custom widget that inherits from EditBox is one way to solve the problem, however the tutorial for custom widgets is not written yet and there are a few small catches so this may not be so easy.

It may not be the best way, but I think just looping over all edit boxes is probably the easiest way. The enablePanel function would be similar.
Code (cpp) Select
void disablePanel(tgui::Panel::Ptr panel)
{
    panel->disable();
    for (auto& widget : panel->getWidgets())
    {
        if (widget->getWidgetType() == "editbox")
            std::static_pointer_cast<tgui::EditBox>(widget)->getRenderer()->setTextColor(color);
    }
}