How to fit a dialog

Just starting out? Need help? Post your questions and find answers here.
Mesa
Enthusiast
Enthusiast
Posts: 345
Joined: Fri Feb 24, 2012 10:19 am

How to fit a dialog

Post by Mesa »

How to fit a dialog to the size of an editorgadget or a listview ?

Code: Select all

#Dialog = 0
#Xml = 0

;   XML$ = "<window id='#PB_Any' name='test' text='test' flags='#PB_Window_ScreenCentered | #PB_Window_Borderless'  height='300' width='100' margin='vertical:0'>" +
XML$ = "<window id='#PB_Any' name='test' text='test' flags='#PB_Window_ScreenCentered | #PB_Window_Borderless' width='100' margin='vertical:0'>" +
       "  <vbox expand='item:1' spacing='1'>" +
       "    <editor name='listview_1'/>" +;"    <listview name='listview_1'/>" +
       "      <canvas name='canvas_1' height='18'/>" +
       "        </vbox>" +
       "    </window>"

If ParseXML(#Xml, XML$) And XMLStatus(#Xml) = #PB_XML_Success
	
	If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
		
		For i=0 To 100
			AddGadgetItem(DialogGadget(#Dialog, "listview_1"), -1,"#True"+Str(i))
			RefreshDialog(#Dialog)
		Next i
		
		If StartDrawing(CanvasOutput(DialogGadget(#Dialog, "canvas_1")))
			Box(0,0,OutputWidth(),OutputHeight(), #Red)
			StopDrawing()
		EndIf
		
		
		
		;           h=GadgetHeight(DialogGadget(#Dialog, "listview_1"),#PB_Gadget_RequiredSize)
		;           ResizeWindow(DialogWindow(#Dialog),#PB_Ignore,#PB_Ignore,h,#PB_Ignore)
		
		Repeat
			Event = WaitWindowEvent()
			EventGadget = EventGadget()
			
			Select Event 
				Case #PB_Event_Gadget
					Select EventGadget 
						Case DialogGadget(#Dialog, "listview_1")
							Select EventType()
								Case#PB_EventType_Change
									h=GadgetHeight(DialogGadget(#Dialog, "listview_1"),#PB_Gadget_RequiredSize)+GadgetHeight(DialogGadget(#Dialog, "canvas_1"))
									ResizeWindow(DialogWindow(#Dialog),#PB_Ignore,#PB_Ignore,h,#PB_Ignore)
									RefreshDialog(#Dialog)
							EndSelect
					EndSelect
					
			EndSelect
			
		Until Event = #PB_Event_CloseWindow 
		
	Else  
		Debug "Erreur de la bibliothèque -Dialog- : " + DialogError(#Dialog)
	EndIf
Else
	Debug "Erreur XML : " + XMLError(#Xml) + " (Ligne: " + XMLErrorLine(#Xml) + ")"
EndIf

M.
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: How to fit a dialog

Post by Danilo »

Mesa wrote: Sat May 21, 2022 11:21 am How to fit a dialog to the size of an editorgadget or a listview ?
Editor and ListView don't have a "size to fit" because the gadgets can be empty or have thousands of lines/items.

You can set a minimum size using the width and height properties:

Code: Select all

XML$ = "<window id='#PB_Any' name='test' text='test' flags='#PB_Window_ScreenCentered | #PB_Window_Borderless' width='100' margin='vertical:0'>" +
       "  <vbox expand='item:1' spacing='1'>" +
       "    <editor name='listview_1' width='100' height='100'/>" +
       ;"    <listview name='listview_1' width='100' height='100'/>" +
       "      <canvas name='canvas_1' height='18'/>" +
       "        </vbox>" +
       "    </window>"
To calculate the minimum height of a ListView with 5 lines, you need to
use TextHeight() * 5 for a drawing output with the same font as the gadget.
Plus some pixels for the gadget border, depending on OS.
Post Reply