From df371bd8bbb45937d66300f1a53b9bae20fed66b Mon Sep 17 00:00:00 2001 From: Sam Anklesaria Date: Thu, 6 Aug 2009 15:20:10 -0500 Subject: [PATCH] magic scrollers hide sliders when not needed --- extra/models/conditional/authors.txt | 1 + extra/models/conditional/conditional.factor | 21 +++++++++++++++++++ extra/ui/gadgets/magic-scrollers/authors.txt | 1 + .../magic-scrollers/magic-scrollers.factor | 21 +++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 extra/models/conditional/authors.txt create mode 100644 extra/models/conditional/conditional.factor create mode 100644 extra/ui/gadgets/magic-scrollers/authors.txt create mode 100644 extra/ui/gadgets/magic-scrollers/magic-scrollers.factor diff --git a/extra/models/conditional/authors.txt b/extra/models/conditional/authors.txt new file mode 100644 index 0000000000..ce0899f16e --- /dev/null +++ b/extra/models/conditional/authors.txt @@ -0,0 +1 @@ +Sam Anklesaria \ No newline at end of file diff --git a/extra/models/conditional/conditional.factor b/extra/models/conditional/conditional.factor new file mode 100644 index 0000000000..37cf3d115e --- /dev/null +++ b/extra/models/conditional/conditional.factor @@ -0,0 +1,21 @@ +! Copyright (C) 2009 Sam Anklesaria. +! See http://factorcode.org/license.txt for BSD license. +USING: arrays accessors kernel models threads calendar ; +IN: models.conditional + +TUPLE: conditional < model condition thread ; + +M: conditional model-changed + [ + [ dup + [ condition>> call( -- ? ) ] + [ thread>> self = not ] bi or + [ [ value>> ] dip set-model f ] + [ 2drop t ] if 100 milliseconds sleep + ] 2curry "models.conditional" spawn-server + ] keep (>>thread) ; + +: ( condition -- model ) + f conditional new-model swap >>condition ; + +M: conditional model-activated [ model>> ] keep model-changed ; \ No newline at end of file diff --git a/extra/ui/gadgets/magic-scrollers/authors.txt b/extra/ui/gadgets/magic-scrollers/authors.txt new file mode 100644 index 0000000000..ce0899f16e --- /dev/null +++ b/extra/ui/gadgets/magic-scrollers/authors.txt @@ -0,0 +1 @@ +Sam Anklesaria \ No newline at end of file diff --git a/extra/ui/gadgets/magic-scrollers/magic-scrollers.factor b/extra/ui/gadgets/magic-scrollers/magic-scrollers.factor new file mode 100644 index 0000000000..53344979c4 --- /dev/null +++ b/extra/ui/gadgets/magic-scrollers/magic-scrollers.factor @@ -0,0 +1,21 @@ +! Copyright (C) 2009 Sam Anklesaria. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors combinators kernel math models sequences +ui.gadgets ui.gadgets.scrollers ui.gadgets.sliders ; +IN: ui.gadgets.magic-scrollers + +TUPLE: magic-slider < slider ; +: ( range orientation -- slider ) magic-slider new-slider ; +: get-dim ( orientation dims -- dim ) + swap { + { horizontal [ first ] } + { vertical [ second ] } + } case ; + +! do this with pref-dim*, not draw-gadget +M: magic-slider model-changed [ call-next-method ] 2keep swap value>> + [ second ] [ fourth ] bi < [ show-gadget ] [ hide-gadget ] if ; + +TUPLE: magic-scroller < scroller ; +: ( gadget -- scroller ) magic-scroller new-scroller ; +M: magic-scroller (build-children) ; \ No newline at end of file