Jump to content

Dynamically positioning GUI alements


nitro322
 Share

Recommended Posts

I've written a GUI app that can be displayed in various languages, depending on which translation file is loaded. Functionally it works fine, but it's created a layout problem due to differences in text length. For example, the English label "write debug file to" becomes significantly longer when translated into German. So, any elements positioned to the right of that label using the English version will overlap the end of the label when displayed in German.

Can anyone recommend any suggestions on how I can workaround this? I know that I can specify -1 as the width of an control to make it automatically expend to the correct size, but I can't figure out how to do the same for the position of an control. Eg, how do I specify that an control begin 5px past the end of the previous control?

Thanks.

Link to comment
Share on other sites

That's an interesting idea, but I have two problems with your suggestion:

1. I need the width of the previous control in addition to the position, so I can calculate the position of the next control as PrevPos + PrevWidth + Spacer.

2. More importantly, I don't know _how_ to write a custom function to get the position. I looked through the GUI function list for ideas, but everything seems focused on setting control properties as opposed to getting them.

I hate to sound like a newb, but could you please provide a little more detail to get me started?

Thanks.

Link to comment
Share on other sites

maybe..

#include<GuiConstants.au3>

$Label_text = " this is how long the label is "

$Main_GUI = GUICreate("Gui", 500, 250)

$Label = GUICtrlCreateLabel($Label_text, 50, 70)
$pos = GetPos($Label)
$OK_BUT = GUICtrlCreateButton("OK", $pos + 70, 70, 80, 20)

$Label_text = $Label_text & $Label_text

$Label = GUICtrlCreateLabel($Label_text, 50, 100)
$pos = GetPos($Label)
$OK_BUT = GUICtrlCreateButton("OK", $pos + 70, 100, 80, 20)

GUISetState()

While 1
    $msg = GUIGetMsg()

    If $msg = -3 Then Exit
WEnd

Func GetPos($control, $value = 2)
    $Location = ControlGetPos($Main_GUI, "", $control)
    Return $Location[$value]
EndFunc   ;==>GetPos

8)

NEWHeader1.png

Link to comment
Share on other sites

Shoot, I completely missed that ControlGetPost() function (and yes, after re-reading your original post I see it clearly mentioned).

I think this may get pretty ugly for a complicated GUI, but I should be able to make this work. Thanks, Valuater, this is a huge help.

Btw, has any thought been given to a relative vs. absolute layout for AutoIt? Eg, think of an HTML page where all elements are positioned relative to each other, ragardless of size/width/etc. Obviously pixel-based layouts as AutoIt currently implements certainly have their uses, but I've encountered a few situations (such as this one) where relative positioning would be really[/em] handy. Just wondering if this has come up before.

Thanks again.

Link to comment
Share on other sites

Welcome!

and yes... maybe GUICoordMode

#include <GUIConstants.au3>

GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
$Button_1 = GUICtrlCreateButton ("Run Notepad",  10, 30, 100)
$Button_2 = GUICtrlCreateButton ( "Button Test",  0, -1)

GUISetState ()      ; will display an  dialog box with 2 button

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            Run('Notepad.exe')    ; Will Run/Open Notepad
        Case $msg = $Button_2
            MsgBox(0, 'Testing', 'Button 2 was pressed')    ; Will demonstrate Button 2 being pressed
    EndSelect
Wend

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...