Need advice on building React like framework for love2d
Posted: Wed May 02, 2018 6:46 pm
So for a while i have been searching for customizeable GUI libraries/frameworks but haven't found any that were consistent or that i liked. I want to be able to build every GUI element that i could imagine, design every part of it, add custom animations and events. I found this Javascript GUI/View library called "ReactJS" and i liked, how it handled data flow, it's component paradigm and how it forced you to write GUI code in consistent way and i got idea to build my own GUI framework. I want to build framework, where you are not limited by predefined GUI components, but you could write every GUI component yourself, add components together and be able to reuse components in other projects or other part of your game. All the existing Löve2d GUI libraries provide you with some predefined elements that give you some events and way to design them but it's usually very minimal and i would like to design mine from ground up.
NOTE:
The main purpose of this framework/library would not be to provide you with predefined GUI elements, but to provide you with basic building blocks and to force you to write code in specific organized way and make GUI components more reusable.
In short, how the framework would work:
The framework would revolve around "component" classes that are essentially just tables that have access to all love API(window, keyboard-events, mouse-events and other love API's including sound) but they would also have few of their own functions like render/draw that accepts some data how the GUI would be drawn(color-data, size, position and also your own custom data), it's main purpose would just be draw on the screen. It's kinda similar how most love2d state/scene manager libraries work, they hook to love2d events and you write your own logic into these functions.
1) How to nicely handle input?
Now the tricky part would be how to nicely handle user-input, checking if user clicked inside certain element, imagine writing user-input code for every GUI element separately, it's nightmare. I thought about providing some kind of building block's(rectangles, Text) that already handle all the user-input stuff, you could then build your Components out of these simple building blocks and not worry about doing these nasty inBound checks to see, whether mouse is inside certain region or not, it would also handle keyboard/controller and touch events you would just have to listen for the events.
Here's https://roblox.github.io/roact/guide/components/ Lua version of "ReactJS" called "Roact", i know it's for different game engine but the main idea remains the same.
NOTE:
The main purpose of this framework/library would not be to provide you with predefined GUI elements, but to provide you with basic building blocks and to force you to write code in specific organized way and make GUI components more reusable.
In short, how the framework would work:
The framework would revolve around "component" classes that are essentially just tables that have access to all love API(window, keyboard-events, mouse-events and other love API's including sound) but they would also have few of their own functions like render/draw that accepts some data how the GUI would be drawn(color-data, size, position and also your own custom data), it's main purpose would just be draw on the screen. It's kinda similar how most love2d state/scene manager libraries work, they hook to love2d events and you write your own logic into these functions.
1) How to nicely handle input?
Now the tricky part would be how to nicely handle user-input, checking if user clicked inside certain element, imagine writing user-input code for every GUI element separately, it's nightmare. I thought about providing some kind of building block's(rectangles, Text) that already handle all the user-input stuff, you could then build your Components out of these simple building blocks and not worry about doing these nasty inBound checks to see, whether mouse is inside certain region or not, it would also handle keyboard/controller and touch events you would just have to listen for the events.
Here's https://roblox.github.io/roact/guide/components/ Lua version of "ReactJS" called "Roact", i know it's for different game engine but the main idea remains the same.