]> gitweb.factorcode.org Git - factor.git/commitdiff
Line gadgets now support min/max rows/cols; this obsoletes limited-scroller
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 15 Feb 2009 10:01:57 +0000 (04:01 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 15 Feb 2009 10:01:57 +0000 (04:01 -0600)
basis/math/rectangles/rectangles.factor
basis/ui/gadgets/editors/editors-tests.factor
basis/ui/gadgets/editors/editors.factor
basis/ui/gadgets/line-support/line-support.factor
basis/ui/gadgets/tables/tables.factor
basis/ui/tools/listener/completion/completion.factor

index d3ada2951c3ba4e4858e64e2e74a9eb64e3c6b18..d1bfad6ec7dea6e4ca57eff6290170aabc9085b8 100644 (file)
@@ -48,3 +48,6 @@ M: rect contains-point?
 : rect-containing ( points -- rect )
     [ vsupremum ] [ vinfimum ] bi
     [ nip ] [ v- ] 2bi <rect> ;
+
+: rect-min ( rect dim -- rect' )
+    [ rect-bounds ] dip vmin <rect> ;
\ No newline at end of file
index daaacacba76d1811ad4879b28c2eaaa6719fdf69..ec2f39f00954b7b2b56eca6799c16190993a6c07 100644 (file)
@@ -1,7 +1,7 @@
 USING: accessors ui.gadgets.editors tools.test kernel io
 io.streams.plain definitions namespaces ui.gadgets
 ui.gadgets.grids prettyprint documents ui.gestures tools.test.ui
-models documents.elements ;
+models documents.elements ui.gadgets.scrollers sequences ;
 IN: ui.gadgets.editors.tests
 
 [ "foo bar" ] [
@@ -55,4 +55,6 @@ IN: ui.gadgets.editors.tests
 
 [ ] [ <editor> com-join-lines ] unit-test
 [ ] [ <editor> "A" over set-editor-string com-join-lines ] unit-test
-[ "A B" ] [ <editor> "A\nB" over set-editor-string [ com-join-lines ] [ editor-string ] bi ] unit-test
\ No newline at end of file
+[ "A B" ] [ <editor> "A\nB" over set-editor-string [ com-join-lines ] [ editor-string ] bi ] unit-test
+
+[ 2 ] [ <editor> 20 >>min-rows 20 >>min-cols pref-viewport-dim length ] unit-test
\ No newline at end of file
index d6dcf32f73de9ac33fd08858d5858357851c6611..7724e262aeaa4072319e6e48ff4d627adbc706ef 100755 (executable)
@@ -11,8 +11,8 @@ ui.pens.solid ui.gadgets.line-support ui.text ui.gestures
 math.rectangles splitting unicode.categories fonts grouping ;
 IN: ui.gadgets.editors
 
-TUPLE: editor < gadget
-font caret-color selection-color
+TUPLE: editor < line-gadget
+caret-color
 caret mark
 focused? blink blink-alarm ;
 
@@ -24,11 +24,10 @@ focused? blink blink-alarm ;
 
 : editor-theme ( editor -- editor )
     COLOR: red >>caret-color
-    selection-color >>selection-color
     monospace-font >>font ; inline
 
 : new-editor ( class -- editor )
-    new-gadget
+    new-line-gadget
         <document> >>model
         init-editor-locs
         editor-theme ; inline
index 0aacf9445ad8bd0e13b953de312e1bc5f0467a0e..4e1c3ecf4df9e7ffa92dea1466645ad8a1a76395 100644 (file)
@@ -2,19 +2,26 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays combinators fry kernel math math.functions math.order
 math.ranges math.vectors namespaces opengl sequences ui.gadgets
-ui.render ui.text ;
+ui.render ui.text ui.gadgets.theme ui.gadgets.scrollers ;
 IN: ui.gadgets.line-support
 
 ! Some code shared by table and editor gadgets
-SLOT: font
+TUPLE: line-gadget < gadget
+font selection-color
+min-rows max-rows
+min-cols max-cols ;
+
+: new-line-gadget ( class -- gadget )
+    new
+        selection-color >>selection-color ;
 
 GENERIC: line-leading ( gadget -- n )
 
-M: gadget line-leading font>> font-metrics leading>> ;
+M: line-gadget line-leading font>> font-metrics leading>> ;
 
 GENERIC: line-height ( gadget -- n )
 
-M: gadget line-height font>> font-metrics height>> ;
+M: line-gadget line-height font>> font-metrics height>> ;
 
 : y>line ( y gadget -- n ) line-height /i ;
 
@@ -50,4 +57,24 @@ GENERIC: draw-line ( line index gadget -- )
     } cleave '[
         0 over _ * >integer 2array
         [ _ draw-line ] with-translation
-    ] each-slice-index ;
\ No newline at end of file
+    ] each-slice-index ;
+
+<PRIVATE
+
+: clamp ( dim unit min max -- dim' )
+    [ -1/0. or * ] [ 1/.0 or * ] bi-curry* bi
+    [ max ] [ min ] bi* ;
+
+: line-gadget-width ( pref-dim gadget -- w )
+    [ first ] [ [ font>> "m" text-width ] [ min-cols>> ] [ max-cols>> ] tri ] bi* clamp ;
+
+: line-gadget-height ( pref-dim gadget -- h )
+    [ second ] [ [ line-height ] [ min-rows>> ] [ max-rows>> ] tri ] bi* clamp ;
+
+PRIVATE>
+
+M: line-gadget pref-viewport-dim
+    [ pref-dim ] keep
+    [ line-gadget-width ]
+    [ line-gadget-height ]
+    2bi 2array ;
\ No newline at end of file
index fd921484e1920ce59a325a7170cb7a750d4b150c..cea714c658a97611596b7abbed1b38c9638aafa9 100644 (file)
@@ -21,7 +21,7 @@ M: object prototype-row drop { "" } ;
 M: object row-value drop ;
 M: object row-color 2drop f ;
 
-TUPLE: table < gadget
+TUPLE: table < line-gadget
 { renderer initial: trivial-renderer }
 filled-column column-alignment
 { action initial: [ drop ] }
@@ -29,7 +29,7 @@ single-click?
 { hook initial: [ ] }
 { gap initial: 6 }
 column-widths total-width
-font selection-color focus-border-color
+focus-border-color
 { mouse-color initial: COLOR: black }
 { column-line-color initial: COLOR: dark-gray }
 selection-required?
@@ -38,11 +38,10 @@ mouse-index
 focused? ;
 
 : <table> ( rows -- table )
-    table new-gadget
+    table new-line-gadget
         swap >>model
         f <model> >>selected-value
         sans-serif-font >>font
-        selection-color >>selection-color
         focus-border-color >>focus-border-color ;
 
 <PRIVATE
index 867a367655394a5194c2293f1d0d00c3484f320d..cef1e9ab87cb0db02d6e8f66e862c5f2b5ed045a 100644 (file)
@@ -50,11 +50,6 @@ M: vocab-completion completion-banner drop "Vocabularies" ;
 M: char-completion completion-banner drop "Unicode code point names" ;
 M: history-completion completion-banner drop "Input history" ;
 
-GENERIC: completion-popup-width ( interactor completion-mode -- x )
-
-M: object completion-popup-width 2drop 300 ;
-M: history-completion completion-popup-width drop dim>> first ;
-
 ! Completion modes also implement the row renderer protocol
 M: listener-completion row-columns drop present 1array ;
 
@@ -148,13 +143,12 @@ GENERIC# accept-completion-hook 1 ( item popup -- )
         t >>single-click?
         transparent >>column-line-color
         2 >>gap
+        10 >>min-cols
+        10 >>max-rows
         dup '[ _ accept-completion ] >>action ;
 
 : <completion-scroller> ( completion-popup -- scroller )
-    [ table>> ] [ interactor>> ] [ completion-mode>> ] tri completion-popup-width
-    [ <limited-scroller> ] [ 120 2array ] bi*
-    [ >>min-dim ] [ >>max-dim ] bi
-    COLOR: white <solid> >>interior ;
+    table>> <scroller> COLOR: white <solid> >>interior ;
 
 : <completion-popup> ( interactor completion-mode -- popup )
     [ vertical completion-popup new-track ] 2dip