]> gitweb.factorcode.org Git - factor.git/commitdiff
magic scrollers hide sliders when not needed
authorSam Anklesaria <sam@Tintin.local>
Thu, 6 Aug 2009 20:20:10 +0000 (15:20 -0500)
committerSam Anklesaria <sam@Tintin.local>
Thu, 6 Aug 2009 20:20:10 +0000 (15:20 -0500)
extra/models/conditional/authors.txt [new file with mode: 0644]
extra/models/conditional/conditional.factor [new file with mode: 0644]
extra/ui/gadgets/magic-scrollers/authors.txt [new file with mode: 0644]
extra/ui/gadgets/magic-scrollers/magic-scrollers.factor [new file with mode: 0644]

diff --git a/extra/models/conditional/authors.txt b/extra/models/conditional/authors.txt
new file mode 100644 (file)
index 0000000..ce0899f
--- /dev/null
@@ -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 (file)
index 0000000..37cf3d1
--- /dev/null
@@ -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) ;
+
+: <conditional> ( 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 (file)
index 0000000..ce0899f
--- /dev/null
@@ -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 (file)
index 0000000..5334497
--- /dev/null
@@ -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 ;
+: <magic-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 ;
+: <magic-scroller> ( gadget -- scroller ) magic-scroller new-scroller ;
+M: magic-scroller (build-children) <magic-slider> ;
\ No newline at end of file