Lua API for GUI

Everything about development and the OpenMW source code.
User avatar
wazabear
Posts: 51
Joined: 13 May 2020, 19:31
Gitlab profile: https://gitlab.com/glassmancody.info

Re: Lua API for GUI

Post by wazabear »

urm wrote: 20 May 2021, 20:16 I don't see any built-in way to make a widget's width 30% of its parent's.
That's what position_real is for, to get 30% width and 100% height you'd do this.

Code: Select all

position_real="0 0 0.3 1"
Fade away and radiate
User avatar
urm
Posts: 78
Joined: 02 Jun 2017, 16:05
Contact:

Re: Lua API for GUI

Post by urm »

wazabear wrote: 20 May 2021, 20:33
urm wrote: 20 May 2021, 20:16 I don't see any built-in way to make a widget's width 30% of its parent's.
That's what position_real is for, to get 30% width and 100% height you'd do this.

Code: Select all

position_real="0 0 0.3 1"
I see, it's just yes another MyGUI feature which has a nonsensical name and isn't documented :)
Will try it out and see if I need to roll my own after all. I can already tell that the one I've made for tes3mp was more advanced, but maybe this is good enough.
User avatar
urm
Posts: 78
Joined: 02 Jun 2017, 16:05
Contact:

Re: Lua API for GUI

Post by urm »

I've considered custom widgets written in Lua more, and realized that they wouldn't be useful unless they run on the main (UI) thread.
Even if we accept a one-frame delay on UI functionality, we could have delays of arbitrary amount of frames if multiple custom widgets are nested.

That is because one of the core functionalities of custom widgets is reacting to size changes of their parents, so we would have a sequence like this:
1. Lua code changes the size of a custom widget -> it gets processed next frame by MyGUI, which passes the update to all of its children
2. we handle the updates of the children on the Lua thread -> next frame MyGUI passes those to their children

Step 2 repeats until we reach the bottom of the widget tree. Not only these arbitrary delays would be visual jarring, they would also be very bug prone, as the UI tree would often be in half-updated states like that.

So we either need some approach for running some Lua code in the main thread, simultaneously with MyGUI, or restrict creating widgets to C++. I'm leaning towards the latter, I think we can provide all the necessary widgets ourselves. However that is assuming this is the only issue caused by multiple one-frame delays, and assuming we are fine with a one-frame delay for all of the Lua UI actions.
User avatar
AnyOldName3
Posts: 2158
Joined: 26 Nov 2015, 03:25

Re: Lua API for GUI

Post by AnyOldName3 »

I brought that up when we were discussing the Lua threading model, and ptmikheev responded in some way or other, so he might have a plan already.
AnyOldName3, Master of Shadows
User avatar
urm
Posts: 78
Joined: 02 Jun 2017, 16:05
Contact:

Re: Lua API for GUI

Post by urm »

wazabear wrote: 20 May 2021, 20:33
urm wrote: 20 May 2021, 20:16 I don't see any built-in way to make a widget's width 30% of its parent's.
That's what position_real is for, to get 30% width and 100% height you'd do this.

Code: Select all

position_real="0 0 0.3 1"
Forgot to write an update on this. I've tried real position, and it's not great. The main issue is that it gets converted into pixels immediately. So if the parent size changes later, the children sizes stay the same as they were.
darkbasic
Posts: 126
Joined: 18 Apr 2016, 15:45
Contact:

Re: Lua API for GUI

Post by darkbasic »

AnyOldName3 wrote: 02 Jul 2021, 00:10 I brought that up when we were discussing the Lua threading model, and ptmikheev responded in some way or other, so he might have a plan already.
It would be nice to have him explain what the plan currently is.
ptmikheev
Posts: 61
Joined: 01 Jun 2020, 21:05
Gitlab profile: https://gitlab.com/ptmikheev

Re: Lua API for GUI

Post by ptmikheev »

urm wrote: 01 Jul 2021, 12:36 So we either need some approach for running some Lua code in the main thread, simultaneously with MyGUI, or restrict creating widgets to C++. I'm leaning towards the latter, I think we can provide all the necessary widgets ourselves. However that is assuming this is the only issue caused by multiple one-frame delays, and assuming we are fine with a one-frame delay for all of the Lua UI actions.
It is fine to call some UI callbacks from the main thread if it is really needed.
However I think we shouldn't add too lot of functionality in one merge request.
Would it be reasonable to start from C++-only widgets and keep it mind how to add custom widgets if/when it becomes essential?
User avatar
urm
Posts: 78
Joined: 02 Jun 2017, 16:05
Contact:

Re: Lua API for GUI

Post by urm »

ptmikheev wrote: 02 Jul 2021, 20:49
urm wrote: 01 Jul 2021, 12:36 So we either need some approach for running some Lua code in the main thread, simultaneously with MyGUI, or restrict creating widgets to C++. I'm leaning towards the latter, I think we can provide all the necessary widgets ourselves. However that is assuming this is the only issue caused by multiple one-frame delays, and assuming we are fine with a one-frame delay for all of the Lua UI actions.
It is fine to call some UI callbacks from the main thread if it is really needed.
However I think we shouldn't add too lot of functionality in one merge request.
Would it be reasonable to start from C++-only widgets and keep it mind how to add custom widgets if/when it becomes essential?
Yeah, I'm leaning to that approach in any case
User avatar
wazabear
Posts: 51
Joined: 13 May 2020, 19:31
Gitlab profile: https://gitlab.com/glassmancody.info

Re: Lua API for GUI

Post by wazabear »

urm wrote: 02 Jul 2021, 08:26
wazabear wrote: 20 May 2021, 20:33
urm wrote: 20 May 2021, 20:16 I don't see any built-in way to make a widget's width 30% of its parent's.
That's what position_real is for, to get 30% width and 100% height you'd do this.

Code: Select all

position_real="0 0 0.3 1"
Forgot to write an update on this. I've tried real position, and it's not great. The main issue is that it gets converted into pixels immediately. So if the parent size changes later, the children sizes stay the same as they were.

Daaaamn that's so useless then, thought it was a property of the widgets.
Fade away and radiate
User avatar
urm
Posts: 78
Joined: 02 Jun 2017, 16:05
Contact:

Re: Lua API for GUI

Post by urm »

wazabear wrote: 13 Jul 2021, 01:44 Daaaamn that's so useless then, thought it was a property of the widgets.
I've implemented a different relative positioning system https://gitlab.com/uramer/openmw/-/comm ... c00e45704e

I'm not sure this approach will work however, since currently it doesn't interact with other widget logic changing widgets' positions and size. I don't see any way to make it work "properly" without altering MyGUI code yet.
Post Reply