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 Oct 3, 2024
1 parent 1202dce commit 5c6d019
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)
- Fix `merge(attr1, attr2)` modifying nested attributes in `attr1` [#4416](https://github.com/MakieOrg/Makie.jl/pull/4416)
- Fixed issue with CairoMakie rendering scene backgrounds at the wrong position [#4425](https://github.com/MakieOrg/Makie.jl/pull/4425)
- Fix incorrect inverse transformation in `position_on_plot` for lines, causing incorrect tooltip placement in DataInspector [#4402](https://github.com/MakieOrg/Makie.jl/pull/4402)
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 @@ -320,10 +320,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)

Check warning on line 324 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L323-L324

Added lines #L323 - L324 were not covered by tests
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)

Check warning on line 334 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L334

Added line #L334 was not covered by tests
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 @@ -541,3 +541,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 5c6d019

Please sign in to comment.