cancel
Showing results for 
Search instead for 
Did you mean: 

Highlight a character within a text

AWies.1
Associate III

I would like to highlight a single character within the text of a flex button. In my application I have an encoder with a button, which can change the numerical value displayed in certain increments, and I would like to switch the position of the highlighted character with each button click, thus indicating that different increments are used. Nice would be something like 123456 or 123456. I actually do not care much about the method for highlighting the character, so it can be a different color, bold face, underline, whatever, as long as it is highlighted. Is there a simple way for doing this? Are there any control sequences available for the text, for example "\u" to indicate that now the text should get underlined?

9 REPLIES 9
MM..1
Chief II

Hi,

i mean you have only one way, place over next text, calculate x,y and show one highlighted char in textarea.

Hi,

I agree with MM, it is the easiest solution especialy for the higligted char: have the flex button write "abc e" and a textarea overt it with the letter you want to highlight " d ". The logic needs to be done through code to be able to navigate within the text. Here is a cursor demo I did a while back. It might help you get some inspiration on how to do your own on a flex button.

/Romain

simpler is leave "abcde" and only next "d" over

you are right as this will make sure you have the right width if you do not use a monospace font (where letters do not all have the same width and height).

AWies.1
Associate III

I looked at the cursor example, and think I will try a different approach. I will pack the flex button in a container, use a monospace font, overlay the flex button with a text field and then write a text with an underscore character '_' at the right position.

perfect :ok_hand: Do not hesitate to share this here if other users could be interested by your solution.

/Romain

I mean your idea will not work and when you plan only underscore marking you dont need other text, only move an graphics element line .

Underscored font in your second text is used for all characters then all is underscored maybe too spaces.

yes the "abc e" idea was not for the underscore but for the highlighted character.

AWies.1
Associate III

Overlaying the flex button with a text field worked. I was using a monospace font (Deja Vu, since that font is available in all kinds of variations, proportional and monospace). Marking the position was as easy as writing an underscore ‘_’ character into the buffer of the text field at the right position. I dropped the idea of packing this into a container, since the additional complication I am getting with the container did not outweigh the additional code I need to write if I use this method in several places. I did not check this, but in theory this method should also work for highlighting a character in a different color or with the boldface variation of the font.