From f8ab4be9daae031133078d47646ab192be616c4b Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 15 Feb 2009 04:01:57 -0600 Subject: [PATCH] Line gadgets now support min/max rows/cols; this obsoletes limited-scroller --- basis/math/rectangles/rectangles.factor | 3 ++ basis/ui/gadgets/editors/editors-tests.factor | 6 ++- basis/ui/gadgets/editors/editors.factor | 7 ++-- .../gadgets/line-support/line-support.factor | 37 ++++++++++++++++--- basis/ui/gadgets/tables/tables.factor | 7 ++-- .../listener/completion/completion.factor | 12 ++---- 6 files changed, 48 insertions(+), 24 deletions(-) diff --git a/basis/math/rectangles/rectangles.factor b/basis/math/rectangles/rectangles.factor index d3ada2951c..d1bfad6ec7 100644 --- a/basis/math/rectangles/rectangles.factor +++ b/basis/math/rectangles/rectangles.factor @@ -48,3 +48,6 @@ M: rect contains-point? : rect-containing ( points -- rect ) [ vsupremum ] [ vinfimum ] bi [ nip ] [ v- ] 2bi ; + +: rect-min ( rect dim -- rect' ) + [ rect-bounds ] dip vmin ; \ No newline at end of file diff --git a/basis/ui/gadgets/editors/editors-tests.factor b/basis/ui/gadgets/editors/editors-tests.factor index daaacacba7..ec2f39f009 100644 --- a/basis/ui/gadgets/editors/editors-tests.factor +++ b/basis/ui/gadgets/editors/editors-tests.factor @@ -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 [ ] [ com-join-lines ] unit-test [ ] [ "A" over set-editor-string com-join-lines ] unit-test -[ "A B" ] [ "A\nB" over set-editor-string [ com-join-lines ] [ editor-string ] bi ] unit-test \ No newline at end of file +[ "A B" ] [ "A\nB" over set-editor-string [ com-join-lines ] [ editor-string ] bi ] unit-test + +[ 2 ] [ 20 >>min-rows 20 >>min-cols pref-viewport-dim length ] unit-test \ No newline at end of file diff --git a/basis/ui/gadgets/editors/editors.factor b/basis/ui/gadgets/editors/editors.factor index d6dcf32f73..7724e262ae 100755 --- a/basis/ui/gadgets/editors/editors.factor +++ b/basis/ui/gadgets/editors/editors.factor @@ -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 >>model init-editor-locs editor-theme ; inline diff --git a/basis/ui/gadgets/line-support/line-support.factor b/basis/ui/gadgets/line-support/line-support.factor index 0aacf9445a..4e1c3ecf4d 100644 --- a/basis/ui/gadgets/line-support/line-support.factor +++ b/basis/ui/gadgets/line-support/line-support.factor @@ -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 ; + +> "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 diff --git a/basis/ui/gadgets/tables/tables.factor b/basis/ui/gadgets/tables/tables.factor index fd921484e1..cea714c658 100644 --- a/basis/ui/gadgets/tables/tables.factor +++ b/basis/ui/gadgets/tables/tables.factor @@ -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? ; : ( rows -- table ) - table new-gadget + table new-line-gadget swap >>model f >>selected-value sans-serif-font >>font - selection-color >>selection-color focus-border-color >>focus-border-color ; > 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-popup -- scroller ) - [ table>> ] [ interactor>> ] [ completion-mode>> ] tri completion-popup-width - [ ] [ 120 2array ] bi* - [ >>min-dim ] [ >>max-dim ] bi - COLOR: white >>interior ; + table>> COLOR: white >>interior ; : ( interactor completion-mode -- popup ) [ vertical completion-popup new-track ] 2dip