Hi!
I've been working lately on an expansion of SFML in C++ intended to make the process of creating and managing UI layouts easier. It's not a full GUI, but a set of classes and methods aimed towards helping you make your own according to the needs of your game/application.
While I was starting the development of a game a few months ago, I realised that some of the functionality I needed to implement was general enough so it could be useful for reuse in future projects, so I decided to create a stand-alone library expanding SFML in the ways I needed for my own layouts (and other ways that I could potentially need in future projects). Because it's usual when developing a game to create our own objects (as opposed to limiting ourselves to those offered by SFML and other libraries), I deemed it best to make the library heavy on polymorphism at its core, so it could be further expanded with minimal extra code.
The default classes in SFML_Layout implement:
- An easy way of handling position, size, and alignment of layout elements (including nested layouts).
- Multiple predefined layout distributions: horizontal, vertical, table, and the more customisable free layout.
- Management of sprites as element backgrounds. Backgrounds can have their own alignment inside their frame, and one of three distinct drawing modes: crop, adjust to fit the frame, or fill the frame by tessellation (cropping on the borders if needed). The chosen mode can be different for each axis.
- A sprite element: a layout element intended to have a sprite as its content. Until I write a detailed guide about that, this class can be easily used as an example on how to expand the library in order to create custom elements.
- An integrated event system. Elements can have different events associated to them, which in turn contain pointers to condition and effect methods designed by the user (although a couple of commonly used conditions are included in the library). Those methods can accept any number of arguments of any type, which can be provided in different ways.
- An element handler class which allows grouping elements together in order to trigger events simultaneously for all of them (for instance, activating all events labelled as "onClick" for a series of layout elements, with their conditions checking that the mouse cursor is over their associated element).
- Other layout-related logic, like the depth management for different layout elements, their visibility, or the number of slots in a layout. Elements and layouts can also be easily cloned and destroyed.
- For many functions, two versions exist: one applying only to the element or layout itself, and another one applying recursively to all nested layouts and elements.
In addition to the library itself (layout.hpp, layout.cpp, SFMLLayout.hpp, SFMLLayout.cpp), the repository also contains:
- example.cpp: a short program illustrating some of the functionality built in the library. It consists of a simple sprite viewer, allowing to switch between a list of sprites with "Previous" and "Next" buttons, and a "Close" button to quit. Some screenshots here: http://imgur.com/a/3C7wo#0.
- Assets folder: image files used in example.cpp. One of the images was borrowed from Deviantart, so there is also a text file linking to the source.
I've done my best with the in-code documentation, but even with that and the example it may still be a bit tricky to take full advantage of the library without thoroughly understanding it. At the moment I'm working on a detailed guide on how to use and expand SFML_Layout, but until then (and also afterwards, I guess) you can contact me for any doubt/bug report/request/quarrel you have about it here in the comments, or through e-mail at
sergi (at) protonmail (dot) ch.
Link to repository:
https://github.com/SergiSalvadorLozano/SFML_Layout.
Latest release:
https://github.com/SergiSalvadorLozano/SFML_Layout/releases/tag/v1.0.1 (2014/08/10).