Skip to content

Commit

Permalink
add unsafe_set!(::Textbox...)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed Nov 20, 2024
1 parent 26b5189 commit 24fd6c4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Add `unsafe_set!(::Textbox, ::String)` [#4417](https://github.com/MakieOrg/Makie.jl/pull/4417)
- Prevent more default actions when canvas has focus [#4602](https://github.com/MakieOrg/Makie.jl/pull/4602).
- Fix an error in `convert_arguments` for PointBased plots and 3D polygons [#4585](https://github.com/MakieOrg/Makie.jl/pull/4585).
- Fix polygon rendering issue of `crossbar(..., show_notch = true)` in CairoMakie [#4587](https://github.com/MakieOrg/Makie.jl/pull/4587).
Expand Down
10 changes: 9 additions & 1 deletion src/makielayout/blocks/textbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,18 @@ end
Sets the stored_string of the given `Textbox` to `string`, triggering listeners of `tb.stored_string`.
"""
function set!(tb::Textbox, string::String)
if !validate_textbox(string, tb.validator[])
if validate_textbox(string, tb.validator[])
unsafe_set!(tb, string)
else
error("Invalid string \"$(string)\" for textbox.")
end
end

"""
unsafe_set!(tb::Textbox, string::String)
Sets the stored_string of the given `Textbox` to `string`, ignoring the possibility that it might not pass the validator function.
"""
function unsafe_set!(tb::Textbox, string::String)
tb.displayed_string = string
tb.stored_string = string
nothing
Expand Down
8 changes: 8 additions & 0 deletions test/makielayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,11 @@ end
end
@test isempty(limits.listeners)
end

@testset "Textbox set! & unsafe_set!" begin
f = Figure()
tb = Textbox(f[1,1], validator = isequal("hi"))
@test isnothing(Makie.set!(tb, "hi"))
@test_throws ErrorException Makie.set!(tb, "there")
@test isnothing(Makie.unsafe_set!(tb, "there"))
end

0 comments on commit 24fd6c4

Please sign in to comment.