Large static text alignment

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.

mine.png

fontDialog.png

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.

Yes, currently the frame does resize to fit the its controls, but I would still like to know if it is possible to emulate this specific behaviour.

···

On Thursday, 8 August 2013 21:08:27 UTC+3, Che M wrote:

On Thu, Aug 8, 2013 at 10:04 AM, Alexandru Popa a.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…

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?

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?

···

On Thu, Aug 8, 2013 at 1:33 PM, Alexandru Popa a.ephesos@gmail.com wrote:

Yes, currently the frame does resize to fit the its controls, but I would still like to know if it is possible to emulate this specific behaviour.

On Thursday, 8 August 2013 21:08:27 UTC+3, Che M wrote:

On Thu, Aug 8, 2013 at 10:04 AM, Alexandru Popa a.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…

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?

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

C M 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.

···

On Thu, Aug 8, 2013 at 10:04 AM, Alexandru Popa<a.ephesos@gmail.com> wrote:

--
Robin Dunn
Software Craftsman

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.

sample.zip (788 Bytes)

···

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.


Robin Dunn

Software Craftsman

http://wxPython.org

Alexandru Popa 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?

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.

···

--
Robin Dunn
Software Craftsman