Skip to content

Commit

Permalink
Fixed bug in xyz-panel example where widget moved wasn't very smooth.
Browse files Browse the repository at this point in the history
This exposed an issue with the drag delta calculation which isn't
tolerant of widgets moving around underneath it.
  • Loading branch information
daveray committed May 20, 2012
1 parent 0af4c98 commit 37ebd9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/seesaw/behave.clj
Expand Up @@ -71,6 +71,8 @@
:mouse-dragged
(fn [^java.awt.event.MouseEvent e]
(let [p (.getPoint e)]
; TODO the delta reported here is incorrect if the widget is
; programmatically moved during the callback. See xyz-panel test.
(drag e [(- (.x p) (.x last-point)) (- (.y p) (.y last-point))])
(.setLocation last-point (.getPoint e))))
:mouse-released
Expand Down
19 changes: 14 additions & 5 deletions test/seesaw/test/examples/xyz_panel.clj
Expand Up @@ -16,11 +16,20 @@

; Put in some basic support for moving w around using behave/when-mouse-dragged.
(defn movable [w]
(when-mouse-dragged w
; When the mouse is pressed, move the widget to the front of the z order
:start #(move! % :to-front)
; When the mouse is dragged move the widget
:drag #(move! %1 :by %2))
(let [start-point (java.awt.Point.)]
(when-mouse-dragged w
; When the mouse is pressed, move the widget to the front of the z order
:start (fn [e]
(move! e :to-front)
(.setLocation start-point (.getPoint e)))
; When the mouse is dragged move the widget
; Unfortunately, the delta passed to this function doesn't work correctly
; if the widget is moved during the drag. So, the move is calculated
; manually.
:drag (fn [e _]
(let [p (.getPoint e)]
(move! e :by [(- (.x p) (.x start-point))
(- (.y p) (.y start-point))])))))
w)

(defn make-label
Expand Down

0 comments on commit 37ebd9b

Please sign in to comment.