def on_framebuffer_resize(self, window, w, h):
        """Updates windows/UI sizes and redraws the UI with correct HDPI scaling."""
        self.framebuffer_size = w, h
        if self.is_minimized():
            return

        # NOTE: macOS and some Linux versions with the wayland display server have an
        # upscaled framebuffer when using a high-DPI monitor. This means that screen
        # coordinates != pixel coordinates. We need to know if this is the case in order
        # to transform UI input into the right coordinates, so we check for this case
        # here.
        window_size = glfw.glfwGetWindowSize(window)
        self.has_scaled_framebuffer = window_size != self.framebuffer_size

        # Always clear buffers on resize to make sure that the black stripes left/right
        # are black and not polluted from previous frames. Make sure this is applied on
        # the whole window and not within glViewport!
        gl_utils.glClear(gl_utils.GL_COLOR_BUFFER_BIT)
        gl_utils.glClearColor(0, 0, 0, 1)

        self.hdpi_factor = glfw.glfwGetWindowContentScale(window)[0]
        self.gui.scale = self.gui_user_scale * self.hdpi_factor

        with self.use_content_area() as (x, y, content_w, content_h):
            # update GUI window to full window
            self.gui.update_window(w, h)

            # update content container to content square
            # NOTE: since this is part of the UI, it will be affected by the gui
            # scaling, but we actually need real coordinates, so we need to convert it
            # back.
            self.cont.outline = ui.FitBox(
                ui.Vec2(x // self.hdpi_factor, y // self.hdpi_factor),
                ui.Vec2(content_w // self.hdpi_factor,
                        content_h // self.hdpi_factor),
            )
            self.draw_texture()
            self.gui.collect_menus()
            self.update_gui()

        gl_utils.glFlush()
        glfw.glfwSwapBuffers(self._window)
 def hdpi_changed(self):
     return self.hdpi_factor != glfw.glfwGetWindowContentScale(
         self._window)[0]