raysan5 / raygui

A simple and easy-to-use immediate-mode gui library
zlib License
3.47k stars 298 forks source link

Text-styling properties configuration #328

Open raysan5 opened 1 year ago

raysan5 commented 1 year ago

Beside the font used, raygui supports multiple text-styling properties for controls text drawing. At this moment some text-styling properties can be configured by-control while some other properties are global for all controls.

Per-control properties:

Global properties:

In any case, those properties can be set by user before drawing each control for a per-control configuration but in the case of per-control properties they are saved individually with the style while with the global properties they must be set at runtime depending on the user needs.

Also, all those properties determine how GetTextBounds() is calculated and how GuiDrawText() behaves (functions used by all controls).

I'm considering unifying all those properties per-control or global but I'm seing multiple issues... because some current per-control properties should probably stay configured per control...

raysan5 commented 1 year ago

Some more info while investigating those properties:

At this moment TEXT_PADDING and TEXT_ALIGNMENT are set by control, here the custom values set by default raygui style plus some concerns:

GuiSetStyle(TEXTBOX, TEXT_PADDING, 4);      // OK: text inner padding from bounds
GuiSetStyle(STATUSBAR, TEXT_PADDING, 8);    // OK: text inner padding from bounds -> TEXT_INDENTATION?
GuiSetStyle(SLIDER, TEXT_PADDING, 4);       // WARNING: Padding refers to outside label spacing -> LABEL_SEPARATION (using TEXT_PADDING for label text internal content)
GuiSetStyle(PROGRESSBAR, TEXT_PADDING, 4);  // WARNING: Padding refers to outside label spacing -> LABEL_SEPARATION
GuiSetStyle(CHECKBOX, TEXT_PADDING, 4);     // WARNING: Padding refers to outside label spacing -> LABEL_SEPARATION

GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);       // OK: text alignment inside text-bounds
GuiSetStyle(TEXTBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);     // OK: text alignment inside text-bounds
GuiSetStyle(STATUSBAR, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);   // OK: text alignment inside text-bounds
GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);    // WARNING: Text alignment refers to label side on control -> LABEL_SIDE: 0-left, 1-right
GuiSetStyle(SPINNER, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);     // WARNING: Text alignment refers to label side on control -> LABEL_SIDE: 0-left, 1-right
GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_RIGHT);   // WARNING: Text alignment refers to label side on control -> LABEL_SIDE: 0-left, 1-right

Noted that TEXT_PADDING and TEXT_ALIGNMENT usage could be missleading for some controls, not directly referring to padding/alignment inside text-bounds but LABEL positioning around a specific control (SLIDER, PROGRESSBAR, CHECKBOX, VALUEBOX, SPINNER). That functionality should be reviewed, specific properties can be created for affected controls.

raysan5 commented 1 year ago

Still thinking about this issue. Just noticed that for controls not containing text inside the control bounds (SLIDER, PROGRESSBAR, CHECKBOX) text padding and alignment could be used, despite referring to outside labels. It simplifies controls properties.

On the other side, controls actually containing some text inside the control (VALUEBOX, SPINNER) could be missleading and somewhat limit the control capabilities (i.e. the contained value padding and alignment).

a-alhusaini commented 7 months ago

I find it confusing to have both global and per control settings.

My solution is to make all properties apply globally and per control. That way, we get rid of the confusing. Or prefix global properties with a letter like G_ so we know that G_TEXT_ALIGN_VERTICAL is a global property and that properties without the G_ prefix are per control properties.