: 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
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" ] [
[ ] [ <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
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 ;
: 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
! 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 ;
} 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
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 ] }
{ 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?
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
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 ;
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