Skip to content
/ sfw Public
forked from xparq/sfw

sfw::GUI -- a descendant of Alexandre Bodelot's's sfml-widgets

License

Notifications You must be signed in to change notification settings

dawei-wang/sfw

 
 

Repository files navigation

Build

sfw::GUI - A fork of "SFML Widgets", a small & simple SFML-based GUI

Original (upstream) author: Alexandre Bodelot [email protected]

License: MIT License (See the LICENSE file.)

Changes to the original:

  • Adapted to the pre-3.0 ("master") SFML API
  • Windows/MSVC build added
  • Compiling as C 20 now (to embrace recent C features; SFML3 is C 17 already)
  • Richer, more flexible API, bugfixes, improvements to existing widgets etc.
  • Reshuffled source tree (to allow growth & to help integrating into other projects)
  • Default quick-start assets included (and removed the non-free ones from the demo)
  • Auto download & setup the latest SFML-master lib (mostly for the GitHGub workflow)

For other (both planned and completed) changes see the issues!

Quick Summary

  • Small package with no external dependencies (beyond SFML & std::)
  • Simple, straightforward API
  • Spritesheet-based visuals: a single, small image file to customize widget styles (like box borders/corners etc.)
  • Simple callbacks: optional lambdas (or std::functions) triggered on important user actions (only) (You can still derive from the widgets to override the other event handlers, too, of course.)
  • Easy layouts: automatically align content without the need to precalculate positions/sizes
  • No CMake. (Well, since I never got to learn it, now I just consider this a feature. ;) Use e.g. TGUI if you don't feel warm and cozy without CMake.)

screenshot

Build

GCC/CLANG:

  • Run make to build the library (lib/libsfw.a) & the demo (./sfw-demo).

MSVC (Windows):

  • Run nmake -f Makefile.msvc to build the lib (lib/sfw.lib) & the demo (./sfw-demo.exe).

(See the Makefiles for options. The MSVC variant is rather dumb yet!)

Use

  1. Integrate (via env. vars, or just copy) the include & lib dirs to your project. (Copy the asset dir, too, if you want to use the stock defaults.)
  2. #include "sfw/GUI.hpp".
  3. Setup theme config resources (like the styling texture image, default font etc.), customize default style properties etc.
  4. Create the top-level GUI manager object, connecting it to your SFML window, like: sfw::GUI myGUI(window); (or, typically with a customized config.: sfw::GUI myGUI(window, myConfig);)
  5. Add containers, widgets with ...->add(sfw::SomeWidget(...)), or if you prefer: ...->add(new sfw::OtherWidget) calls, set their properties (like callbacks) etc. (Note: widget objects will be created and deleted implicitly.)
  6. Pass events to the GUI (in your app's event loop): myGUI.process(event);.
  7. Draw the GUI (in your frame refresh loop; or the event loop in single-treaded apps): myGUI.render();.
  8. Have fun!

More...

  • a minimal example (or another, with a polling event loop)
  • a fairly comprehensive example: demo.cpp
  • the headers in the include dir, for an authoritative reference (they are easy to read)

About

sfw::GUI -- a descendant of Alexandre Bodelot's's sfml-widgets

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 95.7%
  • Shell 1.9%
  • Smarty 1.4%
  • Makefile 1.0%