- Notifications
You must be signed in to change notification settings - Fork14
GUI library for ocaml based on SDL2
License
sanette/bogue
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Bogue is an all-purpose GUI (Graphical user interface) library forocaml, with animations, written from scratch inocaml
, based onSDL2.
- Can be used to add interactivity to any program.
- Can work within an already existing event loop, for instance to addGUI elements to a game.
- UsesGPU acceleration (thanks to theSDL2 renderer library),which makes it quite fast.
- Can deal with several windows.
- Bogue isthemable, and does not try to look like yourdesktop. Instead, it will look the same on every platform.
- Graphics output is scalable (without need to recompile), and henceeasily adapts toHi-DPI displays.
- Predefined animations (slide-in, fade-in, fade-out, rotate).
- Built-in audio mixer.
- Works with mouse, touchscreen, and even TAB focusing
Programming withbogue is easy if you're used to GUIs with widgets,layouts, callbacks, and of course it has a functional flavor. It usesThreadswhen non-blocking reactions are needed.
openBoguelet()=Widget.label"Hello world"|>Layout.resident|>Bogue.of_layout|>Bogue.run
Widgets are the building bricks, responsible for graphic elements thatrespond to events (mouse, touchscreen, keyboard, etc.).
For a more "functional" use, they can be "connected" instead ofreacting with callbacks (see examples).
- boxes with decorations (round corner, border, shadow, gradientbackground, image pattern)
- check box
- push button (with labels or images)
- rich text display (bold, italics, underline), any TTF font can be used.
- image (all usual formats, including SVG)
- slider (horizontal, vertical, or circular)
- text input with select and copy-paste
- SDL area for free drawing with the whole SDL Renderer API
widgets can be combined in various ways into layouts. For instance, acheck box followed by a text label is a common layout.
Several predefined layouts are available:
- sliders (horizontal, vertical, circular). Can be used as progress bars
- scrollable lists (that can easily handle a large number of elements,like one million)
- multi-column tables with sortable columns
- multiple tabs with slide-in animation
- modal popups
- various menus (menu bar, drop down menus with submenus)
- drop-down select lists
- radio lists
- automatic tooltips can be attached to any element
- file chooser
Layouts can beanimated (slide-in, transparency, rotation). Alllayouts can be automaticallyresized when the user resizes thewindow.Timeouts are available to execute arbitrary actions aftera delay.
demo, tab1 | demo, tab2 |
---|---|
![]() | ![]() |
Seehere for the source codeof this demo.
It's the easiest way unless you want to try out the developmentversion.
opam install bogue
That's it.But, if you want to stay in sync with the latestdevelopement, you can directly "pin" the github repository:
opam pin add https://github.com/sanette/bogue.git
(Then update/upgrade opam). And this can easily be undone with
opam unpin https://github.com/sanette/bogue.git
Bogue needs the SDL2 library. In general you already have itinstalled, or, if everything goes smoothly, it will be installedautomatically withopam install tsdl
.However,tsdl
is not ableto automatically pick up the right version corresponding to your SDL2version. You might have to tellopam
the version you need: forinstance for Bogue 20240928 on Ubuntu 20.04 you shouldopam install tsdl.1.0.0
, because the more recenttsdl.1.1.0
requiresSDL >= 2.0.18
which you probably don't have on your system.
Seehttps://github.com/dbuenzli/tsdl/blob/master/CHANGES.md
You need a workingocaml
installation withopam
, see theocaml doc. Then, make sureyou havedune
,tsdl
,tsdl-image
andtsdl-ttf
:
opam install dune tsdl tsdl-image tsdl-ttf
Download thegit archive,unzip it, cd into thebogue-master
dir, and then:
dune buildopam install .
https://ci.ocamllabs.io/github/sanette/bogue
It's good to first have a look at Bogue'sgeneral principles.
You can also directly try thetutorials.
The public API can be foundhere.
You should first try aminimal example.
Theexamples
directory contains more sophisticated examples. If youinstalled thebogue
package withopam
(as described above), theseexamples are available via theboguex
program. For instance, runexamples 34 and 41 by:
boguex 34 41
Typeboguex -h
to have the list of all examples.
Seehere.
About
GUI library for ocaml based on SDL2