diff --git a/CHANGELOG.md b/CHANGELOG.md index 36a78b23e4e..f883599a4ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ## [0.21.17] - 2024-12-05 +- Added `backend` and `update` kwargs to `show` [#4558](https://github.com/MakieOrg/Makie.jl/pull/4558) - Disabled unit prefix conversions for compound units (e.g. `u"m/s"`) to avoid generating incorrect units. [#4583](https://github.com/MakieOrg/Makie.jl/pull/4583) - Added kwarg to rotate Toggle [#4445](https://github.com/MakieOrg/Makie.jl/pull/4445) - Fixed orientation of environment light textures in RPRMakie [#4629](https://github.com/MakieOrg/Makie.jl/pull/4629). diff --git a/src/display.jl b/src/display.jl index c5ce72610de..336c6028922 100644 --- a/src/display.jl +++ b/src/display.jl @@ -244,7 +244,7 @@ function Base.show(io::IO, m::MIME"text/markdown", fig::FigureLike) throw(MethodError(show, io, m, fig)) end -function Base.show(io::IO, m::MIME, figlike::FigureLike) +function Base.show(io::IO, m::MIME, figlike::FigureLike; backend = current_backend(), update=true) if ALWAYS_INLINE_PLOTS[] == false && m isa MIME_TO_TRICK_VSCODE # We use this mime to display the figure in a window here. # See declaration of MIME_TO_TRICK_VSCODE for more info @@ -252,9 +252,8 @@ function Base.show(io::IO, m::MIME, figlike::FigureLike) return () # this is a diagnostic vscode mime, so we can just return nothing end scene = get_scene(figlike) - backend = current_backend() # get current screen the scene is already displayed on, or create a new screen - update_state_before_display!(figlike) + update && update_state_before_display!(figlike) screen = getscreen(backend, scene, Dict(:visible=>false), io, m) backend_show(screen, io, m, scene) return screen diff --git a/test/figures.jl b/test/figures.jl index e1637544e0d..f268ae39b17 100644 --- a/test/figures.jl +++ b/test/figures.jl @@ -171,3 +171,10 @@ end @test_throws ArgumentError lines(f[1, 1], 1:10, axis = (aspect = DataAspect())) @test_throws ArgumentError lines(f[1, 1][2, 2], 1:10, axis = (aspect = DataAspect())) end + +@testset "show with a backend" begin + fig = Figure() + io = IOBuffer() + # if there were no show method with backend and update kwargs then MethodError would be thrown instead + @test_throws ErrorException show(io, MIME"text/plain"(), fig, backend=missing, update=false) +end