{"id":17299443,"url":"https://github.com/moalyousef/zfltk","last_synced_at":"2025-04-09T13:04:34.570Z","repository":{"id":54960076,"uuid":"331034728","full_name":"MoAlyousef/zfltk","owner":"MoAlyousef","description":"Zig bindings for the FLTK gui library","archived":false,"fork":false,"pushed_at":"2025-03-19T21:46:00.000Z","size":9441,"stargazers_count":65,"open_issues_count":5,"forks_count":8,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-02T07:56:31.599Z","etag":null,"topics":["fltk","gui","zig","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MoAlyousef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-19T16:04:08.000Z","updated_at":"2025-03-24T07:08:00.000Z","dependencies_parsed_at":"2024-07-30T10:44:27.190Z","dependency_job_id":"62d84f2e-0045-48ed-9395-4c4cb0356105","html_url":"https://github.com/MoAlyousef/zfltk","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoAlyousef%2Fzfltk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoAlyousef%2Fzfltk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoAlyousef%2Fzfltk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MoAlyousef%2Fzfltk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MoAlyousef","download_url":"https://codeload.github.com/MoAlyousef/zfltk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248045230,"owners_count":21038553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fltk","gui","zig","zig-package"],"created_at":"2024-10-15T11:22:30.807Z","updated_at":"2025-04-09T13:04:34.558Z","avatar_url":"https://github.com/MoAlyousef.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zfltk\nA Zig wrapper for the FLTK gui library.\n\n## Building the package from source\n```sh\ngit clone https://github.com/MoAlyousef/zfltk\ncd zfltk\nzig build\n```\n\nTo build the examples, pass `-Dzfltk-build-examples=true` to your `zig build` command.\n\n## Usage\nzfltk supports the zig package manager. To create a new project:\n\n```sh\nmkdir myproject\ncd myproject\nzig init\n```\n\nThis should create `build.zig`, `build.zig.zon` and other files.\n\nYou can add zfltk as a dependency to your project with one of these:\n\n```sh\n## specific release\n# 0.6.0 for zig 0.13\nzig fetch --save=zfltk https://github.com/MoAlyousef/zfltk/archive/refs/tags/pkg0.6.0.zip\n## or main branch\nzig fetch --save=zfltk https://github.com/MoAlyousef/zfltk/archive/refs/heads/main.zip\n```\n\nThis might add something like this in your `build.zig.zon`:\n```zig\n.{\n    ...\n    .dependencies = .{\n        .zfltk = .{\n            .url = \"https://github.com/MoAlyousef/zfltk/archive/refs/tags/pkg0.7.0.zip\",\n            .hash = \"...\",\n        },\n    },\n    ...\n}\n```\n\nYou can add the following to your build.zig:\n```zig\n    const zfltk_dep = b.dependency(\"zfltk\", .{\n        .target = target,\n        .optimize = optimize,\n    });\n    exe.root_module.addImport(\"zfltk\", zfltk_dep.module(\"zfltk\"));\n```\n\nThen you can run:\n```sh\nzig build run\n```\n\n## Dependencies \nzfltk requires a system install of cfltk (which along with fltk will be statically linked to your executable). CMake and a C++ compiler.\nYou can install cfltk using:\n```sh\ngit clone https://github.com/MoAlyousef/cfltk -b fltk1.4 --recurse-submodules --depth=1\ncd cfltk\n./scripts/bootstrap_posix.sh # optionally specify a -DCMAKE_INSTALL_PREFX=/some/path\n```\nThis might require super user privileges if no install prefix is provided since it might install to /usr/local.\nIf you install cfltk into a non-standard search path you would need to supply your executable with an include path and library path:\n```zig\n    exe.addLibraryPath(\"/some/path/include\");\n    exe.addIncludePath(\"/some/path/lib\");\n```\nAlternatively you can supply the zig executable with a search prefix:\n```bash\nzig build --search-prefix /some/path\n```\ncfltk dependencies:\n- Windows: With mingw, no dependencies.\n- MacOS: MacOS SDK.\n- Linux: X11 and OpenGL development headers need to be installed for development. The libraries themselves are available on linux distros with a graphical user interface.\n\nFor Debian-based GUI distributions, that means running:\n```sh\nsudo apt-get install libx11-dev libxext-dev libxft-dev libxinerama-dev libxcursor-dev libxrender-dev libxfixes-dev libpango1.0-dev libpng-dev libgl1-mesa-dev libglu1-mesa-dev\n```\nFor RHEL-based GUI distributions, that means running:\n```sh\nsudo yum groupinstall \"X Software Development\" \u0026\u0026 yum install pango-devel libXinerama-devel libpng-devel libstdc++-static\n```\nFor Arch-based GUI distributions, that means running:\n```sh\nsudo pacman -S libx11 libxext libxft libxinerama libxcursor libxrender libxfixes libpng pango cairo libgl mesa --needed\n```\nFor Alpine linux:\n```sh\napk add pango-dev fontconfig-dev libxinerama-dev libxfixes-dev libxcursor-dev libpng-dev mesa-gl\n```\nFor nixos:\n```sh\nnix-shell --packages rustc cmake git gcc xorg.libXext xorg.libXft xorg.libXinerama xorg.libXcursor xorg.libXrender xorg.libXfixes libcerf pango cairo libGL mesa pkg-config\n```\n\n## API\nUsing the Zig wrapper (under development):\n```zig\nconst zfltk = @import(\"zfltk\");\nconst app = zfltk.app;\nconst Window = zfltk.window.Window;\nconst Button = zfltk.button.Button;\nconst Box = zfltk.box.Box;\nconst Color = zfltk.enums.Color;\n\nfn butCb(but: *Button, data: ?*anyopaque) void {\n    var box = Box.fromRaw(data.?);\n\n    box.setLabel(\"Hello World!\");\n\n    but.setColor(Color.fromName(.cyan));\n}\n\npub fn main() !void {\n    try app.init();\n    app.setScheme(.gtk);\n\n    var win = try Window.init(.{\n        .w = 400,\n        .h = 300,\n\n        .label = \"Hello\",\n    });\n    win.freePosition();\n\n    var but = try Button.init(.{\n        .x = 160,\n        .y = 220,\n        .w = 80,\n        .h = 40,\n\n        .label = \"Click me!\",\n    });\n\n    but.setDownBox(.flat);\n\n    var box = try Box.init(.{\n        .x = 10,\n        .y = 10,\n        .w = 380,\n        .h = 180,\n\n        .boxtype = .up,\n    });\n\n    box.setLabelFont(.courier);\n    box.setLabelSize(18);\n\n    win.end();\n    win.show();\n\n    but.setCallbackEx(butCb, box);\n    try app.run();\n}\n```\nThe messaging api can also be used:\n```zig\nconst zfltk = @import(\"zfltk\");\nconst app = zfltk.app;\nconst Window = zfltk.window.Window;\nconst Button = zfltk.button.Button;\nconst Box = zfltk.box.Box;\nconst enums = zfltk.enums;\n\npub const Message = enum(usize) {\n    // Can't begin with Zero!\n    first = 1,\n    second,\n};\n\npub fn main() !void {\n    try app.init();\n    app.setScheme(.gtk);\n\n    var win = try Window.init(.{\n        .w = 400,\n        .h = 300,\n\n        .label = \"Hello\",\n    });\n\n    var but1 = try Button.init(.{\n        .x = 100,\n        .y = 220,\n        .w = 80,\n        .h = 40,\n\n        .label = \"Button 1\",\n    });\n\n    var but2 = try Button.init(.{\n        .x = 200,\n        .y = 220,\n        .w = 80,\n        .h = 40,\n\n        .label = \"Button 2\",\n    });\n\n    var mybox = try Box.init(.{\n        .x = 10,\n        .y = 10,\n        .w = 380,\n        .h = 180,\n\n        .boxtype = .up,\n    });\n\n    mybox.setLabelFont(.courier);\n    mybox.setLabelSize(18);\n\n    win.end();\n    win.show();\n    but1.emit(Message, .first);\n    but2.emit(Message, .second);\n\n    while (app.wait()) {\n        if (app.recv(Message)) |msg| switch (msg) {\n            .first =\u003e mybox.setLabel(\"Button 1 Clicked!\"),\n            .second =\u003e mybox.setLabel(\"Button 2 Clicked!\"),\n        };\n    }\n}\n```\n\nUsing the C Api directly:\n```zig\nconst c = @cImport({\n    @cInclude(\"cfltk/cfl.h\"); // Fl_init_all, Fl_run\n    @cInclude(\"cfltk/cfl_enums.h\"); // Fl_Color_*\n    @cInclude(\"cfltk/cfl_image.h\"); // Fl_register_images\n    @cInclude(\"cfltk/cfl_button.h\"); // Fl_Button\n    @cInclude(\"cfltk/cfl_box.h\"); // Fl_Box\n    @cInclude(\"cfltk/cfl_window.h\"); // Fl_Window\n});\n\n// fltk initizialization of optional functionalities\npub fn fltkInit() void {\n    c.Fl_init_all(); // inits all styles, if needed\n    c.Fl_register_images(); // register image types supported by fltk, if needed\n    _ = c.Fl_lock(); // enable multithreading, if needed\n}\n\n// Button callback\npub fn butCb(w: ?*c.Fl_Widget, data: ?*anyopaque) callconv(.C) void {\n    c.Fl_Box_set_label(@ptrCast(data), \"Hello World!\");\n    c.Fl_Button_set_color(@ptrCast(w), c.Fl_Color_Cyan);\n}\n\npub fn main() !void {\n    fltkInit();\n\n    _ = c.Fl_set_scheme(\"gtk+\");\n    const win = c.Fl_Window_new(100, 100, 400, 300, \"Hello\");\n    const but = c.Fl_Button_new(160, 220, 80, 40, \"Click me!\");\n    const box = c.Fl_Box_new(10, 10, 380, 180, \"\");\n    c.Fl_Box_set_box(box, c.Fl_BoxType_UpBox);\n    c.Fl_Box_set_label_size(box, 18);\n    c.Fl_Box_set_label_font(box, c.Fl_Font_Courier);\n    c.Fl_Window_end(win);\n    c.Fl_Window_show(win);\n    c.Fl_Button_set_callback(but, butCb, box);\n    _ = c.Fl_run();\n}\n```\nYou can also mix and match for any missing functionalities in the Zig wrapper (see examples/mixed.zig).\n\nWidgets also provide a `call` method which allows to call any method that wasn't wrapped yet in the bindings:\n```zig\n    var flex = try Flex.init(.{\n        .w = 400,\n        .h = 300,\n        .orientation = .vertical,\n    });\n\n    flex.call(\"set_margins\", .{10, 20, 10, 20});\n```\n\n![alt_test](screenshots/image.jpg)\n![alt_test](screenshots/editor.jpg)\n\n[video tutorial](https://youtu.be/D2ijlrDStdM)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoalyousef%2Fzfltk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoalyousef%2Fzfltk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoalyousef%2Fzfltk/lists"}