I'm building a GUI using R and gWidgets (primarily with RGtk2 toolkit). This GUI will display in some places labels based on a (data-defined) string. This string can be arbitrarily long, but if it is too long it will break the GUI because it will force the widget to enlarge, therefore enlarging all the parents.
So, I need to trim the string to a length based on the space available for the label. I can see two solutions:
Force the glabel to have a max size = the size of its parent; this does not appear to be doable, but I'm happy to be corrected here;
determine the length of the string and, if it is too long, clip it before rendering. This seems easier, probably using low level pango functions, but I can not find out how to use them.
Pseudocode:
interface <- gwindow()
text <- "A Very very long label just to see what happens if you try to deliberately break the identification panel with stupidly long strings"
box <- gvbox(cont = interface)
lab <- glabel(text = text, cont = box)
Idea 1:
lab <- glabel(text = text, cont = box,maxsize = size(box))
Idea 2:
strLength <- strwidth(text, font = ???)
if strLength > size(box)[1] {
# Do something about it...
}
Here my problem is the syntax of font=
. How can I read the definition of the font currently used by the widget, and convert it to R-friendly font syntax? Or is there perhaps a better way (low level pango function?) to get the string size?