Scroll Area Resize

Just starting out? Need help? Post your questions and find answers here.
User avatar
tikidays
User
User
Posts: 46
Joined: Tue Oct 24, 2023 6:47 am
Location: New Zealand
Contact:

Scroll Area Resize

Post by tikidays »

Hi,

I have a problem that when my window and scroll area is resized and gadgets follow the resized window, if they move out side the original width of the window they are no longer accessible, ie I can't click on the button. Resizing the window back, they become active again, what have I missed?

Code: Select all

Protected FormWindowWidth, FormWindowHeight
  FormWindowWidth = WindowWidth(#Main)
  FormWindowHeight = WindowHeight(#Main)
  ResizeGadget(#mainScroll, 0,160,FormWindowWidth,FormWindowHeight)
User avatar
spikey
Enthusiast
Enthusiast
Posts: 778
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Scroll Area Resize

Post by spikey »

You haven't allowed for the size of the concealed gadgets and the margin around them when calculating the new size for #mainScroll. You need to do something like:

Code: Select all

FormWindowWidth = WindowWidth(#Main) - (GadgetWidth(#Button) + Margin)
FormWindowHeight = WindowHeight(#Main)
ResizeGadget(#mainScroll, 0,160,FormWindowWidth,FormWindowHeight)
If you're using the Form Designer, you should set the appropriate "Lock" properties on the gadgets so the form designer creates the resize procedure correctly for you. So for example a button to the right of the scroll area should have its "Lock Right" property set and its "Lock Left" property cleared. See the "Layout" section in the "Properties" panel.
User avatar
tikidays
User
User
Posts: 46
Joined: Tue Oct 24, 2023 6:47 am
Location: New Zealand
Contact:

Re: Scroll Area Resize

Post by tikidays »

Ive discovered its not the resize that's the issue, it appears to be the way I have or haven't used closegadgetlist(), if I move this just after the scroll area gadget, the buttons move with the resize and are able to be clicked, however the scroll area objects no longer scroll with the area. This suggests they haven't been added to this scroll area gadget correctly.

Since that I created a container panel for my header at the top of the window, added the gadgets, and closed the list, then I open a scroll area gadget, add gadgets to this and then close the list. But Im still getting the same issue, buttons can't be clicked.

Frustratingly if I manually move the closegadgetlist() in the FormDesigner mock up to include the button, although it now scrolls, it too has the same issue, button can't be clicked on resize. Full code below:

Code: Select all

 
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Global windowTest

Global editTitle, editDescription, textTitle, textDescription, Frame_0, ScrollArea_0, Button_0

Enumeration FormFont
  #Font_windowTest_0
  #Font_windowTest_1
  #Font_windowTest_2
EndEnumeration

LoadFont(#Font_windowTest_0,"Arial Narrow", 18, #PB_Font_Bold)
LoadFont(#Font_windowTest_1,"Arial Narrow", 16)
LoadFont(#Font_windowTest_2,"Arial Narrow", 13)

Declare ResizeGadgetswindowTest()


Procedure OpenwindowTest(x = 0, y = 0, width = 1290, height = 830)
 windowTest = OpenWindow(#PB_Any, x, y, width, height, "Test", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_WindowCentered)
  editTitle = EditorGadget(#PB_Any, 10, 30, 390, 25)
  SetGadgetFont(editTitle, FontID(#Font_windowTest_0))
  editDescription = EditorGadget(#PB_Any, 10, 110, 1250, 40, #PB_Editor_WordWrap)
  SetGadgetFont(editDescription, FontID(#Font_windowTest_1))
  textTitle = TextGadget(#PB_Any, 10, 10, 110, 20, "Title")
  SetGadgetFont(textTitle, FontID(#Font_windowTest_2))
  textDescription = TextGadget(#PB_Any, 10, 90, 110, 20, "Description")
  SetGadgetFont(textDescription, FontID(#Font_windowTest_2))
  Frame_0 = FrameGadget(#PB_Any, 750, 60, 10, 10, "")
  ScrollArea_0 = ScrollAreaGadget(#PB_Any, 0, 160, 1290, 670, 1490, 880, 1)
  Button_0 = ButtonGadget(#PB_Any, 1170, 180, 100, 25, "")
  CloseGadgetList()
EndProcedure

Procedure ResizeGadgetswindowTest()
  Protected FormWindowWidth, FormWindowHeight
  FormWindowWidth = WindowWidth(windowTest)
  FormWindowHeight = WindowHeight(windowTest)
  ResizeGadget(editDescription, 10, 110, FormWindowWidth - 40, 40)
  ResizeGadget(ScrollArea_0, 0, 160, FormWindowWidth - 0, FormWindowHeight - 160)
  ResizeGadget(Button_0, GadgetWidth(ScrollArea_0) - 120, 180, 100, 25)
EndProcedure

User avatar
tikidays
User
User
Posts: 46
Joined: Tue Oct 24, 2023 6:47 am
Location: New Zealand
Contact:

Re: Scroll Area Resize

Post by tikidays »

Forgot to mention this was in MacOS, when compiling under Windows I see a different behaviour, were the Mac shows the gadgets correctly moving with the resize, windows shows a blank gray area of the scroll area. :?
User avatar
HeX0R
Addict
Addict
Posts: 1221
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Scroll Area Resize

Post by HeX0R »

The idea of the ScrollAreaGadget is to have always enough space to place all your gadgets on it, no matter the windows width and height.
It's untypical to move the gadgets inside the scroll area when a window is resized, all that gets resized is usually the outer area.
If you need repositioning of Gadgets, you have to take care about the inner dimensions of the scroll area also, because what happens in your case, the position of the button will reach a point where it is no longer inside the inner area and gets cut until it is gone.
Check for SetGadgetAttribute(), #PB_ScrollArea_InnerWidth and #PB_ScrollArea_InnerHeight
User avatar
tikidays
User
User
Posts: 46
Joined: Tue Oct 24, 2023 6:47 am
Location: New Zealand
Contact:

Re: Scroll Area Resize

Post by tikidays »

Thanks so much! I had just figured this out myself, its a shame that the FormDesigner doesn't accommodate this in the resize, not sure why you wouldn't want your objects that follow the window to be included in the area.

Added this, fixed my issue.

Code: Select all

SetGadgetAttribute(#mainScroll, #PB_ScrollArea_InnerWidth, FormWindowWidth) ; increase the size of the inner scroll area.
Post Reply