flamendless / Slab

An immediate mode GUI for the Love2D framework.
MIT License
286 stars 25 forks source link

Menu, Window, file loading, and many other improvements #150

Closed MellowArpeggiation closed 1 year ago

MellowArpeggiation commented 1 year ago

A small subset of the more general changes I made to Slab for FUNG - cleaned up and brought back to the main repo. Strap yourself in:

File loading

The file dialog as it is now will return a string containing the path to the selected file, but expects you to bring in a whole 'nother library just to load that file using love library functions. Since Slab already has 90% of the lovefs implementation, I've added the file copy to it, which will copy the file to the love save directory as a temporary file, returning a love friendly path which can be directly input into the love library functions:

local fileDialog = slab.FileDialog({
    Type = "openfile",
    Filters = { { ".png", "Image files" } }
})

if fileDialog.Button == "OK" then
    local imageData = love.image.newImageData(slab.ToLoveFile(fileDialog.Files[1]))
end

Menus

Added a new Hint option for menu items, which can be used to tell the user available keyboard shortcuts

Screen Shot 2023-04-05 at 6 04 51 pm

Added menu and menu item padding to style options

Screen Shot 2023-04-05 at 6 07 40 pm

Windows

Added default window border to style options Added window title height to style options

Misc

Insert multiple newlines with NewLine Checkbox size now matches font size Listboxes now have a BG color, default transparent Button can be set to appear clicked (useful for toggles) Add init argument to prevent the cursor from being modified by Slab Add H option to Textf, aligns centered in the defined height Fix Textf not respecting explicit width Fix layouts completely ignoring borders (and causing overlaps with large borders!) Fix minimise/close button position and rendering when borders or title height is larger than default

flamendless commented 1 year ago

Awesome! Thanks for the improvements.

Just to be sure, there's no breaking changes to the API?

MellowArpeggiation commented 1 year ago

No breaking API changes, however I did leave a TODO for an API change from the Text option Pad to PadX/PadW for an eventual v1.

I also made a minor change to the behaviour of Textf when a W option is passed which may lead to unexpected behaviour, but I believe it’s much better aligned to what a developer would expect from the option