From 16381beddcd0c05fff8cc226e9ca1d651fa8136d Mon Sep 17 00:00:00 2001 From: masweeney Date: Sun, 21 Aug 2016 18:19:03 -0400 Subject: [PATCH] ui.gadgets.editors: add editor-constrained-dim function to editor This function allows the calculation of dimensions with respect to min/max-row/column values. --- basis/ui/gadgets/editors/editors.factor | 32 ++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/basis/ui/gadgets/editors/editors.factor b/basis/ui/gadgets/editors/editors.factor index f14e2b6ed2..e1119af718 100644 --- a/basis/ui/gadgets/editors/editors.factor +++ b/basis/ui/gadgets/editors/editors.factor @@ -6,7 +6,7 @@ documents.elements fry grouping kernel locals make math math.functions math.order math.ranges math.rectangles math.vectors models models.arrow namespaces opengl sequences sorting splitting timers ui.baseline-alignment ui.clipboards -ui.commands ui.gadgets ui.gadgets.borders +ui.commands ui.gadgets ui.gadgets.borders strings ui.gadgets.line-support ui.gadgets.menus ui.gadgets.scrollers ui.theme ui.gestures ui.pens.solid ui.render ui.text unicode ; @@ -213,6 +213,36 @@ M: editor draw-gadget* [ draw-lines ] [ draw-caret ] bi ] with-variable ; + swap + CHAR: \n + append text-dim ; + +: min-dim ( font editor -- dim ) + [ min-rows>> [ 0 ] unless* ] + [ min-cols>> [ 0 ] unless* ] bi + row,col-dim ; + +: max-dim ( font editor -- dim ) + ! hopefully no one goes over 5000 + [ max-rows>> [ 5000 ] unless* ] + [ max-cols>> [ 5000 ] unless* ] bi + row,col-dim ; + +: txt-dim ( font editor -- dim ) + control-value text-dim ; + +PRIVATE> + +: editor-constrained-dim ( editor -- dim ) + [ font>> ] keep + [ max-dim ] + [ txt-dim ] + [ min-dim ] + 2tri vmax vmin { 1 0 } v+ ; + M: editor pref-dim* ! Add some space for the caret. [ font>> ] [ control-value ] bi text-dim { 1 0 } v+ ; -- 2.34.1