Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot renders with wrong size when replacing the GtkMakieWidget Figure #24

Open
Joroks opened this issue Jan 31, 2025 · 1 comment
Open

Comments

@Joroks
Copy link
Contributor

Joroks commented Jan 31, 2025

Here's my MWE:

using Gtk4, GLMakie, Gtk4Makie

win = GtkWindow("", 500, 600)
win[] = grid = GtkGrid()

grid[1,1] = button = GtkButton(width_request=100)
grid[2,1] = widget = GtkMakieWidget()

fig, ax, line = lines(rand(10))
push!(widget, fig)

signal_connect(button, :clicked) do _
    fig, ax, line = lines(rand(10))
    push!(widget, fig)
end

show(win)

When I press the Button, I first have to resize the window in for the plot to render with the correct size.

Image

@Joroks
Copy link
Contributor Author

Joroks commented Jan 31, 2025

I tried looking into why this happens, but I don't think I've found the root cause.
A fix that I've found to work is to manually call resize! in display:

function Base.display(screen::Screen{T}, scene::Scene; connect=true) where T <: GtkWidget
    if !Makie.is_displayed(screen, scene)
        if !isnothing(screen.scene)
            delete!(screen, screen.scene)
            screen.scene = nothing
        end
        GLMakie.display_scene!(screen, scene)
        fig = Makie.current_figure()
        if Makie.get_scene(fig) == scene
            widget = glarea(screen)
            resize!(scene, GLMakie.framebuffer_size(widget)) # call resize! here
            if widget.figure != fig
                widget.inspector = nothing
                widget.figure = fig
            end
        end
    else
        @assert screen.scene === scene "internal error. Scene already displayed by screen but not as root scene"
    end
    GLMakie.pollevents(screen, Makie.BackendTick)
    return screen
end

I've also noticed that GLMakie.framebuffer_size never actually gets called by anything. Neither when pushing the Figure nor when resizeing the window. However, at some point the Scene size does get set correctly but I can't figure out where and how that happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant