Skip to content

Instantly share code, notes, and snippets.

@gchiu
Last active December 17, 2015 13:29
Show Gist options
  • Save gchiu/5617487 to your computer and use it in GitHub Desktop.
Save gchiu/5617487 to your computer and use it in GitHub Desktop.
create a draggable button - working version
Rebol [
file: %dragndrop.r3
title: "DragNdrop example"
author: "Graham Chiu"
date: 22-may-2013
purpose: "show how drag and drop works"
]
update-field-data: func [arg] [
set-face offset arg/delta + arg/base
set-face base arg/base
set-face delta arg/delta
]
stylize [
dragbutton: button [
about: "draggable button"
facets: [original-position: none]
actors: [
on-click: [; arg: event
focus face
; update info fields at top
set-face goboff face/gob/offset
if arg/type = 'down [
; save the starting positiong in our custom facet
set-facet face 'original-position face/gob/offset
; return the drag object which is then passed to the on-drag actor
return init-drag/only face arg/offset
]
do-face face
; docs says none needs to be returned but seems to work without it
none
]
on-offset: [ ; arg: offset
if all [arg get-facet face 'original-position] [
face/gob/offset: arg + get-facet face 'original-position
]
]
on-drag: [; arg: drag-object
; update our info fields
update-field-data arg
;show face/gob
do-actor face 'on-offset arg/delta ; arg/delta + arg/base
; update the face to show the new position
draw-face face
do-attached face
do-face face
]
on-drop: [
print "==========on drop"
probe arg
]
]
]
]
view [
hpanel [
label "Current: " current: field
label "Gob Offset: " goboff: field
label "Offset:" offset: field
label "Base: " base: field
label "Delta: " delta: field
]
scroll-panel [
pad 10x200
button "Where is dragbutton" on-action [set-face current db/gob/offset]
button "Send Dragbutton to home" on-action [db/gob/offset: 0x0 draw-face db]
db: dragbutton "DragMe" options [ show-mode: 'fixed ]
]
]
@gchiu
Copy link
Author

gchiu commented May 22, 2013

New version does not send button back to original position by preventing resizing with show-mode: 'fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment