I am making new gadget class. I have a text related issue:
Imagine a button gadget with a locked width. Then the user changes the text to something longer than the button is wide. How do I clip the text off at the end of the button (inner width)? So it doesn't keep printing past the gadget.
IGraphics->Text() would be great if it printed by PIXEL length instead of CHARACTERS length.
My box is not static,though. The width/height can change with window resizing.
Normal clipping routines of layers.library should do. See http://wiki.amigaos.net/wiki/Graphics_Regions
Here is an exampe: http://thomas-rapp.homepage.t-online.de/examples/scalespace.c
It hides the region creation and the necessary handling of Begin/EndRefresh in two support functions set_clip_region resp. remove_clip_region.
At first I thought you was printng text from a button until i stopped making sense. ;-)
Graphics is a touch low level. I would have expected there to be Reaction functions for this built in. But you could also try Intution functions since this is in the BOOPSI domain. Such as PrintIText(). But it may have the same problems.
The itexticlass also looks interesting for the job.
Thanks, Thomas. I found a different example of yours that I almost got working. I wasn't disposing of the region at the correct place. And I had to adjust the order the gadget was drawn, as well.
@mritter0
IntuiTextLength() gives you the width in pixels.
X1000 - OS 4.1FE
TextLength()/IntuiTextLength() will only tell you how many horisontal pixels rendering the entire text will use, so you will only be able to tell if the entire text will fit or not.
In order to find out how many characters can be rendered fully into a given area the TextFit() function can be used.
I used this function in the bevel.image implementation for my no longer worked on open source ReAction clone:
https://sourceforge.net/p/openreaction/code/HEAD/tree/src/bevel_ic/dispatch.c#l214