Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions gui-easy-lib/gui/easy/private/view/input.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
(send* v
(stretchable-width w-s?)
(stretchable-height h-s?))]))

(define/public (destroy v)
(send v clear-context))))

Expand All @@ -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?]
Expand Down
2 changes: 1 addition & 1 deletion gui-easy-lib/gui/easy/view.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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%)))
Expand Down
9 changes: 7 additions & 2 deletions gui-easy/gui/easy/scribblings/reference.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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?)]
Expand Down