Line gadgets now support min/max rows/cols; this obsoletes limited-scroller
parent
074e3238f3
commit
f8ab4be9da
|
@ -48,3 +48,6 @@ M: rect contains-point?
|
||||||
: rect-containing ( points -- rect )
|
: rect-containing ( points -- rect )
|
||||||
[ vsupremum ] [ vinfimum ] bi
|
[ vsupremum ] [ vinfimum ] bi
|
||||||
[ nip ] [ v- ] 2bi <rect> ;
|
[ nip ] [ v- ] 2bi <rect> ;
|
||||||
|
|
||||||
|
: rect-min ( rect dim -- rect' )
|
||||||
|
[ rect-bounds ] dip vmin <rect> ;
|
|
@ -1,7 +1,7 @@
|
||||||
USING: accessors ui.gadgets.editors tools.test kernel io
|
USING: accessors ui.gadgets.editors tools.test kernel io
|
||||||
io.streams.plain definitions namespaces ui.gadgets
|
io.streams.plain definitions namespaces ui.gadgets
|
||||||
ui.gadgets.grids prettyprint documents ui.gestures tools.test.ui
|
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
|
IN: ui.gadgets.editors.tests
|
||||||
|
|
||||||
[ "foo bar" ] [
|
[ "foo bar" ] [
|
||||||
|
@ -55,4 +55,6 @@ IN: ui.gadgets.editors.tests
|
||||||
|
|
||||||
[ ] [ <editor> com-join-lines ] unit-test
|
[ ] [ <editor> com-join-lines ] unit-test
|
||||||
[ ] [ <editor> "A" over set-editor-string 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
|
[ "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
|
|
@ -11,8 +11,8 @@ ui.pens.solid ui.gadgets.line-support ui.text ui.gestures
|
||||||
math.rectangles splitting unicode.categories fonts grouping ;
|
math.rectangles splitting unicode.categories fonts grouping ;
|
||||||
IN: ui.gadgets.editors
|
IN: ui.gadgets.editors
|
||||||
|
|
||||||
TUPLE: editor < gadget
|
TUPLE: editor < line-gadget
|
||||||
font caret-color selection-color
|
caret-color
|
||||||
caret mark
|
caret mark
|
||||||
focused? blink blink-alarm ;
|
focused? blink blink-alarm ;
|
||||||
|
|
||||||
|
@ -24,11 +24,10 @@ focused? blink blink-alarm ;
|
||||||
|
|
||||||
: editor-theme ( editor -- editor )
|
: editor-theme ( editor -- editor )
|
||||||
COLOR: red >>caret-color
|
COLOR: red >>caret-color
|
||||||
selection-color >>selection-color
|
|
||||||
monospace-font >>font ; inline
|
monospace-font >>font ; inline
|
||||||
|
|
||||||
: new-editor ( class -- editor )
|
: new-editor ( class -- editor )
|
||||||
new-gadget
|
new-line-gadget
|
||||||
<document> >>model
|
<document> >>model
|
||||||
init-editor-locs
|
init-editor-locs
|
||||||
editor-theme ; inline
|
editor-theme ; inline
|
||||||
|
|
|
@ -2,19 +2,26 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays combinators fry kernel math math.functions math.order
|
USING: accessors arrays combinators fry kernel math math.functions math.order
|
||||||
math.ranges math.vectors namespaces opengl sequences ui.gadgets
|
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
|
IN: ui.gadgets.line-support
|
||||||
|
|
||||||
! Some code shared by table and editor gadgets
|
! 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 )
|
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 )
|
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 ;
|
: y>line ( y gadget -- n ) line-height /i ;
|
||||||
|
|
||||||
|
@ -50,4 +57,24 @@ GENERIC: draw-line ( line index gadget -- )
|
||||||
} cleave '[
|
} cleave '[
|
||||||
0 over _ * >integer 2array
|
0 over _ * >integer 2array
|
||||||
[ _ draw-line ] with-translation
|
[ _ draw-line ] with-translation
|
||||||
] each-slice-index ;
|
] 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 ;
|
|
@ -21,7 +21,7 @@ M: object prototype-row drop { "" } ;
|
||||||
M: object row-value drop ;
|
M: object row-value drop ;
|
||||||
M: object row-color 2drop f ;
|
M: object row-color 2drop f ;
|
||||||
|
|
||||||
TUPLE: table < gadget
|
TUPLE: table < line-gadget
|
||||||
{ renderer initial: trivial-renderer }
|
{ renderer initial: trivial-renderer }
|
||||||
filled-column column-alignment
|
filled-column column-alignment
|
||||||
{ action initial: [ drop ] }
|
{ action initial: [ drop ] }
|
||||||
|
@ -29,7 +29,7 @@ single-click?
|
||||||
{ hook initial: [ ] }
|
{ hook initial: [ ] }
|
||||||
{ gap initial: 6 }
|
{ gap initial: 6 }
|
||||||
column-widths total-width
|
column-widths total-width
|
||||||
font selection-color focus-border-color
|
focus-border-color
|
||||||
{ mouse-color initial: COLOR: black }
|
{ mouse-color initial: COLOR: black }
|
||||||
{ column-line-color initial: COLOR: dark-gray }
|
{ column-line-color initial: COLOR: dark-gray }
|
||||||
selection-required?
|
selection-required?
|
||||||
|
@ -38,11 +38,10 @@ mouse-index
|
||||||
focused? ;
|
focused? ;
|
||||||
|
|
||||||
: <table> ( rows -- table )
|
: <table> ( rows -- table )
|
||||||
table new-gadget
|
table new-line-gadget
|
||||||
swap >>model
|
swap >>model
|
||||||
f <model> >>selected-value
|
f <model> >>selected-value
|
||||||
sans-serif-font >>font
|
sans-serif-font >>font
|
||||||
selection-color >>selection-color
|
|
||||||
focus-border-color >>focus-border-color ;
|
focus-border-color >>focus-border-color ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
|
@ -50,11 +50,6 @@ M: vocab-completion completion-banner drop "Vocabularies" ;
|
||||||
M: char-completion completion-banner drop "Unicode code point names" ;
|
M: char-completion completion-banner drop "Unicode code point names" ;
|
||||||
M: history-completion completion-banner drop "Input history" ;
|
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
|
! Completion modes also implement the row renderer protocol
|
||||||
M: listener-completion row-columns drop present 1array ;
|
M: listener-completion row-columns drop present 1array ;
|
||||||
|
|
||||||
|
@ -148,13 +143,12 @@ GENERIC# accept-completion-hook 1 ( item popup -- )
|
||||||
t >>single-click?
|
t >>single-click?
|
||||||
transparent >>column-line-color
|
transparent >>column-line-color
|
||||||
2 >>gap
|
2 >>gap
|
||||||
|
10 >>min-cols
|
||||||
|
10 >>max-rows
|
||||||
dup '[ _ accept-completion ] >>action ;
|
dup '[ _ accept-completion ] >>action ;
|
||||||
|
|
||||||
: <completion-scroller> ( completion-popup -- scroller )
|
: <completion-scroller> ( completion-popup -- scroller )
|
||||||
[ table>> ] [ interactor>> ] [ completion-mode>> ] tri completion-popup-width
|
table>> <scroller> COLOR: white <solid> >>interior ;
|
||||||
[ <limited-scroller> ] [ 120 2array ] bi*
|
|
||||||
[ >>min-dim ] [ >>max-dim ] bi
|
|
||||||
COLOR: white <solid> >>interior ;
|
|
||||||
|
|
||||||
: <completion-popup> ( interactor completion-mode -- popup )
|
: <completion-popup> ( interactor completion-mode -- popup )
|
||||||
[ vertical completion-popup new-track ] 2dip
|
[ vertical completion-popup new-track ] 2dip
|
||||||
|
|
Loading…
Reference in New Issue