From f24444e99019a68bfa8fa546a3ea8b5218e0f4cb Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sun, 16 Aug 2015 13:45:16 -0700 Subject: [PATCH] ui.gadgets.editors: allow action-fields to have a default text. --- basis/ui/gadgets/editors/editors.factor | 30 +++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/basis/ui/gadgets/editors/editors.factor b/basis/ui/gadgets/editors/editors.factor index 5c18d226ac..80446da3fb 100644 --- a/basis/ui/gadgets/editors/editors.factor +++ b/basis/ui/gadgets/editors/editors.factor @@ -8,7 +8,8 @@ math.vectors models models.arrow namespaces opengl sequences sorting splitting timers ui.baseline-alignment ui.clipboards ui.commands ui.gadgets ui.gadgets.borders ui.gadgets.line-support ui.gadgets.menus ui.gadgets.scrollers -ui.gestures ui.pens.solid ui.render ui.text unicode.categories ; +ui.gadgets.theme ui.gestures ui.pens.solid ui.render ui.text +unicode.categories ; EXCLUDE: fonts => selection ; IN: ui.gadgets.editors @@ -646,10 +647,35 @@ M: model-field ungraft* M: model-field model-changed nip [ editor>> editor-string ] [ field-model>> ] bi set-model ; +TUPLE: action-editor < editor default-text ; + +: ( -- editor ) + action-editor new-editor ; + +> ] [ model>> doc-string empty? ] } 1&& ; + +: draw-default-text ( editor -- ) + [ font>> clone line-color >>foreground ] + [ default-text>> ] bi draw-text ; + +PRIVATE> + +M: action-editor draw-gadget* + dup draw-default-text? [ + [ draw-default-text ] [ draw-caret ] bi + ] [ + call-next-method + ] if ; + TUPLE: action-field < field quot ; : ( quot: ( string -- ) -- gadget ) - action-field new-field + action-field [ ] dip new-border + dup gadget-child >>editor + field-theme swap >>quot ; : invoke-action-field ( field -- ) -- 2.34.1