-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8727115
commit 9d6ba26
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Textbox | ||
|
||
The `Textbox` supports entry of a simple, single-line string, with optional validation logic. | ||
|
||
\begin{examplefigure}{} | ||
```julia | ||
using GLMakie | ||
using CairoMakie # hide | ||
CairoMakie.activate!() # hide | ||
|
||
f = Figure() | ||
Textbox(f[1, 1], placeholder = "Enter a string...") | ||
Textbox(f[2, 1], width = 300) | ||
|
||
f | ||
``` | ||
\end{examplefigure} | ||
|
||
## Validation | ||
|
||
The `validator` attribute is used with `validate_textbox(string, validator)` to determine if the current string is valid. It can be a `Regex` that needs to match the complete string, or a `Function` taking a `String` as input and returning a `Bool`. If the validator is a type T (for example `Float64`), validation will be `tryparse(string, T)`. The textbox will not allow submitting the currently entered value if the validator doesn't pass. | ||
|
||
\begin{examplefigure}{} | ||
```julia | ||
using GLMakie | ||
using CairoMakie # hide | ||
CairoMakie.activate!() # hide | ||
|
||
f = Figure() | ||
|
||
tb = Textbox(f[2, 1], placeholder = "Enter a frequency", | ||
validator = Float64, tellwidth = false) | ||
|
||
frequency = Node(1.0) | ||
|
||
on(tb.stored_string) do s | ||
frequency[] = parse(Float64, s) | ||
end | ||
|
||
xs = 0:0.01:10 | ||
sinecurve = @lift(sin.($frequency .* xs)) | ||
|
||
lines(f[1, 1], xs, sinecurve) | ||
|
||
f | ||
``` | ||
\end{examplefigure} |