diff --git a/gui-easy-lib/gui/easy/private/view/input.rkt b/gui-easy-lib/gui/easy/private/view/input.rkt index 8400e88..2bd754c 100644 --- a/gui-easy-lib/gui/easy/private/view/input.rkt +++ b/gui-easy-lib/gui/easy/private/view/input.rkt @@ -119,7 +119,7 @@ (send* v (stretchable-width w-s?) (stretchable-height h-s?))])) - + (define/public (destroy v) (send v clear-context)))) @@ -136,7 +136,16 @@ #:mixin [mix values] #:value=? [value=? equal?] #:value->text [value->text values]) - (new (input% (mix gui:text-field%)) + ; The modified text-field makes the action responsive to the control receiving or losing the focus. + (define modified-text-field% (class gui:text-field% + (super-new) + (define/override (on-focus focused?) + (action + (case focused? + [(#t) 'has-focus] + [(#f) 'lost-focus]) + (send this get-value))))) + (new (input% (mix modified-text-field%)) [@label @label] [@content @content] [@enabled? @enabled?] diff --git a/gui-easy-lib/gui/easy/view.rkt b/gui-easy-lib/gui/easy/view.rkt index 080eb1b..0ecfe86 100644 --- a/gui-easy-lib/gui/easy/view.rkt +++ b/gui-easy-lib/gui/easy/view.rkt @@ -159,7 +159,7 @@ #:mode (maybe-obs/c (or/c 'fit 'fill))] view/c)] [input (->* [(maybe-obs/c any/c)] - [(-> (or/c 'input 'return) string? any) + [(-> (or/c 'input 'return 'has-focus 'lost-focus) string? any) #:label (maybe-obs/c maybe-label/c) #:enabled? (maybe-obs/c boolean?) #:background-color (maybe-obs/c (or/c #f (is-a?/c gui:color%))) diff --git a/gui-easy/gui/easy/scribblings/reference.scrbl b/gui-easy/gui/easy/scribblings/reference.scrbl index a45d893..40867b6 100644 --- a/gui-easy/gui/easy/scribblings/reference.scrbl +++ b/gui-easy/gui/easy/scribblings/reference.scrbl @@ -542,7 +542,7 @@ packages in the Racket ecosystem, into their projects. } @defproc[(input [value (maybe-obs/c any/c)] - [action (-> (or/c 'input 'return) string? any) void] + [action (-> (or/c 'input 'return 'has-focus 'lost-focus) string? any) void] [#:label label (maybe-obs/c maybe-label/c) #f] [#:enabled? enabled? (maybe-obs/c boolean?) #t] [#:background-color background-color (maybe-obs/c (or/c #f (is-a?/c gui:color%))) #f] @@ -559,7 +559,7 @@ packages in the Racket ecosystem, into their projects. [#:value->text value->text (-> any/c string?) values]) (is-a?/c view<%>)]{ Returns a representation of a text field that calls @racket[action] on change. The first argument to the @racket[action] is the type of - event that caused the input to change and the second is the contents + event that the control is responding to and the second is the contents of the text field. The @racket[#:value=?] argument controls when changes to the input @@ -574,6 +574,11 @@ packages in the Racket ecosystem, into their projects. The @racket[#:value->text] argument controls how the input values are rendered to strings. If not provided, @racket[value] must be either a @racket[string?] or an observable of strings. + + @history[ + #:changed "0.21" @elem{@racket[input] also responds to the @racket['has-focus] and + @racket['lost-focus] events.} + ] } @defproc[(progress [value (maybe-obs/c gui:position-integer?)]