Page 1 of 2
Resize Windows and make scrollbar appear ? [Solved]
Posted: Sat Mar 20, 2021 8:24 pm
by Fig
Hi,
I would like to make scroll bars from scrollareagadget() appear when I make the window smaller. (manual resizing)
How do I get this effect ?
Code: Select all
If OpenWindow(0, 0, 0, 1920, 1080, "test", #PB_Window_Maximize | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_BorderLess | #PB_Window_SizeGadget)=0
MessageRequester("Error","Error can't open windowed screen"):End
EndIf
Procedure WindowResizeEvent()
Debug "change size"
If EventWindow()=0
Debug "newsize"
SetGadgetAttribute(0,#PB_ScrollArea_InnerWidth,WindowWidth(0)) ;doesn't work...
SetGadgetAttribute(0,#PB_ScrollArea_InnerHeight,WindowHeight(0))
Debug Str(WindowWidth(0))
Debug Str(WindowHeight(0))
EndIf
EndProcedure
BindEvent(#PB_Event_SizeWindow,@WindowResizeEvent())
ScrollAreaGadget(0, 0, 0, 1920, 1080, 1898, 1006, 30)
;add some other gadgets...
CloseGadgetList()
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
Re: Resize Windows and make scrollbar appear ?
Posted: Sat Mar 20, 2021 11:50 pm
by RASHAD
Hi Fig
I still don't know what do you want exactly
So the next is a shoot in the dark (For Windows)
Code: Select all
If OpenWindow(0, 0, 0, 1920, 1080, "test", #PB_Window_Maximize | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_BorderLess | #PB_Window_SizeGadget)=0
MessageRequester("Error","Error can't open windowed screen"):End
EndIf
Procedure WindowResizeEvent()
w = WindowWidth(0)
h = WindowHeight(0)
If EventWindow()=0
ResizeGadget(0,0,0,w,h)
SetScrollRange_(GadgetID(0),#SB_HORZ,0,w-20,1)
SetScrollRange_(GadgetID(0),#SB_VERT,0,h-20,1)
EndIf
EndProcedure
ScrollAreaGadget(0, 0, 0, 1920, 1080, 1898, 1006, 30)
;add some other gadgets...
CloseGadgetList()
BindEvent(#PB_Event_SizeWindow,@WindowResizeEvent())
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
Re: Resize Windows and make scrollbar appear ?
Posted: Sun Mar 21, 2021 7:19 am
by Danilo
Fig wrote:I would like to make scroll bars from scrollareagadget() appear when I make the window smaller. (manual resizing)
How do I get this effect ?
Just resize the ScrollArea gadget to the new window size. Scrollbars appear automagically.
Code: Select all
If OpenWindow(0, 0, 0, 1920, 1080, "test", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_TitleBar | #PB_Window_SizeGadget)=0
MessageRequester("Error","Error can't open windowed screen"):End
EndIf
Procedure WindowResizeEvent()
Debug "change size"
If EventWindow()=0
ResizeGadget(0,0,0,WindowWidth(0),WindowHeight(0))
EndIf
EndProcedure
BindEvent(#PB_Event_SizeWindow,@WindowResizeEvent())
ScrollAreaGadget(0, 0, 0, 1920, 1080, 1898, 1006, 30)
;add some other gadgets...
CloseGadgetList()
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
(I added Titlebar because I can't resize a borderless window on macOS)
Re: Resize Windows and make scrollbar appear ?
Posted: Sun Mar 21, 2021 8:37 am
by Fig
Rashad, you basically answered. I struggle all the time explaining my problem in english, my apologies...
Exactly what I was looking for Danilo, thank you !
Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Sun Mar 20, 2022 9:21 am
by Psychophanta
About resizing a ScrollAreaGadget() there is found what is called a "bug", or wrong manual:
From the manual in the ScrollAreaGadget() entry:
The following event is supported through EventType():
#PB_EventType_Resize: The gadget has been resized.
Why is not working?

Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Sun Mar 20, 2022 12:15 pm
by mk-soft
The event works without problems.
But you have to bind the gadget event when you bind the event size window. Otherwise the event only comes after the mouse is released.
Code: Select all
;-TOP
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
EndEnumeration
Enumeration Gadgets
#MainScrollArea
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
; ----
Procedure DoEventResizeScrollArea()
Debug "Bind Event: dx = " + GadgetWidth(#MainScrollArea) + " / dy = " + GadgetHeight(#MainScrollArea)
EndProcedure
; ----
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar); - MenuHeight()
; Resize gadgets
ResizeGadget(#MainScrollArea, 0, 0, dx, dy)
EndProcedure
; ----
Procedure Main()
Protected dx, dy
#MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar); - MenuHeight()
ScrollAreaGadget(#MainScrollArea, 0, 0, dx, dy, dx * 2, dy * 3)
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
BindGadgetEvent(#MainScrollArea, @DoEventResizeScrollArea(), #PB_EventType_Resize)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #MainScrollArea
Select EventType()
Case #PB_EventType_Resize
;Debug "Main Loop: dx = " + GadgetWidth(#MainScrollArea) + " / dy = " + GadgetHeight(#MainScrollArea)
EndSelect
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
Structured event processing is important in order to query events only when they are valid.
EventGadget() and EventType() valid after an event #PB_Gadget_Event. EventTypes valid see after description of the gadget. EventTimer() after an event #PB_Event_Timer, etc.
Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Wed Mar 23, 2022 3:59 pm
by Psychophanta
mk-soft wrote: Sun Mar 20, 2022 12:15 pm
The event works without problems.
But you have to bind the gadget event when you bind the event size window. Otherwise the event only comes after the mouse is released.
Code: Select all
;-TOP
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
EndEnumeration
Enumeration Gadgets
#MainScrollArea
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
; ----
Procedure DoEventResizeScrollArea()
Debug "Bind Event: dx = " + GadgetWidth(#MainScrollArea) + " / dy = " + GadgetHeight(#MainScrollArea)
EndProcedure
; ----
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar); - MenuHeight()
; Resize gadgets
ResizeGadget(#MainScrollArea, 0, 0, dx, dy)
EndProcedure
; ----
Procedure Main()
Protected dx, dy
#MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar); - MenuHeight()
ScrollAreaGadget(#MainScrollArea, 0, 0, dx, dy, dx * 2, dy * 3)
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
BindGadgetEvent(#MainScrollArea, @DoEventResizeScrollArea(), #PB_EventType_Resize)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #MainScrollArea
Select EventType()
Case #PB_EventType_Resize
;Debug "Main Loop: dx = " + GadgetWidth(#MainScrollArea) + " / dy = " + GadgetHeight(#MainScrollArea)
EndSelect
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
Structured event processing is important in order to query events only when they are valid.
EventGadget() and EventType() valid after an event #PB_Gadget_Event. EventTypes valid see after description of the gadget. EventTimer() after an event #PB_Event_Timer, etc.
I referred to resize the scrollarea, NOT the window.
Please re-read my previous post carefully.
Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Wed Mar 23, 2022 5:25 pm
by mk-soft
Still works as it should.
- Event ResizeWindow triggers UpdateWindow
- ResizeGadget in UpdateWindow triggers DoEventResizeScollArea.
You can trigger it manually from the Test menu.
Code: Select all
;-TOP
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
EndEnumeration
Enumeration Gadgets
#MainScrollArea
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
; ----
Procedure DoEventResizeScrollArea()
Debug "Bind Event: dx = " + GadgetWidth(#MainScrollArea) + " / dy = " + GadgetHeight(#MainScrollArea)
EndProcedure
; ----
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
; Resize gadgets
ResizeGadget(#MainScrollArea, 0, 0, dx, dy)
EndProcedure
; ----
Procedure Main()
Protected dx, dy
#MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
MenuTitle("Test")
MenuItem(1,"Resize ScrollAreay")
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
ScrollAreaGadget(#MainScrollArea, 0, 0, dx, dy, dx * 2, dy * 3)
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
BindGadgetEvent(#MainScrollArea, @DoEventResizeScrollArea(), #PB_EventType_Resize)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
Case 1
ResizeGadget(#MainScrollArea, 0, 0, dx/2, dy/2)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #MainScrollArea
Select EventType()
Case #PB_EventType_Resize
;Debug "Main Loop: dx = " + GadgetWidth(#MainScrollArea) + " / dy = " + GadgetHeight(#MainScrollArea)
EndSelect
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Sat Mar 26, 2022 4:32 pm
by Psychophanta
mk-soft wrote: Wed Mar 23, 2022 5:25 pm
Still works as it should.
- Event ResizeWindow triggers UpdateWindow
- ResizeGadget in UpdateWindow triggers DoEventResizeScollArea.
You can trigger it manually from the Test menu.
Code: Select all
;-TOP
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
EndEnumeration
Enumeration Gadgets
#MainScrollArea
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
; ----
Procedure DoEventResizeScrollArea()
Debug "Bind Event: dx = " + GadgetWidth(#MainScrollArea) + " / dy = " + GadgetHeight(#MainScrollArea)
EndProcedure
; ----
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
; Resize gadgets
ResizeGadget(#MainScrollArea, 0, 0, dx, dy)
EndProcedure
; ----
Procedure Main()
Protected dx, dy
#MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
MenuTitle("Test")
MenuItem(1,"Resize ScrollAreay")
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
ScrollAreaGadget(#MainScrollArea, 0, 0, dx, dy, dx * 2, dy * 3)
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
BindGadgetEvent(#MainScrollArea, @DoEventResizeScrollArea(), #PB_EventType_Resize)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
Case 1
ResizeGadget(#MainScrollArea, 0, 0, dx/2, dy/2)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #MainScrollArea
Select EventType()
Case #PB_EventType_Resize
;Debug "Main Loop: dx = " + GadgetWidth(#MainScrollArea) + " / dy = " + GadgetHeight(#MainScrollArea)
EndSelect
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
Sorry, it does not work

Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Sun Mar 27, 2022 12:36 am
by mk-soft
What is not work ???
Works here unter macOS, window, linux ...
Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Sun Mar 27, 2022 12:44 pm
by Psychophanta
mk-soft wrote: Sun Mar 27, 2022 12:36 am
What is not work ???
Works here unter macOS, window, linux ...
Dear, you force me to repost my message:
About resizing a ScrollAreaGadget() there is found what is called a "bug", or wrong manual:
From the manual in the ScrollAreaGadget() entry:
The following event is supported through EventType():
#PB_EventType_Resize: The gadget has been resized.
Why is not working?

So please, post something to argue this, or else, keep peacefully.
Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Sun Mar 27, 2022 2:30 pm
by mk-soft
Sorry,
Then I don't understand what you mean or why it doesn't work for you.
In the PB help it says that after changing the gadget size with ResizeGadget() the event PB_Event_Gadget is triggered on the ScrollAreaGadget and with EventType() the event #PB_EventType_Resize can be queried.
Or maybe show me the code where it doesn't work.
Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Sun Mar 27, 2022 3:25 pm
by Psychophanta
mk-soft wrote: Sun Mar 27, 2022 2:30 pm
Sorry,
Then I don't understand what you mean or why it doesn't work for you.
In the PB help it says that after changing the gadget size with ResizeGadget() the event PB_Event_Gadget is triggered on the ScrollAreaGadget and with EventType() the event #PB_EventType_Resize can be queried.
Or maybe show me the code where it doesn't work.
Mhhh, ok, you win, I will try tomorrow to post a short video
Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Fri Apr 01, 2022 5:52 pm
by Psychophanta
Re: Resize Windows and make scrollbar appear ? [Solved]
Posted: Fri Apr 01, 2022 6:35 pm
by RASHAD
Hi Psychophanta
I hope that I just understood you correctly
After resize you can do what you want with the gadget
Code: Select all
Procedure SizeCB()
w = WindowWidth(0)
h = WindowHeight(0)
ResizeGadget(0,10,10,w-20,h-20)
EndProcedure
OpenWindow(0, 0, 0, 800,600, "test", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
ScrollAreaGadget(0, 10, 10, 780,580 , 2000,1500, 30)
;add some other gadgets...
CloseGadgetList()
BindEvent(#PB_Event_SizeWindow,@sizeCB())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_Resize ;The gadget has been resized.
SetGadgetAttribute(0, #PB_ScrollArea_X, 2000)
hpos = GetGadgetAttribute(0, #PB_ScrollArea_X)
SetGadgetAttribute(0, #PB_ScrollArea_Y, 1500)
vpos = GetGadgetAttribute(0, #PB_ScrollArea_Y)
SetGadgetAttribute(0, #PB_ScrollArea_X, hpos/2)
SetGadgetAttribute(0, #PB_ScrollArea_Y, vpos/2)
EndSelect
EndSelect
EndSelect
Until Quit = 1