I am trying to programmatically determine the minimum width to resize an Editor Gadget in order to display the widest text line, so PB won't need to generate a horizontal scrollbar. The #PB_Gadget_RequiredSize option of GadgetWidth on my Editor Gadget always returns 0 - which would indicate to me that RequiredSize is not an available option for Editor Gadgets.
I can manually resize my Editor Gadget until I hit the "sweet width" where the horizontal scrollbar disappears. But I would prefer to initially present the user with a wide-enough Editor Gadget so that the user will never need to scroll right to see off-the-screen text.
Is there a Windows function that can provide the "required" gadget width in pixels?
RequiredSize for the Width of an Editor Gadget?
RequiredSize for the Width of an Editor Gadget?
PB: 6.00 LTS (x86) OS: Windows 10
Re: RequiredSize for the Width of an Editor Gadget?
Hm...
find the longest line,
create an image,
use startdrawing
use TextWidth(Text$) to get the required pixels.
You have to use the same font
find the longest line,
create an image,
use startdrawing
use TextWidth(Text$) to get the required pixels.
You have to use the same font
-
- Addict
- Posts: 1656
- Joined: Sun Dec 12, 2010 12:36 am
- Location: Somewhere in the midwest
- Contact:
Re: RequiredSize for the Width of an Editor Gadget?
Why not just enable wordwrap ?
Re: RequiredSize for the Width of an Editor Gadget?
Well... not the cleanest of solutions, but may be a fallback. Thanks!infratec wrote:Hm...
find the longest line,
create an image,
use startdrawing
use TextWidth(Text$) to get the required pixels.
You have to use the same font
PB: 6.00 LTS (x86) OS: Windows 10
Re: RequiredSize for the Width of an Editor Gadget?
My particular project is highlighting line-by-line for website population. For my users, it is cleaner if all of the data is contained on a single line.Zach wrote:Why not just enable wordwrap ?
PB: 6.00 LTS (x86) OS: Windows 10
Re: RequiredSize for the Width of an Editor Gadget?
Hi
Determine the longest line first
Use the proper font and font size to both the dummy TextGadget() and the EditorGadget()
Determine the longest line first
Use the proper font and font size to both the dummy TextGadget() and the EditorGadget()
Code: Select all
Global reqwidth
Procedure GetWIDTH(Text$)
dummy = TextGadget(#PB_Any,0,0,2000,24,text$)
SetGadgetFont(dummy,FontID(0))
reqwidth = GadgetWidth(dummy,#PB_Gadget_RequiredSize)+4
FreeGadget(dummy)
ProcedureReturn reqwidth
EndProcedure
LoadFont(0,"Tahoma",20)
Text$ = "yui ioiooooo ioooyyyoy oio o yoyo oyoyoioi oyioi"
If OpenWindow(0, 0, 0, 600, 300, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
GetWIDTH(Text$)
EditorGadget(1, 10, 10, reqwidth,130)
SetGadgetFont(1,FontID(0))
AddGadgetItem(1,0, Text$)
Repeat
Select WaitWindowEvent(10)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
EndSelect
EndSelect
Until Quit = 1
EndIf
Egypt my love
Re: RequiredSize for the Width of an Editor Gadget?
Thanks Rashad! I was thinking about going down this direction after the reply from infratec. Thanks for fleshing this out!
PB: 6.00 LTS (x86) OS: Windows 10
Re: RequiredSize for the Width of an Editor Gadget?
You are welcome
If you still in need for API solution
If you still in need for API solution
Code: Select all
LoadFont(0,"Tahoma",12)
Text$ = "Wui ioiooooo ioooyyyoy oio o yoyo oyoyoioi oyioi"
If OpenWindow(0, 0, 0, 600, 300, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(1, 10, 10, 100,100)
GetWindowRect_(GadgetID(1),r.RECT)
GetClientRect_(GadgetID(1),c.RECT)
border = r\right-r\left-c\right+c\left+2
dc = GetDC_(0)
sz.Size
SelectObject_(dc, FontID(0))
GetTextExtentPoint32_(dc, text$, Len(text$), sz)
ReleaseDC_(0, dc)
reqwidth = sz\cx + border
ResizeGadget(1,#PB_Ignore,#PB_Ignore,reqwidth,130)
SetGadgetFont(1,FontID(0))
AddGadgetItem(1,0, Text$)
Repeat
Select WaitWindowEvent(10)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
EndSelect
EndSelect
Until Quit = 1
EndIf
Egypt my love