Skip to content

Commit

Permalink
textbox page
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel committed Aug 25, 2021
1 parent 8727115 commit 9d6ba26
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions docs/examples/layoutables/textbox.md
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}

0 comments on commit 9d6ba26

Please sign in to comment.