--------------- Original first post ---------------
Not exactly next generation, I'm sorry. It's actually an imitation of a commercially available framework (for free). It will be robust. Adding to this framework is also systematic. Just subclass LoveUI.View and write your drawing and input handling code to create a new gui widget. Distributing input to various 'views' is systematic and formulaic. There is no overlapping, no mistakes; only one widget at a time can receive mouse/key inputs. And hopefully, it is simple to use, too.
So far there is not a single widget done but I have written the foundations. The LoveUI.View is slightly modified so you can actually see what is happening in the example.
What inspired me was my previous gui-lib and the past three months I spent playing with objective-C on the iphone. I looked at the old gui-lib code and it looked pretty old and needed to be redone, probably because of everything I've learnt in between.
I'm hoping, in the future, it'll come with not only buttons, textfields, dialogs, checkboxes, radiobuttons but also tables, multiline textviews, scrollable views and even more, or if I cannot do this, you can.
I'd like some comments on not only my code but also my comments in this example please! I got my first job offer in software (Yes, with low student pay, long hours, etc... :s) so I'd like to learn how to comment more 'professionally'.
Here's some example code:
Code: Select all
-- EXAMPLE.lua -- Just include LoveUI.lua like this: love.filesystem.require("LoveUI/LoveUI.lua") -- Setup a 'context' for your love app.: myLoveUIContext=LoveUI.Context:new(640,480); -- All LoveUI widgets you create will belong to this context's view. -- The Context passes on events from your love app to various views and widgets. -- Note that you're only supposed to have one context per love app. -- Plug the context to your event handlers in the load function: -- Automatically: function load() myLoveUIContext:plugin(); end -- Or Manually: function mousepressed(x, y, button) myLoveUIContext:mouseEvent(x, y, button, myLoveUIContext.mouseDown) end function mousereleased(x, y, button) myLoveUIContext:mouseEvent(x, y, button, myLoveUIContext.mouseUp) end function draw(dt) myLoveUIContext:display(dt) end -- Remember to re-plugin the context if you happen to be re-declaring these callback functions later on! -- Create Views, or subclasses of Views, eg. button, textfields, etc -- A View is a rectangular region on screen that, when subclassed by widget, displays images or text or both. -- They also receive mouse and key events. local aButton=LoveUI.Button:new(LoveUI.Rect:new(10,10, 128, 32)); local aView1=LoveUI.View:new(LoveUI.Rect:new(400,10,100,100)); --local aView2=LoveUI.View:new(LoveUI.Rect:new(10,10,80,80)); --local aView3=LoveUI.View:new(LoveUI.Rect:new(10,10,60,60)); -- Add the views to the context's contentView using the addSubview command. myLoveUIContext.contentView:addSubview(aView1); --myLoveUIContext.contentView:addSubview(aView2); myLoveUIContext.contentView:addSubview(aButton); aButton.action=function(sender) sender.color=love.graphics.newColor(0, 0, 255); end -- Views can have subviews of their own. -- Note that coordinates used to initialise the views are relative to the view's superview, not to the screen. --aView:addSubview(aView3);