diff --git a/extra/math/geometry/geometry.factor b/extra/math/geometry/geometry.factor new file mode 100644 index 0000000000..f70864aba3 --- /dev/null +++ b/extra/math/geometry/geometry.factor @@ -0,0 +1,8 @@ + +IN: math.geometry + +GENERIC: width ( object -- width ) +GENERIC: height ( object -- width ) + +GENERIC# set-x! 1 ( object x -- object ) +GENERIC# set-y! 1 ( object y -- object ) \ No newline at end of file diff --git a/extra/math/geometry/rect/rect.factor b/extra/math/geometry/rect/rect.factor index 51f42c22ca..d5b83e2715 100644 --- a/extra/math/geometry/rect/rect.factor +++ b/extra/math/geometry/rect/rect.factor @@ -1,13 +1,15 @@ -USING: kernel arrays math.vectors ; +USING: kernel arrays sequences math.vectors math.geometry accessors ; IN: math.geometry.rect -TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ; +TUPLE: rect loc dim ; -: ( -- rect ) rect new ; +: init-rect ( rect -- rect ) { 0 0 } clone >>loc { 0 0 } clone >>dim ; -C: rect +: ( loc dim -- rect ) rect boa ; + +: ( -- rect ) rect new init-rect ; M: array rect-loc ; @@ -40,3 +42,8 @@ M: array rect-dim drop { 0 0 } ; : rect-union ( rect1 rect2 -- newrect ) (rect-union) ; +M: rect width ( rect -- width ) dim>> first ; +M: rect height ( rect -- height ) dim>> second ; + +M: rect set-x! ( rect x -- rect ) over loc>> set-first ; +M: rect set-y! ( rect y -- rect ) over loc>> set-second ; diff --git a/extra/ui/gadgets/gadgets.factor b/extra/ui/gadgets/gadgets.factor index 0c2caebb3d..328d6eb749 100755 --- a/extra/ui/gadgets/gadgets.factor +++ b/extra/ui/gadgets/gadgets.factor @@ -27,11 +27,13 @@ M: gadget model-changed 2drop ; : nth-gadget ( n gadget -- child ) children>> nth ; -: new-gadget ( class -- gadget ) - new - { 0 1 } >>orientation - t >>visible? - { f f } >>graft-state ; inline +: init-gadget ( gadget -- gadget ) + init-rect + { 0 1 } >>orientation + t >>visible? + { f f } >>graft-state ; inline + +: new-gadget ( class -- gadget ) new init-gadget ; inline : ( -- gadget ) gadget new-gadget ;