Less paint & events for the SplitterGadget
Posted: Wed Feb 14, 2024 4:23 pm
It seems that some redrawing and event sending are done for the Splitter Gadget even without changing the Splitter position (same Gadget state), they seem superfluous and cause flashing.
Including when the cursor is beyond the minimum position (MinimumSize or 0) or maximum position(GadgetWidth-SeparatorSize).
Would be good to avoid these re-drawing and sending event, if there is no change of position.
Including when the cursor is beyond the minimum position (MinimumSize or 0) or maximum position(GadgetWidth-SeparatorSize).
Would be good to avoid these re-drawing and sending event, if there is no change of position.
Code: Select all
EnableExplicit
Enumeration Window
#Window
EndEnumeration
Enumeration Gadgets
#ScrlArea_1
#Txt_1
#Btn_1
#ScrlArea_2
#Txt_2
#Btn_2
#Splitter
EndEnumeration
Procedure BindSplitter()
Static SplitterPosition
Protected NewSplitterPosition = GetGadgetState(EventGadget())
If Not NewSplitterPosition = SplitterPosition
;Debug "Splitter: new position = " + Str(SplitterPosition) + " - previous position = " + Str(NewSplitterPosition)
SplitterPosition = NewSplitterPosition
Else
Debug "Event received with same Splitter position = " + Str(SplitterPosition)
EndIf
EndProcedure
If OpenWindow(#Window, 0, 0, 540, 220, "Less Paint & Event for SplitterGadget", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
ScrollAreaGadget(#ScrlArea_1, 0, 0, 0, 0, 500, 500, 10, #PB_ScrollArea_Single)
SetGadgetColor(#ScrlArea_1, #PB_Gadget_BackColor, $999999)
;SetWindowLongPtr_(GadgetID(#ScrlArea_1), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(#ScrlArea_1), #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
TextGadget(#Txt_1, 20, 20, 240, 80, "The Splitter's child gadgets are redrawn and events are received even without position changes ", #PB_Text_Center)
SetGadgetColor(#Txt_1, #PB_Gadget_BackColor, $400000) : SetGadgetColor(#Txt_1, #PB_Gadget_FrontColor, $40FFFF)
ButtonGadget(#Btn_1, 50, 130, 200, 60, "Button First Gadget ")
CloseGadgetList()
ScrollAreaGadget(#ScrlArea_2, 0, 0, 0, 0, 500, 500, 10, #PB_ScrollArea_Single)
SetGadgetColor(#ScrlArea_2, #PB_Gadget_BackColor, $999999)
;SetWindowLongPtr_(GadgetID(#ScrlArea_2), #GWL_EXSTYLE, GetWindowLongPtr_(GadgetID(#ScrlArea_2), #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
TextGadget(#Txt_2, 20, 20, 240, 80, "Including when the cursor is beyond the minimum position (MinimumSize or 0) or maximum position(GadgetWidth-SeparatorSize)", #PB_Text_Center)
SetGadgetColor(#Txt_2, #PB_Gadget_BackColor, $400000) : SetGadgetColor(#Txt_2, #PB_Gadget_FrontColor, $40FFFF)
ButtonGadget(#Btn_2, 50, 130, 200, 60, "Button Second Gadget")
CloseGadgetList()
SplitterGadget(#Splitter, 0, 0, 540, 220, #ScrlArea_1, #ScrlArea_2, #PB_Splitter_Separator | #PB_Splitter_Vertical)
;SetGadgetAttribute(#Splitter, #PB_Splitter_FirstMinimumSize, 60) : SetGadgetAttribute(#Splitter, #PB_Splitter_SecondMinimumSize, 60)
BindGadgetEvent(#Splitter, @BindSplitter())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf