Minetest GUIs, The Past, Present, and Future: An Overview

For people working on the C++ code.
Post Reply
User avatar
v-rob
Developer
Posts: 792
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Minetest GUIs, The Past, Present, and Future: An Overview

by v-rob » Post

If you want to know what's going on with GUIs, look at the later posts in this thread written by me. I'd rather not repeat everything in this first post. And, I suppose these posts in this thread can be considered my official-ish evolving roadmap.

Most important things to look at:
Lua-based GUI/HUD overview: viewtopic.php?p=382529#p382529
New UI API prototype: viewtopic.php?p=382974#p382974
+ Defunct formspec roadmap stuff
Last edited by v-rob on Mon Oct 26, 2020 15:39, edited 7 times in total.
GUI Core Developer | My Best Mods: Bridger - Slats - Stained Glass | To contact me, send a PM

User avatar
GreenXenith
Member
Posts: 1329
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenXenith
In-game: GreenXenith
Location: The singularity
Contact:

Re: Formspecs, The Past, Present, and Future: An Overview

by GreenXenith » Post

I am rather excited for all of the formspec changes, I just wish they could happen sooner :D

Having styling features for every element is very important, because having the default irrlicht grey gradient on any element seriously breaks the look of themed formspecs. I am glad you have thought of this.

I saw the model element PR and was somewhat disappointed, to say the least. For one, the options for movement seem to be lacking. You can either click and drag to rotate, or control it via the element, but the element control is severely limited, and there is no option for just mouse control without clicking (Minecraft-like player preview .. not that I actually want to use that, but some people might). On top of this, I cant set the animation of the mesh if it has any, which is sort of important for certain previews. The ideal model element would somehow include object visual methods (set_animation, set_bone_position, set_attach, etc), that way you can make it look however you want. Since the element is so limited, I will probably end up making my previews using a form with a transparent viewing window showing an in-world entity, even though I would rather not as it brings up other complications (other players can see the entity and whatnot). I know it isn't your PR, but I'm still giving my thoughts about it.

One thing I regularly miss is dynamic formspec updating. You can change the form in a node live without interrupting the user interaction, so why cant we do so in regular formspecs? For example, I have made use of RGB sliders in various formspecs, but they only really work well in nodes. In a detached formspec, whenever you resend the form after moving the slider (say, to update a colorized preview), the slider gets dropped and the user has to click to start moving it again. This is not an issue in node formspecs, but I don't have the liberty of using node formspecs everywhere.

Your formspec refactor is probably one of the best items I see in this list. I severely dislike the string-based form creation. Yes, it's compact. But it is not always clean or pretty, and it also limits the features that can be added. If formspecs were object-based, elements could have methods (for movement, styling, etc .. could be nice for that model element). Even if they aren't object-based, any real GUI system would open up more opportunities than they current system grants.

And hey, being a core dev doesn't prevent you from specializing in a specific area. I think you'd be great as a formspec core dev :]
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.

User avatar
rubenwardy
Moderator
Posts: 6291
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: United Kingdom
Contact:

Re: Formspecs, The Past, Present, and Future: An Overview

by rubenwardy » Post

The formspec refactor won't change the string-based API of formspecs - just the internal code. Changing the API would require a formspec language replacement, there's an issue for that

User avatar
v-rob
Developer
Posts: 792
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: Formspecs, The Past, Present, and Future: An Overview

by v-rob » Post

Glad to hear some positive feedback. Yes, I wish things could happen faster too. ATM, I'm basically at a standstill because I need some PRs merged before I can work on other things. That's the main reason for the priority numbers, because these are the most important things to be merged for important things to progress. It's not saying which things will be merged first, just their relative importance to future PRs.

I could make one or two more PRs currently, e.g. style animations don't necessarily depend on anything else, but I'd rather not because I can't really start refactoring until I get most of my PRs merged. No one wants to rebase 11 PRs.

Of course, core dev time is limited, so I'm patient :) But if any core devs who want to review a formspec PR or two, this list should help out a bit.
GUI Core Developer | My Best Mods: Bridger - Slats - Stained Glass | To contact me, send a PM

User avatar
jp
Member
Posts: 803
Joined: Wed Dec 18, 2013 09:03
GitHub: kilbith
Location: France

Re: Formspecs, The Past, Present, and Future: An Overview

by jp » Post

GreenXenith wrote:
Mon Aug 17, 2020 20:54
I saw the model element PR and was somewhat disappointed, to say the least. [...]
Since it's my PR, I will reply. First of all, you should be satisfied that this PR exists in the first place. It's not really encouraging to read that it's "disappointing, to say the least" whereas I spent late nights on this.

The options for movements will be made possible if the core-devs move their arses and review #8679 and merge it after a year of waiting and a lot of enthusiasm from the best modders. Then it will be possible to create a 3D game nested in another 3D game.

Setting animations to mesh[] is a low-hanging fruit BUT more improvements can come incrementally in later PRs, for now I just laid the foundations. Like my colleague did for hypertext[].

Priority number one should be making v-rob a core-dev for the continued attention to the formspec PRs over the time and to handle all of this workforce on this area that desperately need(ed) it.
Last edited by jp on Tue Aug 18, 2020 02:40, edited 1 time in total.

User avatar
v-rob
Developer
Posts: 792
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: Formspecs, The Past, Present, and Future: An Overview

by v-rob » Post

I do think that getting a base down is important, and that's what the mesh[] PR does. Honestly, complicated controlled interactions like spinning, rolling, panning, etc. would be best handled by the mod itself with the mesh[] element only handling the necessary rendering details. #8679 combined with dynamic formspecs would achieve this goal beautifully.
GUI Core Developer | My Best Mods: Bridger - Slats - Stained Glass | To contact me, send a PM

User avatar
Pyrollo
Developer
Posts: 385
Joined: Mon Jan 08, 2018 15:14
GitHub: pyrollo
In-game: Naj
Location: Paris

Re: Formspecs, The Past, Present, and Future: An Overview

by Pyrollo » Post

Hi V-Rob,

Thanks a lot for all your work on formspecs. It really moves things forward.

I’m not active on code these times but still thinking a lot. Code refactoring is one of my concerns. Specially about formspecs and horribly huge guiFormSpecMenu.cpp file. The first two though I had about this topic are :
  • Put Formspecs element class files (guiButton.*, guiScrollBar.*, ...) and windows class files (guiKeyChangeMenu.*, guiConfirmRegistration.*, …) in two separate dirs. Having them together is confusing, specially for newcomers.
  • Remove all parse* functions (parseButton, parseScrollBar, ...) from guiFormSpecMenu.cpp and put them in element class. And why not, have a sort of registry of element names and corresponding class (1).
I also think we should get rid of separate lists of elements (m_backgrounds, m_tooltip_rects, m_clickthrough_elements, …) that are drawn in specific ways. Instead a proper z-indexed list should do the job.


(1) Thinking a bit more, this idea is not optimal. Having formspec string parsing stuff in element class would bind rendering stuf to formspec string parsing. Bind parsing to rendering is never good. Maybe we will develop something else than formspec string in a future version.

Trying to find something smart, came in mind the idea that HUD and Formspecs should be managed the same way. Lot of elements are common : text, itemimages, minimap (when #9079 merged), …
It’s just a matter of sizing, positionning and when to display. A same text element type can be displayed :
  • In formspec, with position reletive to its parent;
  • In HUD as static element, with position relative to screen;
  • As Waypoint HUD, with position relative to a map coordinate;
At the end, once positionning and sizing is done, drawing is the same.

Sorry if this post is a bit messy, I’m not that good at putting ideas in words.
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]

User avatar
v-rob
Developer
Posts: 792
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: Formspecs, The Past, Present, and Future: An Overview

by v-rob » Post

I only have a general plan of the parsing parts of refactoring planned out. I don't have implementation details worked out yet fully (Rubenwardy has made a chart of his proposal [issue #9358 comment] which I will probably base mine off of in part), but I'll share my idea as far as I have it.

1) Separate inventory lists. This entails finishing #10222 and any subsequent PRs. This wouldn't have been my first choice to start working on, but it's already there, so I'll finish it. Unfortunately, this will take a while because I wasn't the one who created the PR, so I have to familiarize myself with it and suchlike.

2) Move everything into parserData as possible that only has to do with parsing. Things that don't have to do with parsing will be moved out. This will isolate all parsing things in a specific place so that all parsing can be moved out of GUIFormSpecMenu in the next refactor.

3) Move just the parsing code out into new classes. Currently, the parseSomeElement functions both parse and create the element. I will move only the parsing out, not the element creation. The reason why is that it isn't the parsing code's job to make the element itself, only to parse into something that can be used more easily.

Rubenwardy attempted a refactor earlier which tried to move the entire parsing functions out including the element creation code. I'm convinced that this isn't a good idea because we would have the same problems, just in a different class. Eventually, we'd have to move the element creation code again, so it's extra work for no benefit. (I'm not trying to insult or diminish Rubenwardy's effort -- it was a valiant one, but I think it was partly misguided in this one respect.)

Anyway, the parser will parse the entire formspec string, and then it will hand this parsed stuff back to GUIFormSpecMenu, which will proceed to create the elements.

The parsing code will be designed with the possibility of JSON serialization to replace the current formspec string syntax in the future. The JSON would be generated from whatever format is decided upon in #6527. I'm convinced that the formspec string needs replacement if dynamic formspecs are ever to be realized. There are too many problems with the current format to allow it to work -- too many forward references, element cross-dependencies, helper elements, and whatnot.

I don't know exactly what the parsing code will spit out, but I guess it'll look somewhat like what StyleSpec does right now. The parsing code will automatically handle forward references and cross-dependencies itself, e.g. applying scrollbaroptions[] to all following scrollbars and styling to all applicable elements so that GUIFormSpecMenu can create elements without having to worry about formspec syntax whatsoever.

These three refactors will solve many problems right away, but there are things to yet be considered, e.g. the prolific FieldSpec, where element creation should be moved, etc. I don't know about these yet, but I expect to figure them out after these refactors come to pass.

So, when will this happen? I don't think step 1 has any dependencies come to think of it, so I might be able to start that very soon, but steps 2 and 3 need all PRs that modify GUIFormSpecMenu's parsing code in any regard to be completed and merged. I'll add which PRs are dependencies to these second and third refactors next to the priority numbers.
GUI Core Developer | My Best Mods: Bridger - Slats - Stained Glass | To contact me, send a PM

User avatar
GreenXenith
Member
Posts: 1329
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
IRC: GreenXenith
In-game: GreenXenith
Location: The singularity
Contact:

Re: Formspecs, The Past, Present, and Future: An Overview

by GreenXenith » Post

jp wrote:
Tue Aug 18, 2020 00:47
you should be satisfied that this PR exists in the first place
My intent was not to offend or to belittle your work, but you do not get to tell me whether or not I am satisfied with a feature. As a modder, I do not find it to have enough features to be useful (yet).
Then it will be possible to create a 3D game nested in another 3D game
While I am the kind of person to do something silly and absurd like this, I seriously don't think this is something very many people care about, nor should it be. But on this point, a 3D game in a 3D game requires much more mesh control than the PR currently provides.

I am aware that it is just groundwork, but that does not change the fact that in the current state it is not terribly useful for much other than extremely simple player previews. I simply wanted to state the features I believe are needed to make it more generally useful, and I have done so.
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.

User avatar
v-rob
Developer
Posts: 792
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: Formspecs, The Past, Present, and Future: An Overview

by v-rob » Post

Well, things have just changed drastically for the better. I expect to make some more changes around here, because I have just been elevated to core developer! It's all happened rather fast; I didn't really expect to become one, not this soon at least. (I still don't quite believe it myself yet, but here it is: https://github.com/orgs/minetest/people)

Anyway, this means that PRs can be merged if I and one other developer approve. For my own PRs, I only need one other dev since I am the first. As the bulk of formspec PRs are my own, this should speed things up quite a bit, I expect. In fact, two PRs have been merged already (#10144 and #8678)

This also means that I can update the much-neglected official formspec priority list (https://github.com/minetest/minetest/projects/6), which is my first order of business. Then, it's on to reviewing PRs and getting things done!
GUI Core Developer | My Best Mods: Bridger - Slats - Stained Glass | To contact me, send a PM

User avatar
v-rob
Developer
Posts: 792
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Formspecs, Hopefully to Just be the Past Soon

by v-rob » Post

I'm afraid this list has become all too obsolete. Not that there are many new formspec PRs, but plans have completely changed. The former main idea of refactoring is probably not going to be done. So here's what's been going on: for the past few weeks, I've been experimenting with CSM drawing to the screen, i.e. giving Lua the ability to draw rectangles, images, text, item images, and whatnot to the screen. After extensive testing, I've discovered that this is almost no slower than the speed of formspecs.

So, instead of refactoring, my master plan is to put all formspec work on hold except for highly anticipated features (like model[]) and critical bugfixes, and then to develop a new GUI system in Lua. Finally, after completion, a new SSM API will be developed to interface with the CSM GUI system, and a compatibility layer will be created for formspecs. Then, all that nasty existing formspec code will be thrown out the window, never to be seen again (yay!) and most of the formspec issues will be closed (that's quite a few).

There are many advantages to this Lua-side GUI idea:
  • Developing in Lua is much easier and faster than in C++, so this will make the initial development and later feature development much faster.
  • Everything can be developed from the ground up with features in mind from the start instead of jury-rigging every new feature onto the old system. Things like proper layouting and dynamic editing will be present from the beginning.
  • CSM can take advantage of the new system, defining its own elements with all the benefits of every other element.
  • Anything in CSM, not just the GUI, can take advantage of full mouse and key events (and hopefully touchscreen and joystick events soon), offering just as much as Irrlicht itself (and, well, a little more since Irrlicht's going to need a bit of patching to get proper touchscreen events everywhere).
  • The HUD and GUI can be unified into a single underlying system with similar APIs. In addition to the obvious benefits, making custom Android controls will also be a possibility in the future.
This all sounds far-fetched, but I think it's possible, and I'm devoting most of my development time to getting it to be a reality.

So, how far out is this? I don't know. I personally love the idea, and the other core devs seem to have no objections. ATM, I'm working on the C++ drawing and event API, fleshing it out before working on anything else. At the same time, I'm creating a TODO list for a lot of the internal things than need remedying before that can be completed. Once I get all that done, I'll try to get it merged into the engine before working on the actual Lua GUI code.

If you want to see the PR and API details in its current state, have a look at #10524.
GUI Core Developer | My Best Mods: Bridger - Slats - Stained Glass | To contact me, send a PM

User avatar
Linuxdirk
Member
Posts: 2667
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Formspecs, The Past, Present, and Future: An Overview

by Linuxdirk » Post

This looks quite wonderful! It's about formspecs, but understand I correctly that minetest.register_on_event() basically allows mods to get arbitrary input events and handle them as they like? Or does that only affect CSM (which was a mistake to release in the current state)?

User avatar
v-rob
Developer
Posts: 792
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: Formspecs, The Past, Present, and Future: An Overview

by v-rob » Post

Linuxdirk wrote:
Mon Oct 19, 2020 23:30
This looks quite wonderful! It's about formspecs, but understand I correctly that minetest.register_on_event() basically allows mods to get arbitrary input events and handle them as they like? Or does that only affect CSM (which was a mistake to release in the current state)?
It does, at present, only affect CSM because the client is where events come in and where everything is drawn, so the client is where the GUI code will be. But adding something to send events to the server sounds like a good idea to me (although I have no expertise with packets and whatnot, so it probably won't be me working on it, at least not any time soon). Drawing directly from the server will never work for obvious reasons, though :)
GUI Core Developer | My Best Mods: Bridger - Slats - Stained Glass | To contact me, send a PM

User avatar
Linuxdirk
Member
Posts: 2667
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Formspecs, The Past, Present, and Future: An Overview

by Linuxdirk » Post

v-rob wrote:
Tue Oct 20, 2020 00:58
It does, at present, only affect CSM
So in the end we will have one awesome, modern system allowing random key combinations and one input system that chokes on non-QWERTY input :D

But what’s the state of CSM in general? The information available from the dozens of issues and discussions regarding CSM is that CSM in it’s current form was never intended nor planned. It’s a by-product from the time when some devs worked on SSCSM.

I hope your work does not force CSM to be enabled in the client in order to get what you described.

User avatar
v-rob
Developer
Posts: 792
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: Formspecs, The Past, Present, and Future: An Overview

by v-rob » Post

Linuxdirk wrote:
Tue Oct 20, 2020 08:25
I hope your work does not force CSM to be enabled in the client in order to get what you described.
In the present state, it is a CSM API so it does require CSM to be enabled. When it's used to make GUIs, then that specific part of the client builtin will have to be loaded separately, regardless of whether the rest of CSM is enabled. We can't have the HUD, GUI, chat, etc not work because someone doesn't turn on the entire CSM API :) (User: Hey, why isn't the main menu showing up?! Dev: Yeah, um, you need to enable CSM for it to work. Ha ha.)

As for sending events to the server, that would bypass the client builtin completely by sending Irrlicht's internal event over the network with minimal serializations, and then the server would run the same C++ -> Lua code on it that the client does, just for SSM instead of CSM. Not hard at all as long as I can figure out what part of the networking code I need to change.
GUI Core Developer | My Best Mods: Bridger - Slats - Stained Glass | To contact me, send a PM

User avatar
Andrey01
Member
Posts: 2442
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Formspecs, Hopefully to Just be the Past Soon

by Andrey01 » Post

v-rob wrote:
Mon Oct 19, 2020 22:46
I'm afraid this list has become all too obsolete. Not that there are many new formspec PRs, but plans have completely changed. The former main idea of refactoring is probably not going to be done. So here's what's been going on: for the past few weeks, I've been experimenting with CSM drawing to the screen, i.e. giving Lua the ability to draw rectangles, images, text, item images, and whatnot to the screen. After extensive testing, I've discovered that this is almost no slower than the speed of formspecs.

So, instead of refactoring, my master plan is to put all formspec work on hold except for highly anticipated features (like model[]) and critical bugfixes, and then to develop a new GUI system in Lua. Finally, after completion, a new SSM API will be developed to interface with the CSM GUI system, and a compatibility layer will be created for formspecs. Then, all that nasty existing formspec code will be thrown out the window, never to be seen again (yay!) and most of the formspec issues will be closed (that's quite a few).

There are many advantages to this Lua-side GUI idea:
  • Developing in Lua is much easier and faster than in C++, so this will make the initial development and later feature development much faster.
  • Everything can be developed from the ground up with features in mind from the start instead of jury-rigging every new feature onto the old system. Things like proper layouting and dynamic editing will be present from the beginning.
  • CSM can take advantage of the new system, defining its own elements with all the benefits of every other element.
  • Anything in CSM, not just the GUI, can take advantage of full mouse and key events (and hopefully touchscreen and joystick events soon), offering just as much as Irrlicht itself (and, well, a little more since Irrlicht's going to need a bit of patching to get proper touchscreen events everywhere).
  • The HUD and GUI can be unified into a single underlying system with similar APIs. In addition to the obvious benefits, making custom Android controls will also be a possibility in the future.
This all sounds far-fetched, but I think it's possible, and I'm devoting most of my development time to getting it to be a reality.

So, how far out is this? I don't know. I personally love the idea, and the other core devs seem to have no objections. ATM, I'm working on the C++ drawing and event API, fleshing it out before working on anything else. At the same time, I'm creating a TODO list for a lot of the internal things than need remedying before that can be completed. Once I get all that done, I'll try to get it merged into the engine before working on the actual Lua GUI code.

If you want to see the PR and API details in its current state, have a look at #10524.
Wow! It`s so nice to hear all that! You really have amazing ambitions for MT! Perhaps, are you going to jump on an other 3D engine that adapted for Lua? Also, currently I`m preparing a new feature for the old formspec system, but does it make sense to embed any new ones to that now if you have already got involved into making a new GUI? Just I`d not like to waste a time and effort...

User avatar
v-rob
Developer
Posts: 792
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: Formspecs, The Past, Present, and Future: An Overview

by v-rob » Post

Andrey01 wrote:
Sat Oct 24, 2020 20:00
Also, currently I`m preparing a new feature for the old formspec system, but does it make sense to embed any new ones to that now if you have already got involved into making a new GUI? Just I`d not like to waste a time and effort...
It's your call, really. There's no telling how long this all will take. If you're willing to wait any amount of time from a few months to a year or two, then by all means wait. But it might be better to just work with formspecs for now and transition later after the new stuff is done. Compatibility with formspecs won't be dropped regardless.
_______________________________________________________________________

I don't feel like coding at the moment, so here is my concept for the new GUI/HUD API so far. First off, this is the client API, but I intend to make the server API reflect the client API as much as possible, but some features just won't be possible, e.g. custom elements, without SSCSM.

Everything will be in the ui namespace to keep it together outside of the minetest namespace. UI is a more general term, and it encompasses both GUI and HUD.

Every element will inherit from the base class ui.Element. This will have a number of properties (some of these may not actually be implemented, and others will probably be added):
  • id: The unique internal ID of the element, different for each individual element
  • rect: The rectangle with layouting units (more on that later)
  • draw_rect: The rectangle in pixels for drawing the element
  • parent: A reference to the parent element
  • children: A table of children of this element
  • sub_elements: A table of elements that are sub-elements but not actually children, e.g. the text on a ui.Button might be a ui.Label.
  • visible: If the element should be drawn and receive events
  • disabled: Whether the element is disabled
  • noclip: Should the element be clipped to the parent element?
  • name: The user-provided unique name for the element, like HTML id
  • class: A table of the classes for the element, like HTML class
  • type: The type of the element, e.g. "ui.Element" or "ui.Button"
The base class will also have plenty of methods. Some of these are:
  • draw(dtime, drawer): Called every frame to draw the element
  • on_event(event): Called if an event occurs and the element has focus
  • clone(): Returns a copy of the element
  • move_after/before(other): Moves this element after or before another
  • remove(): Removes this element
  • get_element_by_id/name/class/type/etc(thing): Gets an element that is the child of this one by some attribute.
  • get_element_at_position(pos)/(x, y): Gets the topmost element at the given screen position
  • set_rect(rect)/(x, y, w, h): Sets the rectangle with layouting units. This internally calls resize.
  • resize(): Resizes the element and all children/sub elements because the rect changed or the screen/parent element resized.
  • add/remove_class(class): Adds or removes a class
There will also be event handler callbacks a lot like HTML+JavaScript event handlers, e.g. on_click, on_mouseover, on_mouseout, etc, with some differences.

Lastly, elements will have a fancy constructor and the bare-minimum constructor. Bare-minimum is probably a lot like ui.Element(parent, rect, label, name) where all parameters are optional. The fancy constructor, rather XML/HTMLish, would look more like this:

Code: Select all

local elem = ui.Element {
    rect = {x=0, y=0, w="1w", h="1h"},
    name = "cool_element",
    
    ui.Button {
        rect = {w = "100p", h = "20p"},
        name = "btn_1",
        class = {"btn", "red"},
        label = "Some Button"
    }
    -- More child elements go here
}
Actual elements will have extra properties, methods, and callbacks, of course. ui.Element is just the bare minimum.

As mentioned above, rect is a rectangle with layouting units. This is essentially CSS units that look like "<number><unit>". These would be p (pixel, or px), f (proportional to font height, or em), w h > < (proportional to parent width, height, greater dimension, or smaller dimension, like a combination of % with vx, vy, vmax, and vmin). I have not decided whether there should be something akin to formspec coordinates. I also haven't decided the default unit if a unitless number/string is provided. Lastly, units can be combined with a + symbol, e.g.0.5w+20p.

What elements will we have? Here's a non-comprehensive on-the-moment list:
  • ui.Element doubles as a simple container.
  • ui.Scroller is a container that scrolls when elements overflow outside of the boundaries, or alternatively, the width/height can be explicitly set.
  • ui.Sizer arranges child elements itself, like a vertical or horizontal sizer or a grid
  • ui.Button is the all-purpose button. No need for button, image_button, and item_image_button
  • ui.Label is just that, a static label. Optional word wrapping
  • ui.Input is an input text box, single or multiline, word wrapping and not.
  • ui.ScrollBar is a scrollbar, but can also be used like a slider
  • ui.DropDown is a dropdown with optional textual input
  • ui.CheckBox is a checkbox and can also be a radiobutton
  • ui.Tabs and ui.ProgressBar are what they sound like
  • ui.List is a simple table or textlist. If one wants more options, use a ui.Element with ui.Button children
  • ui.HyperText is like the formspec hypertext. This is one of the last elements that will be made because of the complexity
  • ui.Inventory is an inventory list.
  • ui.Minimap, ui.HotBar, and ui.ChatBox are the probable equivalents of their HUD counterparts. Statbars will probably be ui.ProgressBar's.
Really, I can add all sorts of goodies to this list once the base API gets in place. Many of these won't be very hard at all. The hardest are likely to be things that deal with lots of text, like multiline ui.Input and ui.Hypertext.

Styling. Well, I really don't know how this should work yet, and I'm quite open to suggestions.

The base that does a lot of the management is ui.Environment. This manages a lot of the stuff like where to make events go, which element holds the focus, etc. Not very interesting.

So, how will things like handling both the HUD and GUI and even things like multiple GUIs work? Well, the ui.Environment, which is also the root element, will have a number of built-in child elements which will be ui.Elements as large as the entire screen, which are, in essence, the replacement for many of the z_index positions. These elements are so important that they will have global variables associated with them for easy adding to them. These might be something like ui.effects (for graphical effect elements), ui.hud, and ui.gui, although more specific. These are not for inserting single things like ui.Button (although they can be used that way), but a ui.Element to hold everything (a lot like formspec size[] make a box for everything).

And how will the HUD work in a GUI system? Actually, it's going to literally be a GUI, but when in game, you can't interact with either the HUD or the GUI if any GUIs are still open (they shouldn't, but they wouldn't be interactable even if they were). So yes, you could put a button on the HUD. That isn't useful on desktop systems, but with touchscreen systems, this means that you could make custom control buttons on the HUD.

How do you make custom elements? Pretty easily. There will probably be a gui.inherit(base_class) function that returns an inherited class from another element (or ui.Element by default), and then you just add or override methods in the returned class. As for how to make the custom elements, looking at some of the built in ones will be the easiest method to learn how.

Anyway, I need to wrap this up as it's getting long. But I hope I've clarified somewhat what the API could quite possibly look like. Like always, suggestions, criticisms, and questions are quite welcome.
GUI Core Developer | My Best Mods: Bridger - Slats - Stained Glass | To contact me, send a PM

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest