Hokusai
A Ruby library for authoring GUI applications
Getting started
In your Gemfile
gem "hokusai-zero", "0.2.6"
In order to run an application, you will need to install a backend
Raylib
- Install raylib >= 5.0
- Write your app
- Run app with
RAYLIB_PATH=/libpath/for/libraylib.(so|dylib) ruby <your app>.rb
SDL2
-
Install the following deps
-
Write your app
-
Run app with
SDL_PATH=/libpath/for/libsdl.(so|dylib) ruby <your app>.rb
Example counter application
require "hokusai"
require "hokusai/backends/raylib"
class Counter < Hokusai::Block
template " [template]\n vblock\n hblock\n label {\n :content=\"count\"\n size=\"130\" \n :color=\"count_color\"\n }\n hblock\n vblock\n label { \n content=\"Add\"\n @click=\"increment\" \n }\n vblock\n label { \n content=\"Subtract\"\n @click=\"decrement\" \n }\n EOF\n\n uses(\n vblock: Hokusai::Blocks::Vblock,\n hblock: Hokusai::Blocks::Hblock,\n label: Hokusai::Blocks::Label,\n )\n\n attr_accessor :count\n\n def increment(event)\n self.count += 1\n end\n\n def decrement(event)\n self.count -= 1\n end\n\n def count_color\n self.count > 0 ? [0,0,255] : [255,0,0]\n end\n\n def initialize(**args)\n @count = 0\n\n super(**args)\n end\nend\n\nHokusai::Backends::RaylibBackend.run(Counter) do |config|\n config.width = 500\n config.height = 500\n config.title = \"Counter application\"\nend\n"
Development
The build tooling of this project is xmake. You will need it to compile dependencies and run demos.
Hokusai contains a tree-sitter grammar to parse templates, and uses md4c to parse markdown.
When compiling the C portion of hokusai, tree-sitter will be statically linked.
Requirements:
- xmake to build dependencies
- Ruby to run applications
Steps:
- Download project
- Install dependencies
bundle installxmake q hoku-tree-sitterxmake q hoku-md4c- For Raylib
xmake q raylib
- For SDL2
xmake q libsdlxmake q libsdl_gfxxmake q lbsdl_ttfxmake q libsdl_image
- Build grammar and ast code
xmake b hokusai
- Run specs
xmake b -g test
- Run a demo
xmake demo counter
License
Hokusai is released under the MIT License