Page 1 of 1

Need tips for SplitterGadget and Gadgets resize

Posted: Wed May 29, 2024 10:20 am
by tatanas
Hi,

I'm playing with SplitterGadget and several gadgets inside. I would like to know if my way of managing the resizing of gadgets is fine.

Code: Select all

Global first_width = 400
Global first_height = 400

Enumeration Gadgets
	#ScrollArea
	#container
	#Splitter
	#listicon
	#panel
	#str1
	#str2
	#str3
	#str4
	#str5
	#status
EndEnumeration

Procedure BindSplitterV()
	Static SplitterPos
	Protected Position = GetGadgetState(EventGadget())
	If SplitterPos <> Position
		SplitterPos = Position

		ResizeGadget(#listicon, #PB_Ignore, #PB_Ignore, GadgetWidth(#container) - 15, #PB_Ignore)
		ResizeGadget(#ScrollArea, #PB_Ignore, #PB_Ignore, GadgetWidth(#panel) - 12, GadgetHeight(#panel) - 30)
		SetGadgetAttribute(#ScrollArea, #PB_ScrollArea_InnerWidth, GadgetWidth(#ScrollArea) - 30)
		SetGadgetAttribute(#ScrollArea, #PB_ScrollArea_InnerHeight, GadgetHeight(#ScrollArea) + 140)

		ResizeGadget(#str1, #PB_Ignore, #PB_Ignore, GadgetWidth(#ScrollArea) - 80, #PB_Ignore)
		ResizeGadget(#str2, #PB_Ignore, #PB_Ignore, GadgetWidth(#ScrollArea) - 80, #PB_Ignore)
		ResizeGadget(#str3, #PB_Ignore, #PB_Ignore, GadgetWidth(#ScrollArea) - 80, #PB_Ignore)
		ResizeGadget(#str4, #PB_Ignore, #PB_Ignore, GadgetWidth(#ScrollArea) - 80, #PB_Ignore)
		ResizeGadget(#str5, #PB_Ignore, #PB_Ignore, GadgetWidth(#ScrollArea) - 80, #PB_Ignore)

		; to remove the flickering
		UpdateWindow_(GadgetID(#listicon))
		UpdateWindow_(GadgetID(#status))
	EndIf
EndProcedure

Procedure ResizeEvent()
	new_width = WindowWidth(0)
	new_height = WindowHeight(0)

	inc_Width = new_width - first_width
	inc_Height = new_height - first_height

	ResizeGadget(#Splitter, #PB_Ignore, #PB_Ignore, 390 + inc_Width, 390 + inc_Height)

	ResizeGadget(#listicon, #PB_Ignore, #PB_Ignore, GadgetWidth(#container) - 15, 200 + inc_Height)
	ResizeGadget(#status, #PB_Ignore, 5 + GadgetHeight(#listicon), #PB_Ignore, #PB_Ignore)

	ResizeGadget(#ScrollArea, #PB_Ignore, #PB_Ignore, GadgetWidth(#panel) - 12, GadgetHeight(#panel) - 30)
	SetGadgetAttribute(#ScrollArea, #PB_ScrollArea_InnerWidth, GadgetWidth(#ScrollArea) - 30)
	SetGadgetAttribute(#ScrollArea, #PB_ScrollArea_InnerHeight, GadgetHeight(#ScrollArea) + 140)

	ResizeGadget(#str1, #PB_Ignore, #PB_Ignore, GadgetWidth(#ScrollArea) - 80, #PB_Ignore)
	ResizeGadget(#str2, #PB_Ignore, #PB_Ignore, GadgetWidth(#ScrollArea) - 80, #PB_Ignore)
	ResizeGadget(#str3, #PB_Ignore, #PB_Ignore, GadgetWidth(#ScrollArea) - 80, #PB_Ignore)
	ResizeGadget(#str4, #PB_Ignore, #PB_Ignore, GadgetWidth(#ScrollArea) - 80, #PB_Ignore)
	ResizeGadget(#str5, #PB_Ignore, #PB_Ignore, GadgetWidth(#ScrollArea) - 80, #PB_Ignore)
EndProcedure


OpenWindow(0, 0, 0, first_width, first_height, "Splitter", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
WindowBounds(0, first_width, first_height, #PB_Ignore, #PB_Ignore)

ContainerGadget(#container, 0, 0, 0, 0, #PB_Container_Raised)
	ListIconGadget(#listicon, 5, 5, 180, 200, "col1", 100)
	AddGadgetItem(#listicon, -1, "line 1")
	AddGadgetItem(#listicon, -1, "line 2")
	AddGadgetItem(#listicon, -1, "line 3")
	TextGadget(#status, 5, 205, 50, 25, "status :")
CloseGadgetList()

PanelGadget(#panel, 0, 0, 0, 0)
	AddGadgetItem(#panel, -1, "Panel 1")
	ScrollAreaGadget(#ScrollArea, 2, 2, 180, 360, 180 - 30, 360 + 140, 18, #PB_ScrollArea_Raised)
		SetGadgetColor(#ScrollArea, #PB_Gadget_BackColor, #Red)
		StringGadget(#str1, 5, 5, 100, 25, "string one")
		StringGadget(#str2, 5, 35, 100, 25, "string two")
		StringGadget(#str3, 5, 65, 100, 25, "string three")
		StringGadget(#str4, 5, 95, 100, 25, "string four")
		StringGadget(#str5, 5, 125, 100, 25, "string five")
	CloseGadgetList()
	AddGadgetItem(#panel, -1, "Panel 2")
	AddGadgetItem(#panel, -1, "Panel 3")
CloseGadgetList()

SplitterGadget(#Splitter, 5, 5, 390, 390, #container, #panel, #PB_Splitter_Vertical)
BindGadgetEvent(#Splitter, @BindSplitterV())
BindEvent(#PB_Event_SizeWindow, @ResizeEvent(), 0)

; to remove the flickering
SetWindowLongPtr_(GadgetID(#panel), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(#panel), #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
SetWindowLongPtr_(GadgetItemID(#panel, 0), #GWL_STYLE, GetWindowLongPtr_(GadgetItemID(#panel, 0), #GWL_STYLE) | #WS_CLIPSIBLINGS | #WS_CLIPCHILDREN)
SetWindowLongPtr_(GadgetItemID(#panel, 1), #GWL_STYLE, GetWindowLongPtr_(GadgetItemID(#panel, 1), #GWL_STYLE) | #WS_CLIPSIBLINGS | #WS_CLIPCHILDREN)
SetWindowLongPtr_(GadgetItemID(#panel, 2), #GWL_STYLE, GetWindowLongPtr_(GadgetItemID(#panel, 2), #GWL_STYLE) | #WS_CLIPSIBLINGS | #WS_CLIPCHILDREN)
; hStatic = FindWindowEx_(GadgetID(#panel), 0, "Static", 0)
; SetWindowLong_(hStatic, #GWL_STYLE, GetWindowLong_(hStatic, #GWL_STYLE) | #WS_CLIPCHILDREN)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
Thanks for your time.

Re: Need tips for SplitterGadget and Gadgets resize

Posted: Wed May 29, 2024 11:23 am
by mk-soft
Some change ...

Code: Select all

Global first_width = 400
Global first_height = 400

Enumeration Gadgets
  #ScrollArea
  #container
  #Splitter
  #listicon
  #panel
  #str1
  #str2
  #str3
  #str4
  #str5
  #status
EndEnumeration

Procedure ResizeEventContainer()
  Protected dx, dy
  dx = GadgetWidth(#container)
  dy = GadgetHeight(#container)
  
  ResizeGadget(#listicon, #PB_Ignore, #PB_Ignore, dx - 15, dy - 200)
  ResizeGadget(#status, #PB_Ignore, dy - 195, #PB_Ignore, #PB_Ignore)
EndProcedure

Procedure ResizeEventPanel()
  Protected dx, dy
  dx = GadgetWidth(#panel)
  dy = GadgetHeight(#panel)
  
  ResizeGadget(#ScrollArea, #PB_Ignore, #PB_Ignore, dx - 12, dy - 30)
  SetGadgetAttribute(#ScrollArea, #PB_ScrollArea_InnerWidth, dx - 30 - 12)
  SetGadgetAttribute(#ScrollArea, #PB_ScrollArea_InnerHeight, dy + 140)
EndProcedure

Procedure ResizeEventScrollArea()
  Protected dx, dy
  dx = GadgetWidth(#ScrollArea)
  dy = GadgetHeight(#ScrollArea)
  
  ResizeGadget(#str1, #PB_Ignore, #PB_Ignore, dx - 80, #PB_Ignore)
  ResizeGadget(#str2, #PB_Ignore, #PB_Ignore, dx - 80, #PB_Ignore)
  ResizeGadget(#str3, #PB_Ignore, #PB_Ignore, dx - 80, #PB_Ignore)
  ResizeGadget(#str4, #PB_Ignore, #PB_Ignore, dx - 80, #PB_Ignore)
  ResizeGadget(#str5, #PB_Ignore, #PB_Ignore, dx - 80, #PB_Ignore)
EndProcedure

Procedure ResizeEvent()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0)
  
  ResizeGadget(#Splitter, #PB_Ignore, #PB_Ignore, dx, dy)
EndProcedure


OpenWindow(0, 0, 0, first_width, first_height, "Splitter", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
WindowBounds(0, first_width, first_height, #PB_Ignore, #PB_Ignore)

ContainerGadget(#container, 0, 0, 0, 0, #PB_Container_Raised)
ListIconGadget(#listicon, 5, 5, 180, 200, "col1", 100)
AddGadgetItem(#listicon, -1, "line 1")
AddGadgetItem(#listicon, -1, "line 2")
AddGadgetItem(#listicon, -1, "line 3")
TextGadget(#status, 5, 205, 50, 25, "status :")
SetGadgetColor(#status, #PB_Gadget_BackColor, #Blue)
CloseGadgetList()

PanelGadget(#panel, 0, 0, 0, 0)
AddGadgetItem(#panel, -1, "Panel 1")
ScrollAreaGadget(#ScrollArea, 2, 2, 180, 360, 180 - 30, 360 + 140, 18, #PB_ScrollArea_Raised)
SetGadgetColor(#ScrollArea, #PB_Gadget_BackColor, #Red)
StringGadget(#str1, 5, 5, 100, 25, "string one")
StringGadget(#str2, 5, 35, 100, 25, "string two")
StringGadget(#str3, 5, 65, 100, 25, "string three")
StringGadget(#str4, 5, 95, 100, 25, "string four")
StringGadget(#str5, 5, 125, 100, 25, "string five")
CloseGadgetList()
AddGadgetItem(#panel, -1, "Panel 2")
AddGadgetItem(#panel, -1, "Panel 3")
CloseGadgetList()

SplitterGadget(#Splitter, 5, 5, 390, 390, #container, #panel, #PB_Splitter_Vertical)
BindEvent(#PB_Event_SizeWindow, @ResizeEvent(), 0)
BindGadgetEvent(#container, @ResizeEventContainer())
BindGadgetEvent(#panel, @ResizeEventPanel())
BindGadgetEvent(#ScrollArea, @ResizeEventScrollArea())

; to remove the flickering
SetWindowLongPtr_(GadgetID(#panel), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(#panel), #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
SetWindowLongPtr_(GadgetItemID(#panel, 0), #GWL_STYLE, GetWindowLongPtr_(GadgetItemID(#panel, 0), #GWL_STYLE) | #WS_CLIPSIBLINGS | #WS_CLIPCHILDREN)
SetWindowLongPtr_(GadgetItemID(#panel, 1), #GWL_STYLE, GetWindowLongPtr_(GadgetItemID(#panel, 1), #GWL_STYLE) | #WS_CLIPSIBLINGS | #WS_CLIPCHILDREN)
SetWindowLongPtr_(GadgetItemID(#panel, 2), #GWL_STYLE, GetWindowLongPtr_(GadgetItemID(#panel, 2), #GWL_STYLE) | #WS_CLIPSIBLINGS | #WS_CLIPCHILDREN)
; hStatic = FindWindowEx_(GadgetID(#panel), 0, "Static", 0)
; SetWindowLong_(hStatic, #GWL_STYLE, GetWindowLong_(hStatic, #GWL_STYLE) | #WS_CLIPCHILDREN)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend