ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Moving a control with (https://www.esoui.com/forums/showthread.php?t=8315)

Letho 02/01/19 05:23 PM

Moving a control with
 
Hey guys, I need some help with the following task:



I want the icon to be dragable, but only by clicks inside the green square in it's top left corner.

If I apply SetMouseEnabled(true) and SetMovable(true) to the base control, the whole control will react to mouse clicks, not only the green square.

If I apply SetMouseEnabled(true) and SetMovable(true) to the green square, then only the green square reacts to mouse clicks, but the icon does not move with it despite being it's parent element.

This is the XML code:


Code:

<!-- Icon aura -->
<Control name="AM_IconAuraControl" virtual="true" clampedToScreen="true">
        <!--<Anchor point="TOPLEFT" relativeTo="AuraMasteryTLW" anchorPoint="TOPLEFT" />-->
        <Controls>
                       
                <Control name="$(parent)_Anchor" hidden="true">
                        <Dimensions x="12" y="12" />
                        <Anchor point="TOPLEFT" relativeTo="$(parent)" anchorPoint="TOPLEFT" />
                        <Controls>
                                <Backdrop name="$(parent)_Backdrop" centerColor="FF00FF00" edgeColor="FF000000" level="2">
                                        <AnchorFill />
                                        <Edge edgeSize="1" />
                                </Backdrop>
                                <Label name="$(parent)_LabelCoords" font="$(BOLD_FONT)|16|soft-shadow-thin" color="00FF00" text="400,400">
                                        <Anchor point="TOP" relativeTo="$(parent)" anchorPoint="TOP" offsetY="-20" />       
                                </Label>
                        </Controls>
                </Control>
       
                <Backdrop name="$(parent)_Backdrop">
                        <AnchorFill />
                </Backdrop>
                <Cooldown name="$(parent)_Cooldown" fillColor="000000BF" horizontalAlignment="TEXT_ALIGN_CENTER" verticalAlignment="TEXT_ALIGN_CENTER">
                        <AnchorFill />
                </Cooldown>
                <Label name="$(parent)_Label">
                        <Anchor point="TOPLEFT" relativeTo="$(parent)" anchorPoint="TOPLEFT" offsetX="2" offsetY="2" />
                        <Anchor point="BOTTOMRIGHT" relativeTo="$(parent)" anchorPoint="BOTTOMRIGHT" offsetX="-2" offsetY="-2" />
                </Label>
                <Texture name="$(parent)_Icon">
                        <AnchorFill />
                </Texture>
        </Controls>
</Control>


Rhyono 02/01/19 05:27 PM

What about adding a parent to it that is taller, so that you have a bar across the top that can move it? Not exactly what you're going for, but it's a fallback option.

Dolgubon 02/01/19 08:13 PM

One option would be to set the anchor of the parent to be relative to the green square. For example,parent:SetAnchor(TOPLEFT, greenSquare, TOPLEFT, 0,0)


Another option (if that doesn't work) would be to use the OnMoveStart and OnMoveStop of the green square, and put something like:
EVENT_MANAGER:RegisterForUpdate("moving", 10, moveParentToGreenSquare)

Letho 02/02/19 01:03 AM

Quote:

Originally Posted by Dolgubon (Post 36990)
One option would be to set the anchor of the parent to be relative to the green square. For example,parent:SetAnchor(TOPLEFT, greenSquare, TOPLEFT, 0,0)


Another option (if that doesn't work) would be to use the OnMoveStart and OnMoveStop of the green square, and put something like:
EVENT_MANAGER:RegisterForUpdate("moving", 10, moveParentToGreenSquare)

AH of course! The green square needs to be the parent, not the icon. I use the register function to update the coordinates in realtime when draging the control around.

Thanks for your help, guys! :)


All times are GMT -6. The time now is 03:00 AM.

vBulletin © 2019, Jelsoft Enterprises Ltd
© 2014 - 2019 MMOUI