Dynamic hierarchy

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

Dynamic hierarchy

Post by Technopeasant »

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: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Dynamic hierarchy

Post by BruceSteers »

Technopeasant wrote: Sunday 8th 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
If at first you don't succeed , try doing something differently.
BruceS
Online
User avatar
cogier
Site Admin
Posts: 1117
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Dynamic hierarchy

Post by cogier »

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

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

Re: Dynamic hierarchy

Post by Technopeasant »

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: 171
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: Dynamic hierarchy

Post by Quincunxian »

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