Simplify - simple Event-driven GUI library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
mastermarkus
Prole
Posts: 10
Joined: Sun Jun 25, 2017 5:29 pm

Simplify - simple Event-driven GUI library

Post by mastermarkus »

Repository: https://github.com/mastermarkus/simplify
Documantation: https://github.com/mastermarkus/simplify/wiki

Simplify is a simple Event-driven GUI library for Löve2D. With this library you can simply create GUI elements and listen for mouse and keyboard input. This library also support's ZIndex drawing order system, where you can specify the display order of GUI elements.



Quick example:

Code: Select all


function love.load()
    simplify = require('simplify')

    local testbutton = simplify:TextButton(200,100)--size paramters
    --testbutton:SetSize(500,500) you can also set size at any time with :SetSize()
    testbutton:SetTextXAlignment("Center")-- "Left", "Center", "Right"
    testbutton:SetTextYAlignment("Center")-- "Top", "Center", "Bottom"
    testbutton:SetPosition(300,300)
    testbutton:SetText("Hello world!")
    testbutton:SetTextColor(0,0,255)--Blue text ,you cant set alpha with this method directly
    testbutton:SetBorderSizePixel(5)
    testbutton:SetBorderColor(255,0,0)
    testbutton:SetBackgroundColor(70,70,70) -- grey background
end

Listening for mouse events

Code: Select all


 testbutton.MouseButton1Down:connect(function(x,y)--return where mouse clicked on button
        print("Mouse Clicked at X: "..x.." Y:"..y)
    end)

    testbutton.MouseEnter:connect(function(x,y)--return where mouse entered on button
        print("Mouse Enteres at X: "..x.." Y:"..y)
    end)



The main purpose of this project is to make development of Gui easier and more fun. Right now, there's no documentation, but it's pretty straightforward, by simply looking at "Simplify.lua" main file and other class modules.

In future i plan to add Gui groups. Lets say you have minimap or inventory UI in your game and you want them to always to stay on top of
other Guis, well that's the point of Gui groups,they have their specific MasterZIndex and then children are individual GUI elements, that also have regular ZIndex property.

Because i do this all myself, it takes a lot of time and i would be glad if you are willing to contribute to the repositiory bug fixes, new features etc...
Last edited by mastermarkus on Mon Jul 03, 2017 7:47 pm, edited 3 times in total.
Shadowblitz16
Citizen
Posts: 73
Joined: Wed Oct 28, 2015 11:18 pm

Re: Simplify - simple Event-driven GUI library

Post by Shadowblitz16 »

This is cool I have tried to develop GUI libraries in gamemaker in the past however I'm not very good at it.

one thing you might want to do early on though is support tiling and scaling for 9slice sprites
this would allow people to add sprite skins to their gui's

also I would help but looking at the source it looks like you know far more in lua then i do, I would probably mess it up.
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: Simplify - simple Event-driven GUI library

Post by Beelz »

Not too shabby, athough I do want to point out one thing... In lines 99-106 of 'Simplify.lua' you overwrite the Love callbacks... While not too much of an issue for a personal project, doing so in a library you're releasing to the public is another story. That said, what you should do is either document that the end user needs to forward the callbacks, or monkey-patch it(preferably the former). Below is an easy way to monkey patch it, if that's the route you take.

Code: Select all

-- if love.update is already defined we make a local copy, else use anonymous function
local love_update = love.update ~= nil and love.update or function() end

-- overwrite love.update
function love.update(dt)
	-- do stuff
	
	-- call the original love.update the end user created
	-- or an empty function, if they didn't
	love_update(dt)
end

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Simplify - simple Event-driven GUI library

Post by Nixola »

Monkeypatching is not a good thing. The user could overwrite the callbacks at any moment, breaking the library.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
mastermarkus
Prole
Posts: 10
Joined: Sun Jun 25, 2017 5:29 pm

Re: Simplify - simple Event-driven GUI library

Post by mastermarkus »

Beelz wrote: Sun Jul 02, 2017 1:45 am Not too shabby, athough I do want to point out one thing... In lines 99-106 of 'Simplify.lua' you overwrite the Love callbacks... While not too much of an issue for a personal project, doing so in a library you're releasing to the public is another story. That said, what you should do is either document that the end user needs to forward the callbacks, or monkey-patch it(preferably the former). Below is an easy way to monkey patch it, if that's the route you take.

Code: Select all

-- if love.update is already defined we make a local copy, else use anonymous function
local love_update = love.update ~= nil and love.update or function() end

-- overwrite love.update
function love.update(dt)
	-- do stuff
	
	-- call the original love.update the end user created
	-- or an empty function, if they didn't
	love_update(dt)
end

Alrighty thanks for pointing that one out, i fixed the problem.
mastermarkus
Prole
Posts: 10
Joined: Sun Jun 25, 2017 5:29 pm

Re: Simplify - simple Event-driven GUI library

Post by mastermarkus »

I now added detailed Documentation for all the available Gui elements.
Post Reply

Who is online

Users browsing this forum: EdWordy and 6 guests