samyeyo / LuaRT

Open source Windows programming framework for Lua
https://www.luart.org
Other
285 stars 17 forks source link

UI refresh artifacts on window resizing #86

Closed Dismalitie closed 1 year ago

Dismalitie commented 1 year ago

While working on a project, I noticed that when resizing the window with Window.width or Window.height creates black visual artifacts in the section that is resizing. I beleive it is to do with the screen refresh and the ui.update() function. Here is some code that can be used to replicate the problem:

local ui = require("ui")
local win = ui.Window("UI refresh artifacts replication", 500, 500)
local button = ui.Button(win, "Click me!", 10, 10)
function button:onClick()
  repeat
    win.width = win.width+20
    sys.sleep(1)
  until win.width == 800
  button.enabled = false
end
win:show()
repeat ui.update() until not win.visible

image This may also be a problem at my end with my screen, so here are my monitor specs in case you want to emulate them:

My graphics card is a NVIDIA GeForce RTX 2080 Thanks for reading! 👍

samyeyo commented 1 year ago

Hi Dismalitie,

Thank you for this report. In fact it's not a bug : inside an UI event, the GUI is not updated. If you change a widget property (size, position, color...) you need to update the UI using ui.update()

local ui = require("ui")
local win = ui.Window("UI refresh artifacts replication", 500, 500)
local button = ui.Button(win, "Click me!", 10, 10)
function button:onClick()
  repeat
    win.width = win.width+20
    ui.update() -- to update the ui after width has changed
  until win.width == 800
  button.enabled = false
end
win:show()
repeat ui.update() until not win.visible

It's not perfect but it's way better 😄

samyeyo commented 1 year ago

I have found another workaround to prevent this resizing problem, that will be available in next LuaRT release 👍

Dismalitie commented 1 year ago

Thanks!