GadgetHeight(#TEXT_GADGET,#PB_Gadget_RequiredSize) word-wrap
Posted: Sat May 21, 2016 5:20 am
(That 60 char limit on forum topic titles is ridiculous. You can easily expand the allowed chars in the title for PHPBB. I've done it in the past. You just have to do some research and fiddle with the forum files to make it work. If an idiot like me can do it then anyone can do it.)
Currently when the GadgetHeight command is used on a TextGadget with the #PB_Gadget_RequiredSize flag set the GadgetHeight command assumes that the TextGadget only contains unwrapped text (where a paragraph of text is only one display line high, even if the line of text is longer than the width of the TextGadget). The default behaviour for the TextGadget is to word-wrap text so that an over-length string of text will take up multiple lines, which means that the value returned by 'GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize )' where #TEXT_GADGET is a TextGadget is potentially wrong if the the text has wrapped.
What I'd like is for 'GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize )' (where #TEXT_GADGET is a TextGadget) to factor word-wrapping into the returned value. This would make it far easier to do custom alert style message requesters, etc.
I assume that the information required to make this happen already exists in the various OS APIs, otherwise the dynamically resizing alert style message requesters that all these OSs use wouldn't work.
In this example 'GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize )' returns a useful value as the text lines only take up a single display row - because they don't wrap.
In this example 'GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize )' returns a useless value as the text lines have wrapped and the value returned doesn't factor this in.
Currently when the GadgetHeight command is used on a TextGadget with the #PB_Gadget_RequiredSize flag set the GadgetHeight command assumes that the TextGadget only contains unwrapped text (where a paragraph of text is only one display line high, even if the line of text is longer than the width of the TextGadget). The default behaviour for the TextGadget is to word-wrap text so that an over-length string of text will take up multiple lines, which means that the value returned by 'GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize )' where #TEXT_GADGET is a TextGadget is potentially wrong if the the text has wrapped.
What I'd like is for 'GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize )' (where #TEXT_GADGET is a TextGadget) to factor word-wrapping into the returned value. This would make it far easier to do custom alert style message requesters, etc.
I assume that the information required to make this happen already exists in the various OS APIs, otherwise the dynamically resizing alert style message requesters that all these OSs use wouldn't work.
In this example 'GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize )' returns a useful value as the text lines only take up a single display row - because they don't wrap.
Code: Select all
text.s = "abc" + Chr( 10 ) + "def" + Chr( 10 ) + "ghi" + Chr( 10 ) + "jkl" + Chr( 10 ) + "mno" + Chr( 10 ) + "pqr" + Chr( 10 ) + "stu" + Chr( 10 ) + "vwxyz"
#WINDOW = 0
#TEXT_GADGET = 0
text_gadget_width = 500
If OpenWindow( #WINDOW, 0, 0, text_gadget_width + 20, 400, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget( #TEXT_GADGET, 10, 10, text_gadget_width, 150, text.s, #PB_Text_Border )
Debug GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize )
ResizeGadget( #TEXT_GADGET, #PB_Ignore, #PB_Ignore, #PB_Ignore, GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize ) )
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
In this example 'GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize )' returns a useless value as the text lines have wrapped and the value returned doesn't factor this in.
Code: Select all
text.s = "Once you have used the 'Select Puzzle Project' tab page to either create a new puzzle project or open an existing one then you will need to add the " +
"source images that you want to turn into jigsaw puzzles to the project. You can do that using any of the three options below. " + Chr( 10 ) +
"It doesn't matter which of the options below that you use to add the files - just use whichever option suits you the best." + Chr( 10 ) +
"You can add new source images at any time using the options below. The new images will be added to the image sort order on the 'Sort Source Images' tab page after any existing images. " +
"Any attempt to add images that have already been added will be ignored, as will any attempt to add images that are too narrow or too small to make good jigsaw puzzles."
#WINDOW = 0
#TEXT_GADGET = 0
text_gadget_width = 500
If OpenWindow( #WINDOW, 0, 0, text_gadget_width + 20, 400, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget( #TEXT_GADGET, 10, 10, text_gadget_width, 150, text.s, #PB_Text_Border )
Debug GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize )
ResizeGadget( #TEXT_GADGET, #PB_Ignore, #PB_Ignore, #PB_Ignore, GadgetHeight( #TEXT_GADGET, #PB_Gadget_RequiredSize ) )
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf