sanette / bogue

GUI library for ocaml based on SDL2
http://sanette.github.io/bogue/Principles.html
Other
189 stars 15 forks source link
gui gui-library ocaml sdl widgets

Bogue bogue-icon

Bogue is an all-purpose GUI (Graphical user interface) library for ocaml, with animations, written from scratch in ocaml, based on SDL2.

Programming with bogue is easy if you're used to GUIs with widgets, layouts, callbacks, and of course it has a functional flavor. ​It uses Threads when non-blocking reactions are needed.

Hello world

open Bogue

let () =
  Widget.label "Hello world"
  |> Layout.resident
  |> Bogue.of_layout
  |> Bogue.run

Features

Widgets

Widgets are the building bricks, responsible for graphic elements that respond to events (mouse, touchscreen, keyboard, etc.).

For a more "functional" use, they can be "connected" instead of reacting with callbacks (see examples).

Layouts

widgets can be combined in various ways into layouts. For instance, a check box followed by a text label is a common layout.

Several predefined layouts are available:

Layouts can be animated (slide-in, transparency, rotation). All layouts can be automatically resized when the user resizes the window. Timeouts are available to execute arbitrary actions after a delay.

Screenshots

demo, tab1 demo, tab2
demo1 demo2

See here for the source code of this demo.

Videos

randomize, demo 1907

Installation

Using the opam package

It's the easiest way unless you want to try out the development version.

opam install bogue

That's it. But, if you want to stay in sync with the latest developement, 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

SDL2 troubleshooting

Bogue needs the SDL2 library. In general you already have it installed, or, if everything goes smoothly, it will be installed automatically with opam install tsdl. However, tsdl is not able to automatically pick up the right version corresponding to your SDL2 version. You might have to tell opam the version you need: for instance for Bogue 20240928 on Ubuntu 20.04 you should opam install tsdl.1.0.0, because the more recent tsdl.1.1.0 requires SDL >= 2.0.18 which you probably don't have on your system.

See https://github.com/dbuenzli/tsdl/blob/master/CHANGES.md

Building from sources

Prerequisites

You need a working ocaml installation with opam, see the ocaml doc. Then, make sure you have dune, tsdl, tsdl-image and tsdl-ttf:

opam install dune tsdl tsdl-image tsdl-ttf

Get the latest source

Download the git archive, unzip it, cd into the bogue-master dir, and then:

dune build
opam install .

CI

https://ci.ocamllabs.io/github/sanette/bogue

Documentation

It's good to first have a look at Bogue's general principles.

You can also directly try the tutorials.

The public API can be found here.

Examples

You should first try a minimal example.

The examples directory contains more sophisticated examples. If you installed the bogue package with opam (as described above), these examples are available via the boguex program. For instance, run examples 34 and 41 by:

boguex 34 41

Type boguex -h to have the list of all examples.

A minimal app using Bogue

See here.