Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

Script editor, GUI designer, debugger and tools for AutoHotkey
User avatar
boiler
Posts: 5186
Joined: 21 Dec 2014, 02:44

Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

04 Feb 2020, 15:32

Relativity is a tool for converting GUI controls to relative positioning and/or sizing (i.e., to use xs, ys, xp, yp, wp, hp) in GUI scripts created by AutoGUI's GUI designer. It also optionally removes redundant font definition lines.

Image
(version 1.0 shown)

Features:
  • Converts controls with absolute positioning and sizing to 'section' or 'previous' positioning and sizing, automatically doing the math and updating the controls
  • Reorders script lines for the controls (with their associated font specifications) as necessary
  • The Fontalyzer option removes redundant consecutive font definitions, reducing script size and improving readability
  • The testing function allows for visually confirming that controls were grouped/converted as intended by moving (or resizing) the first control of a group and seeing which others automatically move (or change size) with it, as shown below:
Spoiler

Download:
Relativity_v1_2.zip
(99.81 KiB) Downloaded 26 times
Version 1.2 - Requires AutoHotkey v1.1.31+. Tested on Windows 10. Wine/Linux users may require downloading imageres.dll (typically found in Windows installations).
Changelog:
v1.0 - 2020.02.03 - Initial release
v1.1 - 2020.02.12 - Added Align/Nudge feature
v1.2 - 2020.05.26 - Added Open File feature, added menu, allows file save at any time (to allow control re-ordering saves), misc. improvements
planned - Support for AHK v2
Motivation:
I have found AutoGUI's GUI designer to be an excellent tool for laying out and generating the initial code for my GUIs. The GUI script as output by AutoGUI uses absolute positioning for all controls. I find it to be very helpful while developing a script and modifying the initial GUI layout to have many of the controls use relative positioning so moving one control will automatically move those associated with it. But manually converting a large number of controls to relative controls can be a very laborious task, so I created a tool to make it a quick and easy process.
Usage:
When a GUI script is loaded, the relevant controls will be displayed in a table. The user would first reorder the rows in the table as necessary, then indicate which controls are to be section anchors and which are to be positioned by a section or previous control. Width and height can also be based on that of the previous control. When "Update" is clicked, the tool will perform the math and update the options in the controls to reflect the relative positioning (shown in the first image above).

After updating, clicking "Test" will generate a visual demonstration to confirm the changes were made as intended. For each section control and for each control that begins a sequence of previous controls (called a "test point"), the position and/or size (as applicable) will be changed, and the associated relative controls will also change in position or size. If a problem is spotted, just make any changes necessary and update and test again.

The "Fontalyzer" option removes redundant font definition lines (including the lines that return the font to normal) from consecutive controls that have identical font definitions. See below for a before/after example. The "Group" option will take all controls that don't have to be in a particular order because they are not involved in relative positioning and group them together if they have identical font definitions before running Fontalyzer so that even more lines can be eliminated.
Spoiler
Last edited by boiler on 26 May 2020, 19:22, edited 5 times in total.
TAC109
Posts: 528
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

04 Feb 2020, 18:06

Looks very interesting! Does your code depend on Gui -DPIScale? One reason I can’t try AutoGUI is that it can’t handle DPI other than 96 (100%). Other GUI creators I’ve tried suffer from the same problem. My computer is a Surface Pro 4 which runs at 200%. At a DPI of 96 windows are virtually unreadable.
My programs:-
ReClip - a Text Reformatting and Clip Management utility
XRef - Produces Cross Reference lists for scripts
User avatar
boiler
Posts: 5186
Joined: 21 Dec 2014, 02:44

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

04 Feb 2020, 18:27

I didn’t test it for other DPI settings knowing that AutoGUI is made for use only at 100% scaling currently. If you aren’t able to use AutoGUI, I don’t think this tool would be useful to you anyway, but thanks for your interest.
User avatar
haichen
Posts: 445
Joined: 09 Feb 2014, 08:24

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

05 Feb 2020, 02:56

I've just been playing around with it a little. It's a great tool. Just what I had in mind.
I've got another idea or wish:
If you could change the relative values of the selected controls,
so that all selected controls have the same value for e.g. xp?
So e.g. select controls with xp+10 xp+11 xp+10 and set all to xp+10 or xp+20 or only xp.
Thank you very much for providing us with this.
User avatar
Drugwash
Posts: 746
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

05 Feb 2020, 04:18

Good idea, could've used such tool back on Windows. :)

Tried to test it in Linux Mint under Wine 5.1 and first thing popped up an error messagebox related to the Switch command. I realised it was due to an older AHK version (1.1.30.03) so I updated to 1.1.32.00. It may be a good idea for you to mention this version requirement somewhere in first post in order to avoid any further similar bug reports.

Also Wine couldn't find imageres.dll so I had to download it from the web (for testing purposes) and place it in same folder where Relativity.ahk lays. Just saying this in case other Linux users attempt to run your script.

Now, I know it says very clearly that it's meant to be used with unmodified GUI scripts created by AutoGUI, but IMHO this kinda limits its usage range very much. One might want to convert GUIs from older scripts where coordinates may include variables (such as x+m1, y+spc2, w%w5%, h50-var4 or anything similar). Hopefully you could add the capability to process such scripts in a future version. ;)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
boiler
Posts: 5186
Joined: 21 Dec 2014, 02:44

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

05 Feb 2020, 11:00

haichen wrote: I've just been playing around with it a little. It's a great tool. Just what I had in mind.
I've got another idea or wish:
If you could change the relative values of the selected controls,
so that all selected controls have the same value for e.g. xp?
So e.g. select controls with xp+10 xp+11 xp+10 and set all to xp+10 or xp+20 or only xp.
Thank you very much for providing us with this.
Glad you like it, and thanks for the suggestion. I had thought about implementing a feature like that, but then I thought AutoGUI already has alignment features so I didn't. However, I can see that one might not notice they're not exactly aligned until after they see the numbers like in your example. I'll add something that will allow for aligning/nudging them in the next update.
Drugwash wrote: Good idea, could've used such tool back on Windows. :)

Tried to test it in Linux Mint under Wine 5.1 and first thing popped up an error messagebox related to the Switch command. I realised it was due to an older AHK version (1.1.30.03) so I updated to 1.1.32.00. It may be a good idea for you to mention this version requirement somewhere in first post in order to avoid any further similar bug reports.

Also Wine couldn't find imageres.dll so I had to download it from the web (for testing purposes) and place it in same folder where Relativity.ahk lays. Just saying this in case other Linux users attempt to run your script.

Now, I know it says very clearly that it's meant to be used with unmodified GUI scripts created by AutoGUI, but IMHO this kinda limits its usage range very much. One might want to convert GUIs from older scripts where coordinates may include variables (such as x+m1, y+spc2, w%w5%, h50-var4 or anything similar). Hopefully you could add the capability to process such scripts in a future version. ;)
Thank you for pointing that out about the AHK version. I'll add that as a requirement in the first post as you suggested. I'll also mention that Windows vs. Linux issue.

Regarding not being able to use GUIs from older scripts, that introduces issues that are quite difficult to overcome. By using the output of AutoGUI, it is always starting with a known location since each control has absolute positioning (and sizing) numbers associated with it. At least with the approach I've taken for this, it won't really be possible to make it work with generic GUI scripts. So while this tool won't work with GUIs already incorporated into working scripts, I see this tool as an extension of AutoGUI's GUI designer -- something that would be used immediately after finishing the layout using that tool, which I find greatly increases the value of the GUI designer for my purposes (and hopefully for others) and is the reason I created it.
User avatar
Drugwash
Posts: 746
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

05 Feb 2020, 13:31

Thanks for considering my suggestions.

Long ago I managed to get SmartGui Creator to extract most of the GUI-related code and process it, including such "non-standard" coordinates. It wasn't perfect by any means but sometimes it could do a good job. Code, however, was a mess. :lol: And, ironically, it couldn't do what your code does: switch from absolute to relative coordinates when saving. Wish I still had what it takes to work on that code and update it, but I'm afraid it's too late.

Anyway, the way I used to update GUIs when needed was by copy/paste only the GUI-related code into a new script, for much easier processing. SmartGui would then convert to absolute coordinates, additions/adjustments/deletions were done, and then saving. Dunno if AutoGUI can load and edit GUIs that use relative/variable coordinates, I'd assume it can't, so it would be great for your tool if it could read such scripts (maybe even converted by itself), convert to absolute, feed them to AutoGUI for editing, and then read and convert the result back to relative.

Well, it's just an idea. Good luck ahead! :)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
boiler
Posts: 5186
Joined: 21 Dec 2014, 02:44

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

05 Feb 2020, 14:48

Actually, that's a very good point. AutoGUI does have an "Import GUI" function. In my limited testing of its feature that clones an active GUI window (as opposed to the option that parses a script, which is not recommended so I haven't tried it), how well it is able to replicate the GUI depends on how complex the GUI is. It wasn't really able to capture the Relativity GUI, for example. So I think you hit on a good solution that can work in some cases.

Another thing to keep in mind is that the imported GUI wouldn't contain any of the "smarts" you may have coded into it, like positioning with variables as in your earlier example, or g-labels and v-variables. However, you may find it easier to put those things back in manually than to manually convert the absolutes to relatives depending on the script. It's definitely an approach to keep in the bag of tricks.

Thanks for the encouragement! :thumbup:
User avatar
Drugwash
Posts: 746
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

06 Feb 2020, 04:09

Indeed the issue with variable-bound coordinates can be tricky, but is solvable with a bit of effort (like asking the user to manually input values for each variable, for example).
The v, g, hwnd and other parameters can be parsed, if existing. SmartGUI does that. ;) Of course, everything can be put back manually later on.

Just for kicks I tested latest SmartGUI code (4.4.0.7, modified to some extent for Unicode compatibility) under Wine and it managed to grab the Relativity GUI completely (except for the ListView header and items; the missing symbols for up/down/top/bottom are due to the font used by Wine). Unfortunately, for some reason (code bugs or wine quirks) it also adds blank g-labels and hwnds to the resultant code, as well as a blank/invalid label; but just by giving the blank label a random name the resultant GUI code is runnable.
Screenshot from 2020-02-06 10-41-28.png
Stealing Relativity's GUI
Screenshot from 2020-02-06 10-41-28.png (87.33 KiB) Viewed 3913 times
Screenshot from 2020-02-06 11-05-12.png
Stolen Relativity :-)
Screenshot from 2020-02-06 11-05-12.png (25.18 KiB) Viewed 3913 times
So I guess everything is possible in the programming world - one just has to find the (proper) way. 8-)
Keep up the good work! :thumbup:
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
boiler
Posts: 5186
Joined: 21 Dec 2014, 02:44

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

06 Feb 2020, 08:04

So it looks like it would be helpful if I made sure relativity worked with the output of SmartGUI Creator, which upon a quick look of some of the output I've seen in other threads, it may already be capable of. I'll look into it in more detail, and if that is indeed the case, I probably should post a thread for Relativity in the more general "Editors" section of the forum noting that it can be used with the GUIs created by either tool. Thanks for the insight.
User avatar
Drugwash
Posts: 746
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

06 Feb 2020, 11:01

To be fair, SmartGui is quite outdated considering latest changes in AHK 1.1 (it was developed by Rajat and then myself mostly in the AHK 1.0 era). I tried my best to make it compatible with Win9x - since it used to be my main OS - and at some point attempted to update it to work with AHK 1.1 Unicode. However many new commands and features are not (yet?) recognized and parsed so it can't really be considered a full competitor in regard to AutoGUI and the others. Still, it can do some things that others may not be able to do. However, it does not have its own "signature", it takes scripts as they are - even full-blown ones - so it may be difficult for you to create a compatibility pattern.

What you can do is try a generic recognition of specific GUI commands in the autoexec section (until first Return command or End Of File) and only parse those. Complications may arise when multiple GUIs are defined, and frankly not even SmartGui is able to handle those. At some point I started working on a new editor with a completely new approach allowing multiple workspaces with multiple GUIs but never managed to take it to a working stage (and in the mean time someone "stole" the name I wanted to give to it, which further deterred me).

It all boils down to looking at the bigger picture, gathering all necessary data, planning things down carefully, and then getting to work.
Ha, it sounds so easy, doesn't it... :)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
boiler
Posts: 5186
Joined: 21 Dec 2014, 02:44

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

06 Feb 2020, 16:06

I see. I wasn't aware of its history. I knew it had been around a while. I won't spend time on support for it right now then.

As far as Relativity being able to import existing GUIs itself, beyond the parsing issues, one reason I have it using the output of AutoGUI's designer directly is for the testing function, which cycles between two versions of the script with one version having the controls slightly moved. If a script does anything but display the GUI when it's executed, that would really mess things up. I suppose it could strip out the non-GUI-related stuff, but that's getting into more than I'm looking to do at the moment. The goal was to be able to create a GUI layout in AutoGUI, then be able to convert it from absolute positioning to relative positioning. The fact that everything is positioned in absolute terms is the reason I avoided using GUI creation tools in general, so this helps make AutoGUI's GUI designer very useful to me now. Having it work with any GUIs is a laudable goal, but I can't take that on right now.
User avatar
Drugwash
Posts: 746
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

07 Feb 2020, 10:51

Understandable. At least you now know more about other editors. :)
The only drawback in Relativity is that once converted, a GUI cannot be edited again in AutoGUI. A bidirectional conversion might even allow a seamless integration of Relativity in AutoGUI as one of the official tools. ;)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
boiler
Posts: 5186
Joined: 21 Dec 2014, 02:44

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

07 Feb 2020, 11:24

As I understand it, it's not a matter of conversion. Even a GUI script generated by AutoGUI cannot be edited again by the GUI designer once it's saved and the session is closed. Since it cannot be edited again even with no changes, a converter won't change that fact. It could be imported into AutoGUI, but that can be done with no conversion (the import is essentially the conversion).
User avatar
Drugwash
Posts: 746
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

07 Feb 2020, 14:15

Ah, if the import takes care of any necessary conversion then it's OK. Frankly I haven't played much with AutoGUI, for some reason, so I don't really know its strengths and weaknesses. Anyway, it's good we got to talk some ideas out, maybe at some point something useful will come out of this.
Thank you for listening. ;)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
boiler
Posts: 5186
Joined: 21 Dec 2014, 02:44

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

12 Feb 2020, 16:38

haichen wrote:
05 Feb 2020, 02:56
I've got another idea or wish:
If you could change the relative values of the selected controls,
so that all selected controls have the same value for e.g. xp?
So e.g. select controls with xp+10 xp+11 xp+10 and set all to xp+10 or xp+20 or only xp.
I've updated the original post with a new version that incorporates this capability. You can align positions and/or sizes either before or after converting them to relative from absolute. If aligning relative controls, they must be all of the same type for what you are aligning. For example, if aligning in x and one of the controls is xp+1, then the rest being aligned must also be of xp type. It then allows you to choose the amount of offset (defaulting to the amount of the first one in the list). You can also nudge the position or size of an individual control if you choose.
nichatr
Posts: 7
Joined: 17 May 2019, 01:43
GitHub: nichatr

Re: Relativity - Add relative positioning to controls in GUIs created by AutoGUI's GUI designer

07 Mar 2020, 09:25

Very useful program. Thank you very much!

Return to “AutoGUI”

Who is online

Users browsing this forum: No registered users and 17 guests