GUI gem out of the box

Hello Ruby Users! I’d like to introduce my pet project: kredki. It’s a gem for playing with vector graphics and creating simple applications. It’s almost completely untested, full of bugs, and the documentation is sparse, but I’m proud of it. Especially since it’s 100% the result of using Natural Intelligence :upside_down_face: If you’d like to check it out, you can download it from RubyGems or visit my GitHub repository. Any feedback would be greatly appreciated!

Note: kredki currently doesn’t work on macOS. I plan to fix this as soon as I have access to the necessary hardware, or if someone else helps me with it.

3 Likes

Looks like a cool project! Thanks for sharing.

I’m curious to know if you are building it for fun or are you using it in some other project.

I have Mac OS so happy to help with testing if you send me what needs to be done.

Basically, the mini apps that are in kradki/sample are all that I have created using it so far :grinning_face_with_smiling_eyes: I wanted to get to a point where the gem was relatively complete. Now I’m wondering what to do next with it.

To run on Mac, you probably just need to generate the appropriate shared libraries and set the gem to use them. There are 3 shared libraries used in the project: SDL, ThorVG and pastele.

With SDL, things should be simple - you clone the repository and run make or similar.

In the case of ThorVG, it’s a bit different, as meson and ninja are used for compilation. Furthermore, kredki doesn’t use the original version of ThorVG, only the one available here (please, clone thorvg-gui branch, as main is used only to keep fork synchronized). I added a function for text measurements there, which is essential for the gui library.

And the final shared library: pastele. This is the glue layer that connects SDL and ThorVG from kredki. It’s part of the kredki project on GitHub, so you don’t need to clone anything additionally. You can compile it using make, but you’ll need to prepare a dedicated CMakeLists.txt first.

For Windows and Linux, there are rake tasks that automate the entire process. You can take a look at Rakefile and see how it’s done there. I also wrote several points about it in the readme.

If you try to do this and need advice, you can always write here or private message me.

I took a quick look and was able to setup the dependencies using the following commands:

brew install sdl and brew install thorvg and make seems to come out of the box:

$ brew list sdl
Warning: Formula sdl was renamed to sdl12-compat.
/usr/local/Cellar/sdl12-compat/1.2.76/bin/sdl-config
/usr/local/Cellar/sdl12-compat/1.2.76/include/SDL/ (33 files)
/usr/local/Cellar/sdl12-compat/1.2.76/lib/libSDL-1.2.0.dylib
/usr/local/Cellar/sdl12-compat/1.2.76/lib/pkgconfig/ (2 files)
/usr/local/Cellar/sdl12-compat/1.2.76/lib/ (2 other files)
/usr/local/Cellar/sdl12-compat/1.2.76/sbom.spdx.json
/usr/local/Cellar/sdl12-compat/1.2.76/share/aclocal/sdl.m4

$ brew list thorvg
/usr/local/Cellar/thorvg/1.0.3/include/thorvg-1/ (3 files)
/usr/local/Cellar/thorvg/1.0.3/lib/libthorvg-1.1.dylib
/usr/local/Cellar/thorvg/1.0.3/lib/pkgconfig/thorvg-1.pc
/usr/local/Cellar/thorvg/1.0.3/lib/libthorvg-1.dylib
/usr/local/Cellar/thorvg/1.0.3/sbom.spdx.json

$ make -v
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

Does that helps you to generate the template for building in macOS? I could try running it but making code updates to the build process would be out of my depth.

Ok, I see brew install sdl gives us sdl12-compat, which uses SDL2. We need SDL3, so you could try brew install sdl3 instead. There is only one more thing. pastele needs SDL headers files during compilation. If it is a different header version than the one with which the shared library was compiled, it may not work. But let’s assume it will work :slightly_smiling_face:

Official ThorVG package isn’t the one we need. But its compilation shouldn’t be problematic. Try this:

brew install meson
brew install ninja
# cd to path of destination
git clone https://github.com/lpogic/thorvg.git -b thorvg-gui
cd thorvg
meson setup builddir -Dengines=cpu -Dloaders=all -Dsavers=all -Dsimd=false -Dlog=false -Dstrip=false -Dthreads=false -Dtests=false -Dpartial=false
ninia -C builddir

If this succeeds, we can move on to pastele.

SDL3 - Success!

$ brew list sdl3
/usr/local/Cellar/sdl3/3.4.4/include/SDL3/ (86 files)
/usr/local/Cellar/sdl3/3.4.4/lib/libSDL3.0.dylib
/usr/local/Cellar/sdl3/3.4.4/lib/cmake/ (7 files)
/usr/local/Cellar/sdl3/3.4.4/lib/pkgconfig/sdl3.pc
/usr/local/Cellar/sdl3/3.4.4/lib/ (2 other files)
/usr/local/Cellar/sdl3/3.4.4/sbom.spdx.json
/usr/local/Cellar/sdl3/3.4.4/share/licenses/SDL3/LICENSE.txt

meson & ninja - Success!

$ brew list meson
brew list /usr/local/Cellar/meson/1.11.0/bin/meson
/usr/local/Cellar/meson/1.11.0/etc/bash_completion.d/meson
/usr/local/Cellar/meson/1.11.0/lib/python3.14/ (254 files)
/usr/local/Cellar/meson/1.11.0/sbom.spdx.json
/usr/local/Cellar/meson/1.11.0/share/man/man1/meson.1
/usr/local/Cellar/meson/1.11.0/share/polkit-1/actions/com.mesonbuild.install.policy
/usr/local/Cellar/meson/1.11.0/share/vim/ (4 files)
/usr/local/Cellar/meson/1.11.0/share/zsh/site-functions/_meson

$ brew list ninja
/usr/local/Cellar/ninja/1.13.2/bin/ninja
/usr/local/Cellar/ninja/1.13.2/etc/bash_completion.d/ninja
/usr/local/Cellar/ninja/1.13.2/sbom.spdx.json
/usr/local/Cellar/ninja/1.13.2/share/doc/ninja/manual.asciidoc
/usr/local/Cellar/ninja/1.13.2/share/vim/vimfiles/syntax/ninja.vim
/usr/local/Cellar/ninja/1.13.2/share/zsh/site-functions/_ninja

ThorVG - Succes?

$ ninja -C builddir
ninja: Entering directory `builddir'
[47/241] Compiling C++ object src/libthorvg-1.1.dylib.p/loaders_ttf_tvgTtfLoader.cpp.o
...
2 warnings generated.
[241/241] Linking target src/libthorvg-1.1.dylib

Ready for pastele :slight_smile: . Let me know if I need to run anything to verify the ThorVG installation too.

Great! The ThorVG compilation output looks good. You could run the tests with ninja -C test, but we specified -Dtests=false in the meson configuration, so that won’t work now. We can go back to this step if something goes wrong later.

So now let’s try build the pastele:

  1. Confirm you have rake installed.
  2. I’ve added a path for macOS to the kredki repository. Clone it or pull the latest changes if you’ve already done so.
  3. Go to the root kredki project directory.
  4. Run rake config. This will create rake-config.rb file. Open it for editing.
  5. Change the "/home/user/SDL" string to "/usr/local/Cellar/sdl3/3.4.4".
  6. Change the "/home/user/thorvg" string to path to the thorvg project (builddir should be one of the child directories of it).
  7. Save changes.
  8. Run rake build. This task consists of several steps: preparing CMakeLists.txt, compiling pastels, generating a binding file, copying shared libraries to the project.
  9. Run rake. If you see a green window with two buttons, we are home :slight_smile:

It works!

A couple of things I needed to fix:

  1. The Rakefile had a syntax error: Update Rakefile with correct conditional for /darwin/ by solojavier · Pull Request #1 · lpogic/kredki · GitHub
  2. I had to run brew install cmake because that dependency was missing

Everything else worked as expected :slight_smile:

1 Like

Fantastic, you really did it!

  1. The Rakefile had a syntax error: Update Rakefile with correct conditional for /darwin/ by solojavier · Pull Request #1 · lpogic/kredki · GitHub

This is what happens when you switch to Ruby after 8 hours of PHP coding :sweat_smile: I merged your PR. Thanks!

If you want, you can also add PR with copies of dylibs so that Mac users can install kredki by simply running gem install kredki.

Snake is fun indeed! Made me remember my Nokia phone from back in the day :slight_smile:

t

3 Likes