pydm
pydm copied to clipboard
How to scale font size to widget geometry?
I'm used to a feature in MEDM, caQtDM, and CSS BOY where the font size is automatically determined by the height of the widget (and further limited by the width of the widget and the length of the content to be displayed). Is this possible in PyDM?
Basically, I want this feature. Lots of the synApps screens (such as motorx.adl) depend on it.
@prjemian do you mean autoscale at the font size?
Not sure. What does autoscale mean? Feature I want is described above.
Perhaps like this: https://github.com/caqtdm/caqtdm/blob/2c6d50751ec27b66834a4683cc96a95431fac034/caQtDM_QtControls/src/fontscalingwidget.cpp#L300-L313
We don't have the above described feature. By autoscale I mean increase the font size as the dimensions of the widget is changed. We did some tests for that in a widget https://github.com/slaclab/pydm_clock_widget/blob/master/clockwidget/dynlabel.py but it is baked into the PyDM widgets.
Ouch! That's a big stumbling point for our existing displays.
The feature can for sure be added. I am just not sure on how soon we will get it in. If you would like to take a stab at it I would recommend maybe adding the code into the PyDMPrimitive or even the PyDMWidget class with an option to enable/disable the behavior. That will probably get the font issue addressed.
Or even a mixin class that can be simply added into widgets in which this feature is interesting.
Here's two images of the same MEDM screen with MEDM's two different font selection schemes (using the predefined widget_DM fonts and then using scalable fonts). Both use the widget's height to pick the font size, within some limits.
medm -x "P=ioc:" text_examples.adl
:
medm -x "P=ioc:" -displayFont scalable text_examples.adl
:
Here's a sample of the MEDM screen for a 20-pixel high widget:
text {
object {
x=4
y=213
width=140
height=20
}
"basic attribute" {
clr=14
}
textix="height: 20"
}
Sometimes, MEDM makes a bad choice since it does not constrain the displayed text to the widget's geometry width. Yes, it displays available text to the right of the box for "text" and "text update" widgets.
For caQtDM, a different problem exists. The font size is reduced until the width of the text fits into the widget's height and width. This can lead to unreasonably small font sizes when the width is too small and the content is too long.
These two problems, taken together, have caused us conversion headaches since many MEDM widgets were originally created with trivially small width, knowing that any length of text would be displayed, even if the next widget were overlapped (or underlapped). Then, caQtDM tries to fit that into a small space with awful results. We believe we have found most of these cases.
short story: Setting a minimum font size (say 4 pt) is important. Also, truncate display of long text to fit the available widget geometry (could scroll if that is possible).
Those are good suggestions. I'll keep them in mind for when this gains the priority to resolve it. For now, I plow ahead on completing adl2pydm for the initial release.
That is correct... we learned those lessons while playing with the dynamic label that I pointed up there. Thanks for all the suggestions and input/lessons learned with the feature. It will be very good for when it is time to implement it.
Sorry about the fact that it is not yet available.
Just want to chime in: We don't automatically scale fonts with window size, but we do let you scale the global font size like you can in a browser, with "ctrl +" or "ctrl -".
At the Codeathon today, discussed this briefly. Since a developer is working on this, we might best contribute some thoughts today.
- The choice to scale the font size to the widget geometry is based on the developer. If there is more than one possibililty, let's expose that to the user as an option with the existing method as the default.
- I believe the feature in caQtDM is implemented by examining the bounding box and then choosing the font size1. scaling. It's a choice to scale only looking at the BBox vertical size. In caQtDM, it is apparent than both H&V size are examined since sometimes, with a long text, the font size is made very small to fit the text in the available BBox.