Skip to content

Add support for multi-byte chars like emojis (💡) in light device toggle buttons#24482

Open
aschober wants to merge 4 commits intoarendst:developmentfrom
aschober:light_webbutton_emojis
Open

Add support for multi-byte chars like emojis (💡) in light device toggle buttons#24482
aschober wants to merge 4 commits intoarendst:developmentfrom
aschober:light_webbutton_emojis

Conversation

@aschober
Copy link
Contributor

@aschober aschober commented Feb 22, 2026

Description:

Improve UTF-8 handling for light device toggle button labels (including emojis like 💡) by truncating safely before rendering.

  • Add a UTF-8-aware truncation helper that avoids splitting multibyte characters and supports approximated visual-width limits for wider characters like CJK and emoji.
  • When no WebButton string exists, fix non-English truncation by replacing the "fixed 1-byte truncation" with UTF-8-safe truncation to get the first, full codepoint from D_BUTTON_TOGGLE.
  • When a WebButton string exists, replace the "fixed 3-byte truncation" with UTF-8-safe truncation based on a max of 4 codepoints and max visual width of 4.
  • Cache WebButton text once per render block and reuse it (has_web_button) to avoid repeated lookups.

Related issue (if applicable): fixes #

Checklist:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.8
  • The code change is tested and works with Tasmota core ESP32 V.3.1.10
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

…bels for light device toggle buttons

- Remove the 3-character buffer truncation of light device toggle button labels allowing multi-byte characters like emojis
- Rely on CSS to handle truncation and add `max-width:0` to the td so it respects the provided percentage width instead of expanding to fit content
- Wrap button content in a span with overflow handling to prevent layout breakage
- Add `Utf8Truncate` function in `support.ino` to truncate UTF-8 strings to a max chars limit or max visual width limit
- Truncate light device button text to max 4 chars or max width of 4 before passing to button HTML template
- cache calls to GetWebButton so only called once and update bool var from `set_button` to `has_web_button`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants