Added select support.
This commit is contained in:
@@ -25,3 +25,4 @@ rktwebview/build/
|
|||||||
/scrbl/*.js
|
/scrbl/*.js
|
||||||
*.bak
|
*.bak
|
||||||
/scrbl/*.html
|
/scrbl/*.html
|
||||||
|
/doc
|
||||||
|
|||||||
@@ -235,6 +235,17 @@
|
|||||||
(send this update-counter)
|
(send this update-counter)
|
||||||
(send this set-folder my-dir)
|
(send this set-folder my-dir)
|
||||||
|
|
||||||
|
(when (eq? my-page 'first)
|
||||||
|
(let ((language-select
|
||||||
|
(send this element 'sel-lang)))
|
||||||
|
(send language-select
|
||||||
|
on-change!
|
||||||
|
(λ (value)
|
||||||
|
(displayln
|
||||||
|
(format
|
||||||
|
"Selected language: ~a"
|
||||||
|
(send language-select get)))))))
|
||||||
|
|
||||||
(ww-debug "CONNECTING BUTTONS")
|
(ww-debug "CONNECTING BUTTONS")
|
||||||
(send this bind! 'dialog-button 'click (λ (el evt data)
|
(send this bind! 'dialog-button 'click (λ (el evt data)
|
||||||
(send this prefs)))
|
(send this prefs)))
|
||||||
|
|||||||
+43
-1
@@ -384,4 +384,46 @@ Writes @racket[v] by delegating to:
|
|||||||
(webview-set-value! wv element-id v)
|
(webview-set-value! wv element-id v)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@section{Class: wv-input/select%}
|
||||||
|
|
||||||
|
@defclass[wv-input/select% wv-element% ()]{
|
||||||
|
|
||||||
|
Wrapper for an HTML select element.
|
||||||
|
|
||||||
|
@defconstructor[([window (is-a?/c wv-window%)]
|
||||||
|
[element-id symbol?])]{
|
||||||
|
|
||||||
|
Creates a select-element wrapper.
|
||||||
|
}
|
||||||
|
|
||||||
|
@defmethod[(get) (or/c string? boolean?)]{
|
||||||
|
|
||||||
|
Returns the value of the selected option by delegating to
|
||||||
|
@racket[webview-value].
|
||||||
|
}
|
||||||
|
|
||||||
|
@defmethod[(set! [v (or/c symbol? string? number? boolean?
|
||||||
|
g:date? g:time? g:datetime? rgba?)])
|
||||||
|
any/c]{
|
||||||
|
|
||||||
|
Selects the option whose value equals @racket[v] by delegating to
|
||||||
|
@racket[webview-set-value!].
|
||||||
|
}
|
||||||
|
|
||||||
|
@defmethod[(set-options! [options list?]
|
||||||
|
[selected any/c #f])
|
||||||
|
any/c]{
|
||||||
|
|
||||||
|
Replaces the option elements. Each entry in @racket[options] is a list
|
||||||
|
containing a value and a label. When @racket[selected] is not @racket[#f],
|
||||||
|
the option with that value is selected.
|
||||||
|
}
|
||||||
|
|
||||||
|
@defmethod[(on-change! [callback-func procedure?]) any/c]{
|
||||||
|
|
||||||
|
Binds @racket[callback-func] to the HTML @tt{change} event. The callback
|
||||||
|
receives the newly selected value.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ following classes is instantiated:
|
|||||||
@item{@racket[wv-input/check%] for @racket['checkbox]}
|
@item{@racket[wv-input/check%] for @racket['checkbox]}
|
||||||
@item{@racket[wv-input/radio%] for @racket['radio]}
|
@item{@racket[wv-input/radio%] for @racket['radio]}
|
||||||
@item{@racket[wv-input/color%] for @racket['color]}
|
@item{@racket[wv-input/color%] for @racket['color]}
|
||||||
|
@item{@racket[wv-input/select%] for an HTML @tt{select} element}
|
||||||
@item{@racket[wv-element%] otherwise}]
|
@item{@racket[wv-element%] otherwise}]
|
||||||
|
|
||||||
Newly created wrappers receive this window through the @racket[window] init
|
Newly created wrappers receive this window through the @racket[window] init
|
||||||
@@ -537,4 +538,4 @@ This module also re-exports the public APIs from:
|
|||||||
@item{@racketmodname[rgba]}
|
@item{@racketmodname[rgba]}
|
||||||
@item{@racketmodname[wv-settings]}]
|
@item{@racketmodname[wv-settings]}]
|
||||||
|
|
||||||
It also re-exports @racket[webview-version].
|
It also re-exports @racket[webview-version].
|
||||||
|
|||||||
+41
-1
@@ -1,6 +1,7 @@
|
|||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
|
||||||
(require racket/class
|
(require racket/class
|
||||||
|
xml
|
||||||
"wv-element.rkt"
|
"wv-element.rkt"
|
||||||
"racket-webview.rkt"
|
"racket-webview.rkt"
|
||||||
)
|
)
|
||||||
@@ -14,7 +15,8 @@
|
|||||||
wv-input/range%
|
wv-input/range%
|
||||||
wv-input/check%
|
wv-input/check%
|
||||||
wv-input/radio%
|
wv-input/radio%
|
||||||
wv-input/color%)
|
wv-input/color%
|
||||||
|
wv-input/select%)
|
||||||
|
|
||||||
|
|
||||||
(define-syntax mk-cl
|
(define-syntax mk-cl
|
||||||
@@ -55,3 +57,41 @@
|
|||||||
(mk-cl wv-input/check% webview-set-value! webview-value/boolean)
|
(mk-cl wv-input/check% webview-set-value! webview-value/boolean)
|
||||||
(mk-cl wv-input/radio% webview-set-value! webview-value/boolean)
|
(mk-cl wv-input/radio% webview-set-value! webview-value/boolean)
|
||||||
(mk-cl wv-input/color% webview-set-value! webview-value/color)
|
(mk-cl wv-input/color% webview-set-value! webview-value/color)
|
||||||
|
|
||||||
|
(define wv-input/select%
|
||||||
|
(class wv-element%
|
||||||
|
(inherit-field window
|
||||||
|
element-id)
|
||||||
|
|
||||||
|
(super-new)
|
||||||
|
|
||||||
|
(define wv (hash-ref (send window info) 'wv))
|
||||||
|
|
||||||
|
(define/public (get)
|
||||||
|
(webview-value wv element-id))
|
||||||
|
|
||||||
|
(define/public (set! value)
|
||||||
|
(webview-set-value! wv element-id value))
|
||||||
|
|
||||||
|
(define/public (set-options! options [selected #f])
|
||||||
|
(send this
|
||||||
|
set-innerHTML!
|
||||||
|
(apply
|
||||||
|
string-append
|
||||||
|
(for/list ((option (in-list options)))
|
||||||
|
(let ((value (car option))
|
||||||
|
(label (cadr option)))
|
||||||
|
(xexpr->string
|
||||||
|
(list 'option
|
||||||
|
(list
|
||||||
|
(list 'value
|
||||||
|
(format "~a" value)))
|
||||||
|
(format "~a" label)))))))
|
||||||
|
(when selected
|
||||||
|
(send this set! selected)))
|
||||||
|
|
||||||
|
(define/public (on-change! callback-func)
|
||||||
|
(send window bind! element-id 'change
|
||||||
|
(λ (element event data)
|
||||||
|
(callback-func (send this get)))))
|
||||||
|
))
|
||||||
|
|||||||
+2
-2
@@ -100,7 +100,7 @@
|
|||||||
" return a;\n"
|
" return a;\n"
|
||||||
" } else { \n"
|
" } else { \n"
|
||||||
" if (a === null) {\n"
|
" if (a === null) {\n"
|
||||||
" return false;\n"
|
" return el.tagName;\n"
|
||||||
" } else {\n"
|
" } else {\n"
|
||||||
" return a;\n"
|
" return a;\n"
|
||||||
" }"
|
" }"
|
||||||
@@ -124,6 +124,7 @@
|
|||||||
((eq? type 'checkbox) wv-input/check%)
|
((eq? type 'checkbox) wv-input/check%)
|
||||||
((eq? type 'radio) wv-input/radio%)
|
((eq? type 'radio) wv-input/radio%)
|
||||||
((eq? type 'color) wv-input/color%)
|
((eq? type 'color) wv-input/color%)
|
||||||
|
((eq? type 'select) wv-input/select%)
|
||||||
((eq? type 'unknown) (begin
|
((eq? type 'unknown) (begin
|
||||||
(err-webview "Element with id '~a' not found"
|
(err-webview "Element with id '~a' not found"
|
||||||
id)
|
id)
|
||||||
@@ -602,4 +603,3 @@
|
|||||||
handler)
|
handler)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user