adding view-width and view-height methods
This commit is contained in:
parent
f6cc08afa9
commit
fa36b9c3c5
|
@ -11,8 +11,6 @@
|
||||||
;; The world consists of a set of boxes.
|
;; The world consists of a set of boxes.
|
||||||
;;
|
;;
|
||||||
;; A box has an id and a position.
|
;; A box has an id and a position.
|
||||||
|
|
||||||
(define-struct world (boxes))
|
|
||||||
(define-struct box (id x y))
|
(define-struct box (id x y))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,13 @@
|
||||||
|
|
||||||
;; A small drag-and-drop example using the web-world library.
|
;; A small drag-and-drop example using the web-world library.
|
||||||
;;
|
;;
|
||||||
;; The world consists of a set of boxes.
|
;; The world consists of a set of boxes. It also has a reference
|
||||||
;;
|
;; to the currently dragged box, if one is being dragged.
|
||||||
;; A box has an id and a position.
|
(define-struct world (boxes ;; (listof box)
|
||||||
|
dragged ;; (U box #f)
|
||||||
|
))
|
||||||
|
|
||||||
(define-struct world (boxes))
|
;; A box has an id and a position.
|
||||||
(define-struct box (id x y))
|
(define-struct box (id x y))
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,10 +23,11 @@
|
||||||
;; Given a world, creates a new world within the boundaries of the playground.
|
;; Given a world, creates a new world within the boundaries of the playground.
|
||||||
(define (add-fresh-box w v)
|
(define (add-fresh-box w v)
|
||||||
(define-values (max-width max-height) (width-and-height "playground"))
|
(define-values (max-width max-height) (width-and-height "playground"))
|
||||||
(define new-world (cons (make-box (fresh-id)
|
(define new-world (make-world (cons (make-box (fresh-id)
|
||||||
(random max-width)
|
(random max-width)
|
||||||
(random max-height))
|
(random max-height))
|
||||||
w))
|
(world-boxes w))
|
||||||
|
(world-dragged w)))
|
||||||
new-world)
|
new-world)
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,14 +52,24 @@
|
||||||
(box-y a-box))))
|
(box-y a-box))))
|
||||||
"box")))]))
|
"box")))]))
|
||||||
(view-focus v "playground")
|
(view-focus v "playground")
|
||||||
w))
|
(world-boxes w)))
|
||||||
|
|
||||||
|
|
||||||
|
;; When the mouse is down, we see if the event intersects any of our boxes.
|
||||||
|
(define (mousedown w v evt)
|
||||||
|
...)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(define the-view (view-bind-many view.html
|
(define the-view (view-bind-many view.html
|
||||||
["add" "click" add-fresh-box]))
|
["add" "click" add-fresh-box]
|
||||||
|
["playground" "mousedown" mousedown]
|
||||||
|
["playground" "mousemove" mousemove]
|
||||||
|
["playground" "mouseup" mouseup]))
|
||||||
|
|
||||||
(big-bang (list)
|
(big-bang (make-world (list) #f)
|
||||||
(initial-view the-view)
|
(initial-view the-view)
|
||||||
(to-draw draw))
|
(to-draw draw))
|
||||||
|
|
|
@ -1043,6 +1043,14 @@ Update the attribute @racket[name] with the value @racket[value] at the focus.
|
||||||
Remove the attribute @racket[name] at the focus.
|
Remove the attribute @racket[name] at the focus.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@defproc[(view-width [v view]) number]{
|
||||||
|
Get the width at the focus.
|
||||||
|
}
|
||||||
|
|
||||||
|
@defproc[(view-height [v view]) number]{
|
||||||
|
Get the height at the focus.
|
||||||
|
}
|
||||||
|
|
||||||
@defproc[(view-css [v view] [name String]) view]{
|
@defproc[(view-css [v view] [name String]) view]{
|
||||||
Get the css value @racket[name] at the focus.
|
Get the css value @racket[name] at the focus.
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,9 @@
|
||||||
|
|
||||||
view-css
|
view-css
|
||||||
update-view-css
|
update-view-css
|
||||||
|
|
||||||
|
view-width
|
||||||
|
view-height
|
||||||
|
|
||||||
view-id
|
view-id
|
||||||
|
|
||||||
|
|
|
@ -307,6 +307,14 @@
|
||||||
return $(this.getCursor().node[0]).css(name);
|
return $(this.getCursor().node[0]).css(name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MockView.prototype.getWidth = function(name) {
|
||||||
|
return $(this.getCursor().node[0]).width();
|
||||||
|
};
|
||||||
|
|
||||||
|
MockView.prototype.getHeight = function(name) {
|
||||||
|
return $(this.getCursor().node[0]).height();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
MockView.prototype.updateCss = function(name, value) {
|
MockView.prototype.updateCss = function(name, value) {
|
||||||
return this.act(
|
return this.act(
|
||||||
|
@ -2018,6 +2026,20 @@
|
||||||
return view.getCss(name);
|
return view.getCss(name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EXPORTS['view-width'] = makePrimitiveProcedure(
|
||||||
|
'view-width',
|
||||||
|
1,
|
||||||
|
function(MACHINE) {
|
||||||
|
var view = checkMockViewOnElement(MACHINE, 'view-width', 0);
|
||||||
|
return view.getWidth();
|
||||||
|
});
|
||||||
|
EXPORTS['view-height'] = makePrimitiveProcedure(
|
||||||
|
'view-height',
|
||||||
|
1,
|
||||||
|
function(MACHINE) {
|
||||||
|
var view = checkMockViewOnElement(MACHINE, 'view-height', 0);
|
||||||
|
return view.getHeight();
|
||||||
|
});
|
||||||
|
|
||||||
EXPORTS['update-view-css'] = makePrimitiveProcedure(
|
EXPORTS['update-view-css'] = makePrimitiveProcedure(
|
||||||
'update-view-css',
|
'update-view-css',
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
view-text update-view-text
|
view-text update-view-text
|
||||||
view-attr view-has-attr? update-view-attr remove-view-attr
|
view-attr view-has-attr? update-view-attr remove-view-attr
|
||||||
view-css update-view-css
|
view-css update-view-css
|
||||||
|
view-width view-height
|
||||||
view-id
|
view-id
|
||||||
|
|
||||||
view-bind
|
view-bind
|
||||||
|
@ -163,6 +164,12 @@
|
||||||
(define (view-css v attr-name)
|
(define (view-css v attr-name)
|
||||||
(error 'view-css "Please run in JavaScript context."))
|
(error 'view-css "Please run in JavaScript context."))
|
||||||
|
|
||||||
|
(define (view-width v)
|
||||||
|
(error 'view-width "Please run in JavaScript context."))
|
||||||
|
|
||||||
|
(define (view-height v)
|
||||||
|
(error 'view-height "Please run in JavaScript context."))
|
||||||
|
|
||||||
(define (update-view-css v attr-name value)
|
(define (update-view-css v attr-name value)
|
||||||
(error 'update-view-css "Please run in JavaScript context."))
|
(error 'update-view-css "Please run in JavaScript context."))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user