Problems with Containers

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Problems with Containers

Post by JumpyVB »

What I struggle most in Gambas is probably the arrangement of gui elements. I find the Containers such as Panel cumbersome to works with. What I need to achieve (and am unable to currently) is placing two TextLabels on top of each other, aligned right on the main panel, and aligned left in regards of each other.

So far I am pretty close with this:
OverlapTest.png
OverlapTest.png (79.4 KiB) Viewed 3852 times
Where:
'FMain
' .Arrangement = Arrange.Vertical
' .Autoresize = True
'GreenPanel
' .Arrangement = Arrange.Horizontal
'   Spring
'   OrangePanel
'    .Arrangement = Arrange.Vertical
'    .Autoresize = True
'    .Centered = True
'      BlueTextLabel_XXX
'       .Alignment = Left
'       .Autoresize = True
'       .Wrap = False
'      GreenishTextLabel_O
'       .Alignment = Left
'       .Autoresize = True
'       .Wrap = False


What do I need to change to make XXX and O drawn on top of each other? I'm thinking of a customized version of the Panel class with the stacking feature removed, but don't know how to do this.
User avatar
BruceSteers
Posts: 1580
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Problems with Containers

Post by BruceSteers »

How do you mean "on top of eachother" ?

Do you mean overlapping so it looks like one label?

If yes then it would be better to put them in a Horizontal aligned panel with a border and no spacing then remove the borders from the labels.

Then the panel border acts like the label border and the labels will look like one and can be aligned accordingly.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Problems with Containers

Post by cogier »

There is definitely an art to getting the GUI items the way you want, but it's worth the effort. Have a look at ExpandingForms on the Farm or available here. It will give you the basics.

Regarding your present issue, I think what you are looking for is below. Be careful with the use of AutoResize. In your image it has reduced the size of the TextLables to next to nothing as there is next to nothing in them!

If I have incorrectly interpreted what you are looking for, then let me know and I will try again. If you want the TextLables at the bottom, remove the top Spring. If you want the TextLables at the top, remove both of the Springs.

Image
Test-0.0.1.tar.gz
(12.61 KiB) Downloaded 150 times
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: Problems with Containers

Post by JumpyVB »

BruceSteers wrote: Sunday 1st October 2023 9:28amDo you mean overlapping so it looks like one label?
I want O to be draw over X; Not above or below.
OX.png
OX.png (6.48 KiB) Viewed 3829 times
And the width of the element should be exactly the length of Xxx no more or less. Eventually I will hide Xxx. I want Xxx to reserve the space and not be visible. O should be aligned left.

PS: I try to make my app work consistently on both GTK and QT with different display scalings on each platform. I noticed that margin, padding and width are not reliable in QT with display scaling.

PSS: I also noticed that leading white space and consecutive white space is trimmed off from Gambas Text elements. This poses yet another problem I try to circumvent.

Maybe I have to investigate creation of a CustomContainer https://gambaswiki.org/wiki/dev/gambas?l=ru

Here's am example where this is going to be used:
PDHJDel.png
PDHJDel.png (144.41 KiB) Viewed 3828 times
The keyboard shortcuts on the right side may vary depending on user settings and could be as long as "Ctrl+Shift+U" or as short as one letter; But I don't want to hard code the space for this. I want the reserved space to be only as wide as it needs to be. This involves extra steps I can code myself. Currently I just need a way to draw 2 text labels over each other and have the element to autoresize according to the longer label.
User avatar
thatbruce
Posts: 168
Joined: Saturday 4th September 2021 11:29pm

Re: Problems with Containers

Post by thatbruce »

Code: Select all

Public Sub Form_Open()

  Dim L1 As New Label(Me)
  Dim L2 As New Label(Me)
  
  L1.X = 1
  L1.Y = 1
  
  L2.X = 1
  L2.Y = 1
  
  L1.AutoResize = True
  L2.AutoResize = True
  
  L1.Text = "Xxxxx"
  L2.Text = "O"

  Me.W = L1.Width
  Me.H = L1.H
  
End
That is the entire code for the project, just an empty form with this proc. No containers.
Have you ever noticed that software is never advertised using the adjective "spreadable".
Post Reply