I’m happy to announce a brand new version of Bogue, a GUI (Graphical User Interface) library entirely written in ocaml, using SDL2 for hardware accelerated graphics.
The doc can be found here, it will be enriched over time.
Install with opam install bogue
In addition to the library, this installs an executable boguex to showcase about 50 useful constructions, see boguex -h for the list.
Some screenshots of a demo compiled with the latest version:
Note that many widgets are not shown in this demo: tables, menus, drop-down select lists, knob buttons,… I will add more images to the doc when I have some time!
no, this is completely independent; At this point, bogue is an old-fashioned desktop-only GUI … no web… (this could evolve in the future, since SDL is supposed to work with webassembly)
There was a bug in the new installer that prevented loading the correct config file at startup
(only if you had never installed bogue before), thanks @nilsbecker for reporting. Before I upload a new opam version, it’s better to use the github version if you want to give it a try.
thanks. I have never tried this. In the game community (that often means MS Windows, unfortunately) people often ship their game along with the SDL dll. I suppose the same strategy applies in the linux world with flatpacks or snaps…
Looking at the dependencies, I noticed that you also wrote a binding to SDL_ttf.
I am wondering if it would be enough to provide a SDL-based reimplementation of the Graphics library (with exactly the same interface)? It could be a nice way to have a pedagogical graphical API which is just a front-end for a full graphical library.
Yes, I think it would be fairly easy.
Looking at the Graphics API, the only things that are not included in SDL+SDL_ttf+SDL_image
are graphics primitives like (filled) ellipses and (filled) polygons. One could write bindings to SDL_gfx (*) for these, but it’s more fun to program them directly in ocaml
So I’m just drawing circles, lines from a point to another and text.
Would it be possible to add a widget in which I could draw this kind of things to a Bogue window with other widgets ?
Yes, absolutely. The Box widget can contain an arbitrary SDL texture, and hence you may use all SDL drawing functions onto that texture. Unfortunately, this is not documented yet (simply because my strategy is to add to the .mli file only functions that are tested in examples). But I can add this to the next release
Sounds nice ! You could even release a standalone project that would only provide this API in a single window, as an alternative to graphics : that would be a godsend imo, because the api of graphics really is terrible
In fact, for this, using the already existing Bogue version, one can use Labels with a round background. This gives the following picture: it would just remain to implement lines…
open Bogue
module W = Widget
module L = Layout
let n = 15 (* number of discs *)
let radius = 20
let width = 800
let height = 600
let c = Draw.find_color "#e5b92c"
let disc_style = Style.(
create ~border:(
mk_border ~radius (mk_line ~color:Draw.(opaque c) ~width:1 ~style:Solid ()))
~background:(color_bg Draw.(transp c)) ())
let background = L.style_bg Style.(
of_bg (gradient ~angle:45. Draw.[opaque grey; opaque black]))
let fg = Draw.(opaque white)
let create_disc i (x,y) =
let w = 2*radius + 1 in
let bg = Box.create ~style:disc_style ~width:w ~height:w () in
W.label ~fg (string_of_int i)
|> L.resident ~background:(L.box_bg bg) ~x:(x-radius) ~y:(y-radius) ~w ~h:w
let random_center _ =
radius + Random.int (width - 2*radius),
radius + Random.int (height - 2*radius)
let area =
let box = L.resident (W.box ~w:width ~h:height ()) in
let centers = Array.init n random_center in
let discs = Array.mapi create_disc centers |> Array.to_list in
L.superpose ~w:width ~h:height ~background (box :: discs)
let board = Bogue.make [] [area]
let () = Bogue.run board
I’m not sure I understand what you have in mind. If you want to do graphics in a window with the SDL library, you can just import the tsdl, tsdl-image and tstl-ttf packages and you’re good to go.
In theory indeed you could make a horizontal line with a thin box and then use Layout.rotate.
but I think it make sense (for me) to propose a new, dedicated Line widget.
Hi! Can you point me to the documentation about setting up themes? When I do
$ boguex 0
I get
Loading Bogue 20220101 with config dir /home/rsmith/.opam/4.12.1/lib/bogue/../../share/bogue/themes/default
INFO: Using SDL 2.0.14
0 = Just a check button.
Fatal error: exception Failure("SDL ERROR: Couldn't open /home/rsmith/.opam/4.12.1/lib/bogue/../../share/bogue/themes/default/check_on.png")