Is there a way to fit long text in a grid with ellipsis?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Here is an example of what I mean -
The above images are arranged in a Grid layout (using GUI Layout Toolbox), so each axes are in their own uicontainer, which means any text from one grid will be overlaid on top by the a subsequent grid, therefore hiding the text if it's beyond the boundary of its own grid. As you can see, the texts (.170) and (.txt) are partially hidden because of this.
To solve this problem, one would have to replace the extra text with ellipsis (...) to shorten the text and make it fit into the grid. An example is the Windows explorer, showing below, where the text (.170) is replaced with (.1...) as it is shorter in length.
Apparently, this requires the dertermination of the width (or length) of the actual text, which has a lot to do with the font size and font used. Unless it's monospaced font, using number of characters to determine the length is not enough. For example, 'iii' is much shorter than 'DDD' in width.
In MATLAB, although you can determine the width of the graphics text object, the extent of the box that encloses the text is a read-only property, therefore it's not possible to restrict the width of the text object (and MATLAB also has to know to put ellipsis when the text is restrained). A lengthy workaround would be to calculate the width of the text based on its font and font size, and if it's wider than the grid, you'll have to iteratively shortern its characters one by one and determine whether the shortened text would fit inside the grid, while adding ellipsis into the mix.
2 Commenti
Adam Danz
il 26 Gen 2020
Modificato: Adam Danz
il 26 Gen 2020
I don't have this toolbox so I can't play around with it but you could putting line breaks in to the text such as
s = ['Protein-DNA',newline,'complex.txt'];
% or
s = sprintf('Protein_DNA\ncomplex.txt');
I have no idea if the line break will be interpreted correctly or whether the 2nd line will be cut off.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!