]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.gadgets.*: updated docs and new tests
authorBjörn Lindqvist <bjourne@gmail.com>
Mon, 22 Aug 2016 03:25:06 +0000 (05:25 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Mon, 22 Aug 2016 12:22:28 +0000 (14:22 +0200)
As mentioned on the mailing list, the editor class doesn't have a color
slot.

basis/ui/gadgets/editors/editors-docs.factor
basis/ui/gadgets/line-support/line-support-docs.factor
basis/ui/gadgets/line-support/line-support-tests.factor
basis/ui/gadgets/line-support/line-support.factor

index ca6940c580559305177e9e3a35845a8be926e0de..59c76b610ebc2692e82c292543bb11ecbce32a0a 100644 (file)
@@ -1,21 +1,23 @@
-USING: documents help.markup help.syntax ui.gadgets
-ui.gadgets.scrollers models strings ui.commands sequences
-ui.text colors fonts help.tips ;
+USING: colors documents fonts help.markup help.syntax help.tips models
+sequences strings ui.commands ui.gadgets ui.gadgets.line-support
+ui.gadgets.scrollers ;
 IN: ui.gadgets.editors
 
+HELP: <multiline-editor>
+{ $values { "editor" multiline-editor } }
+{ $description "Creates a new multi-line editor gadget." } ;
+
 HELP: editor
 { $class-description "An editor is a control for editing a multi-line passage of text stored in a " { $link document } " model. Editors are crated by calling " { $link <editor> } "."
 $nl
 "Editors have the following slots:"
 { $list
-    { { $snippet "font" } " - a " { $link font } "." }
-    { { $snippet "color" } " - a " { $link color } "." }
     { { $snippet "caret-color" } " - a " { $link color } "." }
-    { { $snippet "selection-color" } " - a " { $link color } "." }
     { { $snippet "caret" } " - a " { $link model } " storing a line/column pair." }
     { { $snippet "mark" } " - a " { $link model } " storing a line/column pair. If there is no selection, the mark is equal to the caret, otherwise the mark is located at the opposite end of the selection from the caret." }
     { { $snippet "focused?" } " - a boolean." }
-} } ;
+} }
+{ $see-also line-gadget } ;
 
 HELP: <editor>
 { $values { "editor" "a new " { $link editor } } }
index 9c082896d938fcb3b8868bcd2f688406325481b4..10587885e6dc529b69dfaac5a78141f91ce39dad 100644 (file)
@@ -1,5 +1,43 @@
+USING: arrays colors fonts help.markup help.syntax
+ui.gadgets.scrollers ;
 IN: ui.gadgets.line-support
-USING: help.markup help.syntax ;
+
+HELP: line-gadget
+{ $class-description "Base class for gadgets that implements display of sequences of text."
+  $nl
+  "Line gadgets have the following slots:"
+  { $table
+    {
+        { $slot "font" }
+        { "a " { $link font } "." }
+    }
+    {
+        { $slot "selection-color" }
+        { "a " { $link color } "." }
+    }
+    {
+        { $slot "min-rows" }
+        { "The preferred minimum number of visible rows when the gadget is contained in a viewport." }
+    }
+    {
+        { $slot "max-rows" }
+        { "The preferred maximum number of visible rows when the gadget is cotnained in a viewport." }
+    }
+    {
+        { $slot "min-cols" }
+        { "The preferred minimum number of visible columns when the gadget is contained in a viewport." }
+    }
+    {
+        { $slot "max-cols" }
+        { "The preferred maximum number of visible columns when the gadget is contained in a viewport." }
+    }
+  }
+} ;
+
+HELP: pref-viewport-dim*
+{ $values { "gadget" line-gadget } { "dim" array } }
+{ $description "Calculates the preferred viewport dimenstions of the line gadget." }
+{ $see-also pref-viewport-dim } ;
 
 ARTICLE: "ui.gadgets.line-support" "Gadget line support"
 "The " { $vocab-link "ui.gadgets.line-support" } " vocabulary provides common code shared by gadgets which display a sequence of lines of text. Currently, the two gadgets that use it are " { $link "ui.gadgets.editors" } " and " { $link "ui.gadgets.tables" } "."
index 4849521a24b444c2dd6e44d0512d19221920bc94..4987fdfeab4eb42e2642e38918442c3d654be677 100644 (file)
@@ -1,4 +1,27 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: tools.test ui.gadgets.line-support ;
+USING: accessors arrays kernel tools.test ui.gadgets.editors
+ui.gadgets.line-support ui.gadgets.line-support.private ui.text ;
 IN: ui.gadgets.line-support.tests
+
+! line-gadget-height
+{ t } [
+    { 0 0 } <multiline-editor>
+    [ 1 >>min-rows line-gadget-height ]
+    [ line-height ] bi =
+] unit-test
+
+! line-gadget-width
+{ t } [
+    { 0 0 } <multiline-editor>
+    [ 1 >>min-cols line-gadget-width ]
+    [ font>> em ] bi =
+] unit-test
+
+! pref-viewport-dim*
+{ t } [
+    <multiline-editor>
+    [ 1 >>min-rows 1 >>min-cols pref-viewport-dim* ] [
+        [ font>> "m" text-width ] [ line-height ] bi 2array
+    ] bi =
+] unit-test
index 078c0eb1494e1c45a768ce311540422253125429..69177da79617a2a0346af7cf29eff53a4131e5e5 100644 (file)
@@ -8,15 +8,14 @@ IN: ui.gadgets.line-support
 
 ! Some code shared by table and editor gadgets
 TUPLE: line-gadget < gadget
-font selection-color
-min-rows max-rows
-min-cols max-cols
-line-leading line-height
-pref-viewport-dim ;
+    font selection-color
+    min-rows max-rows
+    min-cols max-cols
+    line-leading line-height
+    pref-viewport-dim ;
 
 : new-line-gadget ( class -- gadget )
-    new
-        selection-color >>selection-color ;
+    new selection-color >>selection-color ;
 
 GENERIC: line-leading* ( gadget -- n )