From f4ae56a85b6a21642f5f62883b4f331d953312dd Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 7 Feb 2009 18:14:18 -0600 Subject: [PATCH] ui.gadgets.line-support: common code for gadgets that display a vertical list of lines --- basis/ui/gadgets/line-support/authors.txt | 1 + .../line-support/line-support-tests.factor | 4 ++ .../gadgets/line-support/line-support.factor | 50 +++++++++++++++++++ basis/ui/gadgets/line-support/summary.txt | 1 + 4 files changed, 56 insertions(+) create mode 100644 basis/ui/gadgets/line-support/authors.txt create mode 100644 basis/ui/gadgets/line-support/line-support-tests.factor create mode 100644 basis/ui/gadgets/line-support/line-support.factor create mode 100644 basis/ui/gadgets/line-support/summary.txt diff --git a/basis/ui/gadgets/line-support/authors.txt b/basis/ui/gadgets/line-support/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/basis/ui/gadgets/line-support/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/basis/ui/gadgets/line-support/line-support-tests.factor b/basis/ui/gadgets/line-support/line-support-tests.factor new file mode 100644 index 0000000000..4849521a24 --- /dev/null +++ b/basis/ui/gadgets/line-support/line-support-tests.factor @@ -0,0 +1,4 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test ui.gadgets.line-support ; +IN: ui.gadgets.line-support.tests diff --git a/basis/ui/gadgets/line-support/line-support.factor b/basis/ui/gadgets/line-support/line-support.factor new file mode 100644 index 0000000000..b4b59d9a29 --- /dev/null +++ b/basis/ui/gadgets/line-support/line-support.factor @@ -0,0 +1,50 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays combinators fry kernel math math.order +math.ranges math.vectors namespaces opengl sequences ui.gadgets +ui.render ui.text ; +IN: ui.gadgets.line-support + +! Some code shared by table and editor gadgets +SLOT: font + +: line-height ( gadget -- n ) + font>> "" text-height ; + +: y>line ( y gadget -- n ) + line-height /i ; + +: line>y ( n gadget -- y ) + line-height * ; + +: validate-line ( m gadget -- n ) + control-value [ drop f ] [ length 1- min 0 max ] if-empty ; + +: visible-line ( gadget quot -- n ) + '[ + [ clip get @ origin get [ second ] bi@ - ] dip + y>line + ] keep validate-line ; inline + +: first-visible-line ( gadget -- n ) + [ loc>> ] visible-line ; + +: last-visible-line ( gadget -- n ) + [ [ loc>> ] [ dim>> ] bi v+ ] visible-line 1+ ; + +: each-slice-index ( from to seq quot -- ) + [ [ ] [ drop [a,b) ] 3bi ] dip 2each ; inline + +GENERIC: draw-line ( line index gadget -- ) + +: draw-lines ( gadget -- ) + { + [ first-visible-line ] + [ last-visible-line ] + [ control-value ] + [ line-height ] + [ ] + } cleave '[ + 0 over _ * 2array + [ _ draw-line ] with-translation + ] each-slice-index ; \ No newline at end of file diff --git a/basis/ui/gadgets/line-support/summary.txt b/basis/ui/gadgets/line-support/summary.txt new file mode 100644 index 0000000000..90ecc38078 --- /dev/null +++ b/basis/ui/gadgets/line-support/summary.txt @@ -0,0 +1 @@ +Code shared between table and editor gadgets