I’m trying to create use a static text control for previewing a font’s properties, and I would like it to behave like the sample static text from the FontDialog, so that sample text that is too large vertically or horizontally is cropped on top, right and bottom, and vertically centered aligned. In my own program, I cannot make the static text to crop the upper portion, it will only crop to the right and bottom, while leaving empty space on the top.
I have attached 2 images that illustrate how the sample area on the FontDialog and my own badly aligned sample look.
I tried for a few minutes goofing around with sizers to see if I could
get this to work, but couldn't. My guess is it isn't possible (though
it seems the native FontDialog knows how to do it.) Let's see if Robin
knows some way...
But on the hand, maybe the best user experience would be to just make
the staticText appropriately large enough to show the full font. That
has to be preferable to one that is partially cut off, no?
···
On Thu, Aug 8, 2013 at 10:04 AM, Alexandru Popa <a.ephesos@gmail.com> wrote:
I'm trying to create use a static text control for previewing a font's
properties, and I would like it to behave like the sample static text from
the FontDialog, so that sample text that is too large vertically or
horizontally is cropped on top, right and bottom, and vertically centered
aligned. In my own program, I cannot make the static text to crop the upper
portion, it will only crop to the right and bottom, while leaving empty
space on the top.
Not sure if this would work (and I haven’t time to give it a shot), but it sounds like you need an image whose position you can control in the dialog. Would it be possible to capture an image of the text in the point size you’ve selected, and then display that image in a picture control?
I'm trying to create use a static text control for previewing a font's
properties, and I would like it to behave like the sample static text from
the FontDialog, so that sample text that is too large vertically or
horizontally is cropped on top, right and bottom, and vertically centered
aligned. In my own program, I cannot make the static text to crop the upper
portion, it will only crop to the right and bottom, while leaving empty
space on the top.
I tried for a few minutes goofing around with sizers to see if I could
get this to work, but couldn't. My guess is it isn't possible (though
it seems the native FontDialog knows how to do it.) Let's see if Robin
knows some way...
If you use a panel there and then put the static text on the panel, then when the text is large it will be automatically clipped by the panel. You can use panel.SetMinSize to control how big it will be and its parent sizers will use that size for the layout.
Once the panel is being used I'm not sure I would continue using the static text, and would instead just draw the text myself in the panel's EVT_PAINT handler. But either way would probably be fine.
···
On Thu, Aug 8, 2013 at 10:04 AM, Alexandru Popa<a.ephesos@gmail.com> wrote:
I made a sample in which I use an inner panel, but still no luck. I’m not sure I understand the panel.SetMinSize advice, wouldn’t it only set the minimum size for that panel? I tried SetMaxSize(), but sizers ignore this constraint and always resize to fit the text instead of cropping it.
The only solution I can thing of is to use the StaticBox without a StaticBoxSizer, but then I’m not sure how to put the StaticText inside the box, considering that there are other sizers in the frame that would interfere with absolute positioning.
Or maybe I didn’t follow your guidelines properly.
On Friday, 9 August 2013 20:37:41 UTC+3, Robin Dunn wrote:
C M wrote:
On Thu, Aug 8, 2013 at 10:04 AM, Alexandru Popaa.ep...@gmail.com wrote:
I’m trying to create use a static text control for previewing a font’s
properties, and I would like it to behave like the sample static text from
the FontDialog, so that sample text that is too large vertically or
horizontally is cropped on top, right and bottom, and vertically centered
aligned. In my own program, I cannot make the static text to crop the upper
portion, it will only crop to the right and bottom, while leaving empty
space on the top.
I tried for a few minutes goofing around with sizers to see if I could
get this to work, but couldn’t. My guess is it isn’t possible (though
it seems the native FontDialog knows how to do it.) Let’s see if Robin
knows some way…
If you use a panel there and then put the static text on the panel, then
when the text is large it will be automatically clipped by the panel.
You can use panel.SetMinSize to control how big it will be and its
parent sizers will use that size for the layout.
Once the panel is being used I’m not sure I would continue using the
static text, and would instead just draw the text myself in the panel’s
EVT_PAINT handler. But either way would probably be fine.
I made a sample in which I use an inner panel, but still no luck. I'm
not sure I understand the panel.SetMinSize advice, wouldn't it only set
the minimum size for that panel?
Yes, but if the static text is larger than that then it will be clipped at the size of the panel (which is what you want, right?) Setting the Panel's min size (or any widget for that matter) will cause the sizers to use that size instead of the best size.
I tried SetMaxSize(), but sizers ignore
this constraint and always resize to fit the text instead of cropping it.
The only solution I can thing of is to use the StaticBox without a
StaticBoxSizer, but then I'm not sure how to put the StaticText inside
the box, considering that there are other sizers in the frame that would
interfere with absolute positioning.
BTW, I just realized that there is an example of something like what you are asking about in the FontDialog sample. It uses a static text to display the chosen font, and the way it is added to the sizer will keep the item from growing too big, even if the text is larger.