Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Control Anchoring v4 for resizing windows


  • Please log in to reply
78 replies to this topic
toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Thanks.
I looked at your homepage and blog too. Very nice. I like the navigation. Is that difficult to set up and maintain?
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Thanks. Maintaining my site is very easy thanks to Dreamweaver :)
Creating it was sort of difficult. This was because I had to think of a layout, create the CSS styles and images, write a few php and javascript files, cross test between browsers (which made me understand why IE is so disliked by webmasters) and do a little Apache hacking all whilst conforming to the XHTML 1.0 Strict rules. Feel free to copy or use any resources from my site 8)

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005
Although I've been downloading versions of Anchor as they were released, I've never had much use for it -- my GUI's were fairly simple, I've would just write my own sizing code.

Anyway, I started working on a new GUI with a lot more controls on it so I thought I would give Anchor another try/see. Let me just say that the latest version of Anchor is kick-ass!! :!: :D

Thanks for sharing! 8)

jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005
First of all, kick-ass function. See post above.

I ran into a problem/situation with Anchor that I thought I would share. I have a small app that creates a pop-up window to collect information based on dynamic data. Although the object names may remain the same, the starting X and Y positions of an object will change from time to time. The first time the window is created, everything is all good but the 2nd and subsequent times the window is created, Anchor uses some of the object specifications from the first time the window was created and... I think you see the problem.

To solve my problem, I first thought of using a new GUI number every time the pop-up is created but I would eventually run out of window numbers if the application were run for a long time.

The best (?) approach I came up to fix the problem is to get Anchor to remove the records for a particular GUI on request. I created code to solve my problem by deleting the GUI records when it finds an object name equal to "$Delete$". For example:
Anchor("$Delete$","")
Here's the code (added to the very top of the function):
;-- GUI exist?
if not A_GUI
    return

;-- Delete records for the current GUI?
if ctrl=$Delete$
    {
    ;-- Rebuild pos
    tpos:=pos
    pos=
    loop parse,tpos,`n
        {
        ;-- Empty record?
        if A_LoopField is Space
            continue

        ;-- Keep this one?
        if instr(A_LoopField,A_GUI . ":")<>1
            pos:=pos . "`n" . A_LoopField
        }

    return
    }
Using this approach, the target GUI must be "active" so the best time to execute the code would be just before/after the GUI is destroyed. For example:
GUIClose:
Anchor("$Delete$","")
gui Destroy
return
A similar approach to the one above is to use another Anchor function parameter to pass the target GUI window number. Something like the following:
Anchor("$Delete$","23")
This approach allows the developer to remove the target GUI records even if the GUI is not currently active.


These are just a few ideas. I'm hoping that you'll give it some thought and come up with a final solution that will work for everybody.

Them be my thoughts...

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
In version 3.4 I replaced a lot of the string commands with a single regex and reduced the amount of calculations which should make it work faster.

The best (?) approach I came up to fix the problem is to get Anchor to remove the records for a particular GUI on request.

Seems like a good idea, I'll try to work on something for the next version.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Thanks for the update. Very clever. It took me a while to understand.
The only improvement I could see is to avoid the "i" in the last loop by using "A_index" all the time.

I see that your code gets each time Anchor() is called the factors from the string a by RegExMatch. I tried to modify the code to get the factors only at first call and store them in the pos string. But it doesn't seem to improve speed (It is fast anyway). Have you made measurements?

For each control a lot of data is stored, even if it is only resized in e.g. "w". Do you see any way to store only the data needed e.g. for "w" in pos and operate only on this data later. It might shrink the memory/length of pos and speed up.

Since we know the number of items we need from the pos string. It might be possible to use RegExMatch for this as well, instead of StringMin and StringSplit.

Just my 2 €cent.

Thanks again for this great function.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
On jballis idea:
I think the best approach is to specify "delete" for the a string. Thus, data can be delete for individual controls. The only drawback would be that you have to call it multiple times if you want to delete data for every control on a gui. But since you have to call it the same way for resize, it is just a copy&paste action. Maybe a "deleteAll" for the a string could be used as a shortcut.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

The only improvement I could see is to avoid the "i" in the last loop by using "A_index" all the time.

That would take up too much space lol

But it doesn't seem to improve speed (It is fast anyway). Have you made measurements?

No I just assumed RegEx would be faster than several string commands. Either way, the speed difference would be insignificant. If you want, you can compare benchmark results with older versions.

It might be possible to use RegExMatch for this as well, instead of StringMin and StringSplit.

Thanks, I made this change in version 3.4.1 along with a few other things.

Do you see any way to store only the data needed

I prefer to keep it this way as it eliminates bugs with duplicates like Anchor("ctrl", "w") ... Anchor("ctrl", "h.5"). Due to the new RegEx I don't think it's possible anyway.

I think the best approach is to specify "delete" for the a string.

That would be a problem if you have a gui control with the variable 'delete'.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005

I think the best approach is to specify "delete" for the a string.

That would be a problem if you have a gui control with the variable 'delete'.

I suggested to use the string "delete" for the "a" string (second parameter). Not for the "ctrl" string (first parameter). This way there is no conflict with control names.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Ace_NoOne
  • Members
  • 299 posts
  • Last active: May 02 2008 08:19 AM
  • Joined: 10 Oct 2005

I got late in testing out this nice function... its very well-made and works great.. thanks for posting!

Ditto on all accounts! (Except that I'm even later than Rajat... )
Great job, Titan, as always!

MisterGank
  • Members
  • 26 posts
  • Last active: Jun 23 2009 06:32 AM
  • Joined: 07 May 2005
I'm getting a "Call to nonexistant function" error from line 10. Is it just me? I've got both the Anchor.ahk and the anchor-example.ahk. The error is in the Anchor.ahk.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
You have to use the latest AHK version.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

MisterGank
  • Members
  • 26 posts
  • Last active: Jun 23 2009 06:32 AM
  • Joined: 07 May 2005
never mind, the commented version works PERFECTLY! Thank you, this is awsome! (I just wish that it was simpler or built in!)

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

I just wish that it was simpler

Me too, if you have any suggestions I'll be glad to hear them.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


AGU
  • Guests
  • Last active:
  • Joined: --
Hi Titan, :)

I'm currently trying to adapt your new version of Anchor(). I don't get this thing with the factors e.g. x0.5. What's it good for?

Then I'd like to ask if it would be possible to get a commented version of your new script (just like toralf but for the new version ;))?

You know already that I'm using an older version of your function within my BBCodeWriter script. :mrgeen: The concerning code is:
Anchor("EdtComment"   , ""  , ""  , EdtW, EdtH    )
      Anchor("GrpMenuBorder", ""  , ""  , GrpW, ""      )
      Anchor("ChkSig"       , ""  , ChkY, ""  , ""      )
      Anchor("DDLSig"       , ""  , DDLY, ""  , ""      )
      Anchor("BtnEditSig"   , ""  , BSgY, ""  , ""      )
      Anchor("BtnDelSig"    , ""  , BSgY, ""  , ""      )
      Anchor("BtnSend"      , BG1X, BG3Y, ""  , ""  , 1 )
      Anchor("BtnPreview"   , BG2X, BG3Y, ""  , ""  , 1 )
      Anchor("BtnReset"     , BG3X, BG3Y, ""  , ""  , 1 )
      Anchor("BtnPinned"    , BG4X, ""  , ""  , ""      )

Do I have to change s.th here or could I just paste your new version over the old one?
_______________________
Cheers
AGU