[ANN] Bogue, the OCaml GUI

Thanks @sanette for showing me how to achieve what I wanted with Bogue.

I tend to cling to my belief that a way to create new widgets ends up being needed, even if you proved me wrong in that particular instance. That being said, I must admit that web interfaces have been around for a while and there’s no way to add new HTML elements, so maybe I am in fact wrong.

2 Likes

Well, you can create custom HTML elements using Web Components, but at the end of the day they are composed of the built-in elements, so conceptually the same as Bogue.

1 Like

In html you have canvas which can be used as basically anything, is there something equivalent in bogue ?

I’m not sure if it is really comparable, but you have the Bogue.Sdl_area widget where you can draw whatever you want using SDL primitives.

3 Likes

I would say it is equivalent, and it probably allows to do anything :slight_smile:

Hello all,

I am discovering Ocaml and wanted to try the Bogue gui.
Frustratingly, many attempts have all led to the same error message: Segmentation fault.

Here is how I proceeded:
a) Environment:
MacBook Pro 2022 M2
MacOS 13.6.1
Ocaml 5.1.1
VS Code with OCaml Platform v1.14.1
b) Dune init project bog
c) Creation of local switch
d) Setting sandbox to local switch
e) Installation of the bogue package
f) Addition of “bogue” to the libraries entry in bin/dune
g) Replacement of main.ml content with minimal example:
open Bogue

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

h) Dune build
I get:
ld: warning: ignoring duplicate libraries: ‘-lSDL2’, ‘-lintegers_stubs’

i) Dune exec bog
I get:
Loading Bogue 20221112 with config dir …/bog/_opam/share/bogue/themes/default
zsh: segmentation fault dune exec bog

j) When I check installed packages to verify dependencies of bogue, I see that “directories” is not listed by opam
k) upgrade to the last bogue version with:
opam pin add GitHub - sanette/bogue: GUI library for ocaml based on SDL2
I get:
:arrow_down: retrieved directories.0.5 (cached)
⊘ removed bogue.20221112
∗ installed directories.0.5
∗ installed bogue.20231209
Done.
l) Dune build
I get:
ld: warning: ignoring duplicate libraries: ‘-lSDL2’, ‘-lintegers_stubs’
m) Dune exec bog
I get:
Loading Bogue 20231209 with config dir …/bog/_opam/share/bogue/themes/default
zsh: segmentation fault dune exec bog

All my apologies for the very long message, but I am really puzzled and certain that something is wrong in my procedure.

Many thanks in advance for any advise

you might have a bogus SDL library.
Could you remove all versions of SDL on your machine and try to reinstall one cleanly?

After several experiments, I managed to solve the issue by downgrading the Ocaml compiler version to 5.0.0. Bogue is not working with 5.1.1.

Could you open an issue on the compiler about this?

Bogue work fine work on my Mint 21.1 with Ocaml 5.1.1

Could you get the debug information:
BOGUE_DEBUG=true dune exec ./bog.exe

Hi. I think it would be great if you add documentation relating bogue with html and css.
I am not clear on how to add padding, margin kind of stuff to widgets. How to add a box around input widget. It would be easier for me to relate since I’m from web background. Thanks!

Hi, yes, more documentation is always a good idea! Feel free to contribute :wink:
Concerning margins, styling, etc. of course you’re not going to have something as powerful and flexible as html+css, but everything you mentioned is actually doable with Bogue.
The main idea is to put a widget inside a larger Layout. This can be done manually (for instance with Layout.setx / sety) or “automatically” playing with the parameters of Layout.flat:

?sep:int ->
?margins:int ->
?hmargin:int ->
?vmargin:int ->

I agree this is not very well documented (yet!) but you can have a look at the examples.

1 Like

Hi. Is it possible to show something like file/directory picker currently?

Hi, not yet, unfortunately. File chooser is one of the first on my TODO list. Actually I have started working on it, but it’s not ready yet. Hopefully soon!
For the moment you have to resort to system dialogs like zenity or kdialog.

That’s nice to know. Thanks!

Hi
I’m happy to announce a new version of Bogue (20240225). I would like to mention here two main changes:

  • This is the last version that supports SDL 2.0.9 (default in Debian 10)
    Next version will use tsdl 1.0.0 which requires SDL 2.0.10 or later
  • Thanks to @edwin , this version (if using SDL >= 2.0.16) is much more power-friendly (when idle). You may now leave a Bogue app open (if idle) without worrying for your laptop battery (and the environment): energy consumption is now very close to zero. (powertop indicates instantaneous power of 0mW, which I think means less than 0.1mW on my laptop)
11 Likes

I’m having similar issues to @ypamine above. I’ve tried both with OCaml 5.1.0 and 5.1.1. In both cases, I will get a segmentation fault with just the following:

utop
utop # #thread;;
utop # #require "bogue";;
Loading Bogue 20240225 with config dir /Users/me/projects/bogue-tests/_opam/share/bogue/themes/default
[2]    10756 segmentation fault  utop

I also get the same error with the minimal hello world example in the docs.

I’m on M1 Macbook Pro, Mac OS 14.3.1. sdl 2.30.1

Would be keen to check this out. Is it expected to work on Mac? Any troubleshooting steps I could take?

I don’t have (easy) access to a Mac OS machine, but the CI says it should/can work with ocaml 5.1:
https://ocaml.ci.dev/github/sanette/bogue/commit/b307b736609e19ba6fee688cfed761ce9425a2e1/variant/macos-homebrew-5.1_opam-2.1

  • before trying bogue, did you try the tsdl library alone ?

  • do the boguex examples work for you? (try for instance boguex 12)

  • if not, can you try BOGUE_DEBUG=true boguex 12 and post the output ?

1 Like

I ran into a segfault on macOS arm64 with OCaml 4.14. I suspect it is the same issue you have. My working hypothesis based on an lldb debug session (you can skip past this): OCaml making a fixed arity function call foreign "SDL_Log" (string @-> string @-> returning void) into a C variable arity function void SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1) is not safe on macOS/clang across dylib boundary.

I’ll file an issue with appropriate docs in a few weeks (need time to get my DkCoder test+debug apparatus better for shared library issues). If my hypothesis was correct, then introducing a fixed arity function stub in tsdl for SDL_Log should fix the root cause.

My notes (including a temporary fix and how to tell if you are affected) were:

open Tsdl

(* Any use of [Sdl.log] that prints to the log will SIGSEGV on DkCoder
   ARM64 macOS. "Works" on boguex.exe and by directly linking to homebrew's SDL
   2.28.4, but the [Sdl.log] display garbage instead of the expected
   [Sdl.log "Using SDL %u.%u.%u" a b c] from Bogue.B_trigger.

   boguexe.exe and a DkCoder script example, respectively:

    [61][0] :        Warning: SDL initialized
    2024-03-07 22:03:44.812 examples.exe[7961:10522604] INFO: ؠ&`
    [62][0] :        Event: SDL Events initialized

    [73][0] :        Warning: SDL initialized
    2024-03-07 22:16:56.467 ocamlrunx[25764:10578085] INFO: (null)
    [74][0] :        Event: SDL Events initialized

   Maybe because SDL_Log() is varargs and not two arguments like coded into
   Tsdl? Regardless, avoid all logs until fixed! *)

let () = Sdl.log_set_all_priority Sdl.Log.priority_critical

So, try that let () statement before opening Bogue. And if you can, also remove all the Sdl.log statements from Bogue. If either of those works you have the same problem and a temporary fix.

5 Likes