It is currently Sun Oct 25, 2020 2:27 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: RequiredSize for the Width of an Editor Gadget?
PostPosted: Sat Oct 17, 2020 10:25 pm 
Offline
New User
New User

Joined: Tue Nov 17, 2015 11:20 pm
Posts: 7
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? :?


Top
 Profile  
Reply with quote  
 Post subject: Re: RequiredSize for the Width of an Editor Gadget?
PostPosted: Sat Oct 17, 2020 11:12 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4980
Location: Germany
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 :wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: RequiredSize for the Width of an Editor Gadget?
PostPosted: Sat Oct 17, 2020 11:20 pm 
Offline
Addict
Addict

Joined: Sun Dec 12, 2010 12:36 am
Posts: 1642
Location: Somewhere in the midwest
Why not just enable wordwrap ?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: RequiredSize for the Width of an Editor Gadget?
PostPosted: Sun Oct 18, 2020 12:24 am 
Offline
New User
New User

Joined: Tue Nov 17, 2015 11:20 pm
Posts: 7
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 :wink:


Well... not the cleanest of solutions, but may be a fallback. Thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: RequiredSize for the Width of an Editor Gadget?
PostPosted: Sun Oct 18, 2020 12:26 am 
Offline
New User
New User

Joined: Tue Nov 17, 2015 11:20 pm
Posts: 7
Zach wrote:
Why not just enable wordwrap ?


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.


Top
 Profile  
Reply with quote  
 Post subject: Re: RequiredSize for the Width of an Editor Gadget?
PostPosted: Sun Oct 18, 2020 3:06 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3706
Hi
Determine the longest line first
Use the proper font and font size to both the dummy TextGadget() and the EditorGadget()
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: RequiredSize for the Width of an Editor Gadget?
PostPosted: Sun Oct 18, 2020 10:56 pm 
Offline
New User
New User

Joined: Tue Nov 17, 2015 11:20 pm
Posts: 7
Thanks Rashad! I was thinking about going down this direction after the reply from infratec. Thanks for fleshing this out!


Top
 Profile  
Reply with quote  
 Post subject: Re: RequiredSize for the Width of an Editor Gadget?
PostPosted: Sun Oct 18, 2020 11:58 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3706
You are welcome
If you still in need for API solution
Code:
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye