STAR TREK 2d20
Page 2 of 3 First 123 Last
  1. #11
    Quote Originally Posted by Trenloe View Post
    You need to check on exactly how relative anchoring works. Some info in the section here: https://www.fantasygrounds.com/wiki/...face#Anchoring

    To have the buttons align next to each other horizontally you'll need to use relative anchoring on the left/right side of the control, to the side of an anchor on the edge of the window. Then you line the controls out from that anchor, with the side edge of each control being relative to the side anchor.

    It's a really powerful piece of functionality that allows controls to dynamically align based off other controls being added (or removed).
    From the sounds of it the buttons are appearing over the top of each other all stacked as one.

    Looking at the code I'd expect it to build them one under the other like a column with each button visible.

    Unless there is something odd with the anchor "text" I'm not seeing... I dunno why it doesn't work.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  2. #12
    Ok, still not working well. I guess I just need some basic layout help.

    Given that I have a textfield named "text" that is correctly positioned in the window (it is inset from the borders and centered), what do I need to do to layout 3 buttons below the textfield that would look something like this:

    Code:
    +---------------------------------+
    !                                 !
    !    Textfield "text"             !
    +---------------------------------+
    +---------+ +---------+ +---------+
    !Button 1 ! !Button 2 ! !Button 3 !
    +---------+ +---------+ +---------+
    I have tried all kinds of combinations of anchors, and can't seem to get it right.

    What would I need to do If I wanted them to be stacked vertically, instead of horizontally?

    Code:
    +---------------------------------+
    !                                 !
    !    Textfield "text"             !
    +---------------------------------+
    +---------------------------------+
    !          Button 1               !
    +---------------------------------+
    !          Button 2               !
    +---------------------------------+
    !          Button 3               !
    +---------------------------------+

  3. #13
    If you want to get them side by side try something like...

    buttons[i].setAnchor("top", "text", "bottom", "absolute",5);
    buttons[i].setAnchor("left", "text", "right", "relative",-SomeValueBasedYoullhavetoFigureout);

    "SomeValueBasedYoullhavetoFigureout" = You'll have to just figure out what the offset will need to be to actually be on the bottom left. If you try and use relative on the left/left alignment it wont do what you want.

    That "should" place them under the text field left to right as your first layout is going for.

    buttons[i].setAnchor("top", "text", "bottom", "relative",5);
    buttons[i].setAnchor("left", "text", "left", "absolute");

    That should stack them one on top of the other aligned to the left corner of the "Text" field.
    Last edited by celestian; July 26th, 2019 at 06:46.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  4. #14
    When I do 3 buttons like that, I usually anchor bottom and left for the 1st button, bottom and right for the 3rd button, and bottom and center for the 2nd button.

    In that way, the buttons will be positioned correctly, even if I change the window size later.

    Regards,
    JPG

  5. #15
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,649
    Blog Entries
    1
    I think in the OPs use case he has a variable number of buttons so needs to anchor the first and each following one would be relative?

  6. #16
    Since I was unable to insert my buttons into the view correctly, I did the next best thing... when the user hovers over the middle of the Notes view, a series of buttons pop up indicating the various rolls that can be made. The buttons disappear if the user moves the mouse away, or click in the Notes view to edit.

    My only problem now is that I would like the buttons to be variable width, based on the text in the button field, and at the moment, I am forced to define a left and a right anchor. As you can see from this:

    3.png

    The last button's label "Click to roll [Sex Appeal+1]" is too large for the button.

    Is there a way to define a left/right anchor that is "in the middle", and have the button grow horizontally to fit it's label?

  7. #17
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,362
    Quote Originally Posted by Nose66 View Post
    Is there a way to define a left/right anchor that is "in the middle", and have the button grow horizontally to fit it's label?
    Not sure about buttons. But for string controls, if the left anchor is defined, but the right anchor isn't, then the string field will expand to fit the text. I don't know if such an approach would work with buttons. You may need to assign a minimum width in the sizelimits parameter. Here's what I used for a stringcontrol that has a minimum width, but will resize horizontally beyond that based on the contents of the control:

    Code:
    <anchored to="label_price" position="righthigh" offset="5,2">
                   <sizelimits>
                                  <minimum width="30" />
                   </sizelimits>
    </anchored>
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  8. #18
    Quote Originally Posted by Trenloe View Post
    Not sure about buttons
    Yeah, it doesn't seem to resize the buttons based on their text. At least not the way I am building the buttons:

    Code:
        buttons[i] = window.createControl("notes_actions", bn);  
        buttons[i].setText("Click to roll ["..a.orig.."]", "Rolling ["..a.orig.."]!");
        buttons[i].setFrame("buttonup");
        buttons[i].setVisible(false);
        buttons[i].setAnchor("left", parent, "left", "absolute", q1x);
        buttons[i].setAnchor("top", parent, "top", "absolute", top);
        buttons[i].setAnchor("bottom", parent, "top", "absolute", top + buttonH);
    Code:
    	<template name="notes_actions">
    		<buttoncontrol>
    			<anchored to="text" position="insideleft" >
                                <sizelimits>
                                  <minimum width="30" />
                                </sizelimits>
                            </anchored>
    			<script>
    			  function onButtonPress()
    			    window.text.buttonPressed(self);
    			  end
    			  function onClickDown()
    			  	setFrame("buttondown");
    			  end
    			  function onClickRelease()
    			  	setFrame("buttonup");
    			  end
    			</script>
    		</buttoncontrol>
    	</template>
    Also, is there a better way to show a button press? Sometimes it misses a click down or click release event and then the frame isn't correct.
    Last edited by Nose66; August 22nd, 2019 at 05:08.

  9. #19
    You need to return true for all of those event functions to indicate to the client code that you want to capture those events, and not use the default processing. Also, you might consider only using the onButtonPress event; and setting the frames using "state" tags. You can also set tags in the template to mirror starting state (i.e. "invisible" tag, instead of calling setVisible(false)).
    https://www.fantasygrounds.com/refdoc/buttoncontrol.xcp

    For layout, if left or right anchor is defined and the other horizontal anchor is not defined and the width is not defined, then the control should resize to fit the text inside (plus any frame offset).

    Regards,
    JPG

  10. #20
    Quote Originally Posted by Moon Wizard View Post
    and setting the frames using "state" tags.
    That sounds promising... how do you do that? Looking at the setStateFrame API it reads:
    A string identifying the state for which the frame is to be set. This value should be one of "hover", "drophilight", "drophover", or "keyedit".
    And none of those states seemed to be what I am looking for.

    I was looking for was a way to show the button as being pressed down, and then pop back up. Unfortunately, onButtonPress won't allow me to show when the button is pressed down, since it only fires when the button is released.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
FG Spreadshirt Swag

Log in

Log in