Added select support.

This commit is contained in:
2026-08-06 00:08:24 +02:00
parent 3d4deed94a
commit 963fec5df5
6 changed files with 100 additions and 5 deletions
+1
View File
@@ -25,3 +25,4 @@ rktwebview/build/
/scrbl/*.js
*.bak
/scrbl/*.html
/doc
+11
View File
@@ -235,6 +235,17 @@
(send this update-counter)
(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")
(send this bind! 'dialog-button 'click (λ (el evt data)
(send this prefs)))
+42
View File
@@ -385,3 +385,45 @@ Writes @racket[v] by delegating to:
]
}
}
@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.
}
}
+1
View File
@@ -133,6 +133,7 @@ following classes is instantiated:
@item{@racket[wv-input/check%] for @racket['checkbox]}
@item{@racket[wv-input/radio%] for @racket['radio]}
@item{@racket[wv-input/color%] for @racket['color]}
@item{@racket[wv-input/select%] for an HTML @tt{select} element}
@item{@racket[wv-element%] otherwise}]
Newly created wrappers receive this window through the @racket[window] init
+41 -1
View File
@@ -1,6 +1,7 @@
#lang racket/base
(require racket/class
xml
"wv-element.rkt"
"racket-webview.rkt"
)
@@ -14,7 +15,8 @@
wv-input/range%
wv-input/check%
wv-input/radio%
wv-input/color%)
wv-input/color%
wv-input/select%)
(define-syntax mk-cl
@@ -55,3 +57,41 @@
(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/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
View File
@@ -100,7 +100,7 @@
" return a;\n"
" } else { \n"
" if (a === null) {\n"
" return false;\n"
" return el.tagName;\n"
" } else {\n"
" return a;\n"
" }"
@@ -124,6 +124,7 @@
((eq? type 'checkbox) wv-input/check%)
((eq? type 'radio) wv-input/radio%)
((eq? type 'color) wv-input/color%)
((eq? type 'select) wv-input/select%)
((eq? type 'unknown) (begin
(err-webview "Element with id '~a' not found"
id)
@@ -602,4 +603,3 @@
handler)
)