Add support for per-element RGB color code toggling in GUI elements#4961
Open
TheCrazy17 wants to merge 3 commits into
Open
Add support for per-element RGB color code toggling in GUI elements#4961TheCrazy17 wants to merge 3 commits into
TheCrazy17 wants to merge 3 commits into
Conversation
Implements GH issue multitheftauto#4433. GUI text elements (labels, buttons, edit boxes, etc.) now parse #RRGGBB sequences as inline color changes. Any '#' not followed by exactly 6 hex digits is treated as a literal character. guiSetText(label, "#FF0000Red #00FF00Green #0000FFBlue") The alpha of the original widget colour is preserved across color changes. Color codes are skipped in getTextExtent() and getCharAtPixel() so they have no visual width and do not affect text layout or cursor positioning. Both left-aligned (drawTextLine) and justified (drawTextLineJustified) rendering paths are covered.
Color codes are now OFF by default, preserving full backward compatibility. Scripts opt in per element: guiSetColorCodesEnabled(element, true) -- enable #RRGGBB parsing guiSetColorCodesEnabled(element, false) -- disable (default) guiGetColorCodesEnabled(element) -- query state element.colorCodesEnabled = true -- OOP style Implementation: Font::s_colorCodesEnabled (default false) is set inside Window::drawSelf() from a per-window UserString before populateRenderCache() is called, then reset to false. This keeps the toggle contained to the render-cache rebuild phase without touching individual widget types.
Adds \guiSetColorCodesEnabled\, allowing RGB color codes to be toggled on a per-element basis. - Fixes issues where complex Falagard widgets (Buttons, Checkboxes) ignored color codes. - Implements inheritance so internal components (Titlebars, TabButtons) respect their parent's setting. - Adds an optional \includeChildren\ parameter to apply the toggle recursively.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Added RGB color code support for GUI elements, allowing inline color formatting across all supported GUI controls.
guiSetColorCodesEnabled(guiElement, enabled [, includeChilds = false])When includeChilds is true, the function recursively applies the color code state to all child GUI elements, making it easy to enable or disable RGB color codes for an entire GUI hierarchy with a single call.
Screenshots
Motivation
Finally, RGB color codes are supported in MTA GUI elements.
This change adds consistent inline color formatting across GUI components such as windows, labels, buttons, checkboxes, radio buttons, tabs, grid lists (headers and rows), edit boxes, memos, combo boxes, and title bars.
Closes #4433.
Test plan
Tested client-side using the following script to verify that all supported GUI elements correctly render RGB color codes and update immediately when color codes are enabled or disabled recursively.
The test verifies:
guiSetColorCodesEnabled(element, enabled, true).Checklist