]> gitweb.factorcode.org Git - factor-unmaintained.git/blobdiff - ui/gadgets/comboboxes/comboboxes.factor
unmaintained: New home for misfit Factor vocabularies.
[factor-unmaintained.git] / ui / gadgets / comboboxes / comboboxes.factor
diff --git a/ui/gadgets/comboboxes/comboboxes.factor b/ui/gadgets/comboboxes/comboboxes.factor
new file mode 100644 (file)
index 0000000..a2a7585
--- /dev/null
@@ -0,0 +1,22 @@
+USING: accessors arrays kernel math.rectangles sequences
+ui.gadgets.controls models.combinators ui.gadgets ui.gadgets.glass
+ui.gadgets.labels ui.gestures ;
+QUALIFIED-WITH: ui.gadgets.tables tbl
+IN: ui.gadgets.comboboxes
+
+TUPLE: combo-table < table spawner ;
+
+M: combo-table handle-gesture [ call-next-method drop ] 2keep swap
+   T{ button-up } = [
+      [ spawner>> ]
+      [ tbl:selected-row [ swap set-control-value ] [ 2drop ] if ]
+      [ hide-glass ] tri
+   ] [ drop ] if t ;
+
+TUPLE: combobox < label-control table ;
+combobox H{
+   { T{ button-down } [ dup table>> over >>spawner <zero-rect> show-glass ] }
+} set-gestures
+
+: <combobox> ( options -- combobox ) [ first [ combobox new-label ] keep <basic> >>model ] keep
+    <basic> combo-table new-table [ 1array ] >>quot >>table ;