WoW:API Frame StopMovingOrSizing: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(article did not exist before; copied and tweaked the content from StartMoving())
 
mNo edit summary
Line 1: Line 1:
{{widgetmethod}}
{{widgetmethod}}


Stops a frame movement or resize that was started with [[API StartMoving|StartMoving()]] or [[API StartSizing|StartSizing()]].
Stops a frame movement or resize that was started with {{api|Frame:StartMoving|t=w}}() or {{api|Frame:StartSizing|t=w}}().


  obj:StopMovingOrSizing()
  obj:StopMovingOrSizing()
Line 26: Line 26:
;''Description''
;''Description''


*Stops the frame-based object from moving or resizing in relation to where the mouse is being moved -- this would have been started with [[API StartMoving|StartMoving()]] or [[API StartSizing|StartSizing()]].
*Stops the frame-based object from moving or resizing in relation to where the mouse is being moved -- this would have been started with {{api|Frame:StartMoving|t=w}}() or {{api|Frame:StartSizing|t=w}}().
*Use [[API RegisterForDrag|RegisterForDrag()]] and the <OnDragStart>...</OnDragStart> event to allow your frame-based object to be moved or resized by the user.
*Use {{api|Frame:RegisterForDrag|t=w}}() and the <OnDragStart>...</OnDragStart> event to allow your frame-based object to be moved or resized by the user.
*Use this function inside the <OnDragStop>...</OnDragStop> XML section to stop the moving or resizing process.
*Use this function inside the <OnDragStop>...</OnDragStop> XML section to stop the moving or resizing process.
*For pixel-precise movements, you should instead use [[API EnableMouse|EnableMouse()]] and the <OnMouseDown>...</OnMouseDown> and <OnMouseUp>...</OnMouseUp> events (and probably also the <OnHide>...</OnHide> event).
*For pixel-precise movements, you should instead use {{api|Frame:EnableMouse|t=w}}() and the <OnMouseDown>...</OnMouseDown> and <OnMouseUp>...</OnMouseUp> events (and probably also the <OnHide>...</OnHide> event).


;''Notes''
;''Notes''
*If the frame becomes stuck by any cause (see [[API SetClampedToScreen|SetClampedToScreen()]]), the mouse and the frame will go out-of-sync.
*If the frame becomes stuck by any cause (see [[API SetClampedToScreen|SetClampedToScreen()]]), the mouse and the frame will go out-of-sync.
*This function together with [[API StartMoving|StartMoving()]] exhibit some "special" behavior that can cause problems when used with frames that are not anchored to UIParent (or some other full-screen frame).
*This function together with {{api|Frame:StartMoving|t=w}}() exhibit some "special" behavior that can cause problems when used with frames that are not anchored to UIParent (or some other full-screen frame).
**Immediately upon calling [[API StartMoving|StartMoving()]], the frame will be de-anchored from any other frame it was previously anchored to, and instead anchored to the screen.  For example, if MyFrame's TOPLEFT is anchored to MyParent's TOPLEFT at (5,-5), and MyParent's TOPLEFT is anchored to UIParent's TOPLEFT at (100,-100), then MyFrame:[[API StartMoving|StartMoving()]] immediately re-anchors MyFrame's TOPLEFT to the screen's (nil anchor) TOPLEFT at (105,-105).  The original anchor frame (MyParent) and offset will not be restored by StopMovingOrSizing().
**Immediately upon calling {{api|Frame:StartMoving|t=w}}(), the frame will be de-anchored from any other frame it was previously anchored to, and instead anchored to the screen.  For example, if MyFrame's TOPLEFT is anchored to MyParent's TOPLEFT at (5,-5), and MyParent's TOPLEFT is anchored to UIParent's TOPLEFT at (100,-100), then MyFrame:[[API StartMoving|StartMoving()]] immediately re-anchors MyFrame's TOPLEFT to the screen's (nil anchor) TOPLEFT at (105,-105).  The original anchor frame (MyParent) and offset will not be restored by StopMovingOrSizing().
**Furthermore, StopMovingOrSizing() will identify the closest anchor point on the screen and re-anchor the frame once again to that closest point.  For example, if MyFrame is dragged to (50,-600) (still relative to the screen), and has a height of 25, then MyFrame:StopMovingOrSizing() immediately re-anchors MyFrame's BOTTOMLEFT to the screen's BOTTOMLEFT at (50,143) (recall that the WoW UI always has height 768 regardless of resolution).
**Furthermore, StopMovingOrSizing() will identify the closest anchor point on the screen and re-anchor the frame once again to that closest point.  For example, if MyFrame is dragged to (50,-600) (still relative to the screen), and has a height of 25, then MyFrame:StopMovingOrSizing() immediately re-anchors MyFrame's BOTTOMLEFT to the screen's BOTTOMLEFT at (50,143) (recall that the WoW UI always has height 768 regardless of resolution).
**There does not appear to be any way to disable either of these behaviors.  If you want your frame to end up anchored to the same frame it was anchored to initially, one way to work around this issue is to store the result of [[API GetPoint|GetPoint()]] three times:
**There does not appear to be any way to disable either of these behaviors.  If you want your frame to end up anchored to the same frame it was anchored to initially, one way to work around this issue is to store the result of [[API GetPoint|GetPoint()]] three times:
*** immediately before [[API StartMoving|StartMoving()]], to get the initial offset relative-to-frame
*** immediately before {{api|Frame:StartMoving|t=w}}(), to get the initial offset relative-to-frame
*** immediately after [[API StartMoving|StartMoving()]], to get the initial offset relative-to-screen
*** immediately after {{api|Frame:StartMoving|t=w}}(), to get the initial offset relative-to-screen
*** immediately before StopMovingOrSizing(), to get the final offset relative-to-screen, but before the anchor points are (potentially) changed
*** immediately before StopMovingOrSizing(), to get the final offset relative-to-screen, but before the anchor points are (potentially) changed
**This way, you can subtract the second measurement from the third to get a "delta" (x,y) for the total movement, and then add that to the first measurement to get the appropriate final offset relative-to-frame.  You can then manually re-anchor your frame to its appropriate parent, at its new offset -- but you must do so after calling StopMovingOrSizing() (and [[API ClearAllPoints|ClearAllPoints()]]).
**This way, you can subtract the second measurement from the third to get a "delta" (x,y) for the total movement, and then add that to the first measurement to get the appropriate final offset relative-to-frame.  You can then manually re-anchor your frame to its appropriate parent, at its new offset -- but you must do so after calling StopMovingOrSizing(), and {{api|Frame:ClearAllPoints|t=w}}().

Revision as of 05:11, 15 February 2015

Widget API ← Frame < StopMovingOrSizing

Stops a frame movement or resize that was started with Frame:StartMoving() or Frame:StartSizing().

obj:StopMovingOrSizing()

Arguments
nil

Returns
nil

Example
myAddonFrame:StopMovingOrSizing();
Result
The frame named 'myAddonFrame' would stop moving or resizing in relation to where the mouse is being moved.
The frame's anchor will be changed; see below for details.

Description
  • Stops the frame-based object from moving or resizing in relation to where the mouse is being moved -- this would have been started with Frame:StartMoving() or Frame:StartSizing().
  • Use Frame:RegisterForDrag() and the <OnDragStart>...</OnDragStart> event to allow your frame-based object to be moved or resized by the user.
  • Use this function inside the <OnDragStop>...</OnDragStop> XML section to stop the moving or resizing process.
  • For pixel-precise movements, you should instead use Frame:EnableMouse() and the <OnMouseDown>...</OnMouseDown> and <OnMouseUp>...</OnMouseUp> events (and probably also the <OnHide>...</OnHide> event).
Notes
  • If the frame becomes stuck by any cause (see SetClampedToScreen()), the mouse and the frame will go out-of-sync.
  • This function together with Frame:StartMoving() exhibit some "special" behavior that can cause problems when used with frames that are not anchored to UIParent (or some other full-screen frame).
    • Immediately upon calling Frame:StartMoving(), the frame will be de-anchored from any other frame it was previously anchored to, and instead anchored to the screen. For example, if MyFrame's TOPLEFT is anchored to MyParent's TOPLEFT at (5,-5), and MyParent's TOPLEFT is anchored to UIParent's TOPLEFT at (100,-100), then MyFrame:StartMoving() immediately re-anchors MyFrame's TOPLEFT to the screen's (nil anchor) TOPLEFT at (105,-105). The original anchor frame (MyParent) and offset will not be restored by StopMovingOrSizing().
    • Furthermore, StopMovingOrSizing() will identify the closest anchor point on the screen and re-anchor the frame once again to that closest point. For example, if MyFrame is dragged to (50,-600) (still relative to the screen), and has a height of 25, then MyFrame:StopMovingOrSizing() immediately re-anchors MyFrame's BOTTOMLEFT to the screen's BOTTOMLEFT at (50,143) (recall that the WoW UI always has height 768 regardless of resolution).
    • There does not appear to be any way to disable either of these behaviors. If you want your frame to end up anchored to the same frame it was anchored to initially, one way to work around this issue is to store the result of GetPoint() three times:
      • immediately before Frame:StartMoving(), to get the initial offset relative-to-frame
      • immediately after Frame:StartMoving(), to get the initial offset relative-to-screen
      • immediately before StopMovingOrSizing(), to get the final offset relative-to-screen, but before the anchor points are (potentially) changed
    • This way, you can subtract the second measurement from the third to get a "delta" (x,y) for the total movement, and then add that to the first measurement to get the appropriate final offset relative-to-frame. You can then manually re-anchor your frame to its appropriate parent, at its new offset -- but you must do so after calling StopMovingOrSizing(), and Frame:ClearAllPoints().