Dynamic hierarchy

Post your Gambas programming questions here.
Post Reply
User avatar
Technopeasant
Posts: 68
Joined: Saturday 13th July 2019 6:50pm
Location: Stony Plain, Alberta, Canada
Contact:

Dynamic hierarchy

Post by Technopeasant » Sunday 08th August 2021 12:07am

I am wondering if there is any way to change the hierarchy of controls in code. The only way I know how is to generate the objects in code in the order you want them to be placed. This is annoying when you would want a control created from within the IDE to be above a control generated from within the program (i.e. the HUD elements in my new game Bring Them On). I could just generate the labels in code, but that does not seem like the optimum solution.
Technical director,
Piga Software
http://icculus.org/piga/

User avatar
BruceSteers
Posts: 652
Joined: Thursday 23rd July 2020 5:20pm

Re: Dynamic hierarchy

Post by BruceSteers » Sunday 08th August 2021 1:24am

Technopeasant wrote:
Sunday 08th August 2021 12:07am
I am wondering if there is any way to change the hierarchy of controls in code. The only way I know how is to generate the objects in code in the order you want them to be placed. This is annoying when you would want a control created from within the IDE to be above a control generated from within the program (i.e. the HUD elements in my new game Bring Them On). I could just generate the labels in code, but that does not seem like the optimum solution.
MyControlName.Raise() will bring it to the top. .Lower() to the bottom for your base objects
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
cogier
Site Admin
Posts: 756
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Dynamic hierarchy

Post by cogier » Sunday 08th August 2021 11:20am

You can also alter the order in the IDE. Below, I have reversed the order of 3 Buttons.

Image

User avatar
Technopeasant
Posts: 68
Joined: Saturday 13th July 2019 6:50pm
Location: Stony Plain, Alberta, Canada
Contact:

Re: Dynamic hierarchy

Post by Technopeasant » Wednesday 11th August 2021 3:44am

I knew there had to be something obvious like that...

Thanks Bruce!

Would be kinda nice to be able to re-order controls in relation to each other and not just the parent, but it does the job.

EDIT: I am now curious about the Hide method. How is it different than changing the visibility?
Technical director,
Piga Software
http://icculus.org/piga/

User avatar
Quincunxian
Posts: 132
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: Dynamic hierarchy

Post by Quincunxian » Wednesday 11th August 2021 10:32pm

To re-order the controls you will need to have them in a container - A Panel is well suited to this.
I use something similar to set tool buttons in a horizontal panel - This example is set for a vertical sequence.
{As per your example}
If you want to centre them in the panel, you can use
Ctrl.X = (InPanel/2) - (InW/2)


Because you are using the 'For Each' in the subroutine, it will use the sequence set in the hierarchy to process.
Private Sub SetButtonSequence(InH As Integer, InW As Integer, ByRef InPanel As Panel)
Dim Ctrl As Control 
Dim Buffer As Integer = 5
Dim TmpPos As Integer = Buffer
 
For Each Ctrl In InPanel.Children
  If Ctrl Is Button Then
    Ctrl.Height = InH
    Ctrl.Width = InW
    Ctrl.X = Buffer
    Ctrl.Y = TmpPos
    TmpPos += (InH + Buffer)
  Endif 
Next      
Cheers - Quin.
I code therefore I am

Post Reply