[r168] Anchor Behavior Incomplete

0 favourites
  • 4 posts
  • Problem Description

    Ok... I know it can be viewed as a feature request more than as a bug per se.

    But I choose to report it as a bug because the modification is so small that it looks more like a design oversight than anything else.

    So here is the thing:

    You can't ask the anchor behavior to just anchor your object vertically OR horizontally, leaving the other axis alone.

    In my case, I just wanted a UI element to stick to the left border and keep using its default Y position.

    But in some scaling mode (like scale outer) the difference between window border and object position can change. Thus Unecessarily moving the object.

    And in any cases, I always wondered why the options between Left, Top, Right and Bottom edge were so inconsistent.

    Here is my simple fix:

    edittime.js

    @@ -76,8 +76,8 @
     // new cr.Property(ept_combo,      name,   "Item 1",       description, "Item 1|Item 2|Item 3")    // a dropdown list (initial_value is string of initially selected item)
     
     var property_list = [
    [ul]
    	[li]new cr.Property(ept_combo,  "Left edge",        "Window left",      "Anchor the object's left edge to a window edge.",  "Window left|Window right"),[/li]
    	[li]new cr.Property(ept_combo,  "Top edge",         "Window top",       "Anchor the object's top edge to a window edge.",   "Window top|Window bottom"),[/li]
    [/ul]+   new cr.Property(ept_combo,  "Left edge",        "Window left",      "Anchor the object's left edge to a window edge.",  "None|Window left|Window right"),
    +   new cr.Property(ept_combo,  "Top edge",         "Window top",       "Anchor the object's top edge to a window edge.",   "None|Window top|Window bottom"),
        new cr.Property(ept_combo,  "Right edge",       "None",             "Anchor the object's right edge.",                  "None|Window right"),
        new cr.Property(ept_combo,  "Bottom edge",      "None",             "Anchor the object's bottom edge.",                 "None|Window bottom"),
        new cr.Property(ept_combo, "Initial state", "Enabled", "Whether to initially have the behavior enabled or disabled.", "Disabled|Enabled")[/code:2hkpntpj]
    
    [b]runtime.js[/b][code:2hkpntpj]@@ -95,7 +95,7 @
            var bbox = this.inst.bbox;
            
            // Anchor left to window left
    [ul]
    	[li]if (this.anch_left === 0)[/li]
    [/ul]+       if (this.anch_left === 1)
            {
                inst.update_bbox();
                n = (layer.viewLeft + this.xleft) - bbox.left;
    @ -108,7 +108,7 @
            }
            
            // Anchor left to window right
    [ul]
    	[li]else if (this.anch_left === 1)[/li]
    [/ul]+       else if (this.anch_left === 2)
            {
                inst.update_bbox();
                n = (layer.viewRight - this.xright) - bbox.left;
    @ -121,7 +121,7 @
            }
            
            // Anchor top to window top
    [ul]
    	[li]if (this.anch_top === 0)[/li]
    [/ul]+       if (this.anch_top === 1)
            {
                inst.update_bbox();
                n = (layer.viewTop + this.ytop) - bbox.top;
    @ -134,7 +134,7 @
            }
            
            // Anchor top to window bottom
    [ul]
    	[li]else if (this.anch_top === 1)[/li]
    [/ul]+       else if (this.anch_top === 2)
            {
                inst.update_bbox();
                n = (layer.viewBottom - this.ybottom) - bbox.top;[/code:2hkpntpj]
    
    (To really really be complete, maybe adding "window left" and "window top" for right edge and bottom edge option, imagining some cases where the object it is assigned to would change size while still be anchored to it's opposite border window... why not? (:  )
    
    I could of course fork the behavior... but just for that it would be... sad.
    
    In any case, Ash, don't hesitate to throw this post in another part of the forum if you don't think it should be here =)
    
    [b]Construct 2 Version ID[/b]
    r168
    
    [b]Edit:[/b]
    Ok after a bit more fiddling, I realised that the plugin was using the first two edges constraint to position the object and the two last to stretch it... which is highly unintuitive I'd say.
    Using my fix, you'd have strange result if you do Top Edge: None + Bottom Edge: Bottom.  I thought first that the object's bottom edge would stick to its initial bottom position, but with the current implementation, it will just stretch the object vertically to keep the bottom edge at its initial bottom position.
    So ok, it might be a mix of feature request and design/conceptual bug report... A matter of opinion (:
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So it's just a new 'None' setting for the window left/top properties? Seems reasonable, added for next build.

  • Yann :

    "Ok after a bit more fiddling, I realised that the plugin was using the first two edges constraint to position the object and the two last to stretch it... which is highly unintuitive I'd say."

    I agree to this, I know the manual describes it perfectly, but a quick and clearer reminder in the description could be useful I think (even though I guess people are les likely to read the manual to understand it then)

  • Ashley

    Yup, but keep a critical eye, I didn't thoroughly test all implication this would have with combining all possibilities. But since it's so small it should be ok =)

    Aphrodite

    Yeah I'm guilty of not usually checking the manual. I prefer directly go into the plugin's source so I understand everything that occurs under the hood.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)