Giter Site home page Giter Site logo

batiati / iupforzig Goto Github PK

View Code? Open in Web Editor NEW
113.0 5.0 4.0 3.63 MB

IUP (Portable User Interface Toolkit) bindings for the Zig language.

License: The Unlicense

Zig 99.96% Shell 0.02% Batchfile 0.02%
iup iup-toolkit iup-gui-library zig ziglang gui multiplatform zig-package

iupforzig's Introduction

IUP for Zig

Lines of code GitHub code size in bytes made with Zig made with Zig

A Zig language idiomatic and type-checked bindings for IUP Portable User Interface Toolkit

Examples

Simple Notepad Windows

Simple Notepad Ubuntu

First look

A simple hello world example looks like this:

const iup = @import("iup.zig");

pub fn main() !void {
    try iup.MainLoop.open();
    defer iup.MainLoop.close();

    var main_dialog = try (iup.Dialog.init()
        .setTitle("Hello World")
        .setChildren(
        .{
            iup.VBox.init()
                .setMargin(10, 10)
                .setGap(10)
                .setAlignment(.ACenter)
                .setChildren(
                .{
                    iup.Label.init()
                        .setTitle("Hello World from IUPforZig"),
                    iup.Button.init()
                        .setTitle("OK")
                        .setActionCallback(exit),
                },
            ),
        },
    ).unwrap());
    defer main_dialog.deinit();

    try main_dialog.showXY(.Center, .Center);
    try iup.MainLoop.beginLoop();
}

fn exit(button: *iup.Button) !void {
    iup.MainLoop.exitLoop();
}

Resulting in this:

Hello World Windows

Hello World Ubuntu

IUP Metadata

This project contains source-code automatically generated by The IUP Metadata Project.

Most of the hard/repetitive work was done by code-gen tool, however, the API guidelines and all the interop code belongs here on this project.

API

Zig does not require any special treatment to use C libraries, so to use IUP in Zig, it is as simple as adding @cInclude("iup.h") in your source code, no need for special bindings!

This project attempts to create Zig bindings for IUP Toolkit with idiomatic and type-checked API, where none of the original IUP's declarations are exposed in the public interface, only names and concepts are kept as close as possible.

Comparison:

  1. IUP simple example in C:
#include <stdlib.h>
#include <iup.h>

int main(int argc, char **argv)
{
  Ihandle *dlg, *multitext, *vbox;

  IupOpen(&argc, &argv);

  multitext = IupText(NULL);
  vbox = IupVbox(
    multitext,
    NULL);
  IupSetAttribute(multitext, "MULTILINE", "YES");
  IupSetAttribute(multitext, "EXPAND", "YES");

  dlg = IupDialog(vbox);
  IupSetAttribute(dlg, "TITLE", "Simple Notepad");
  IupSetAttribute(dlg, "SIZE", "QUARTERxQUARTER");

  IupShowXY(dlg, IUP_CENTER, IUP_CENTER);
  IupSetAttribute(dlg, "USERSIZE", NULL);

  IupMainLoop();

  IupClose();
  return EXIT_SUCCESS;
}
  1. Equivalent example in Zig:
const iup = @import("iup.zig");

pub fn main() !void {
    try iup.MainLoop.open();
    defer iup.MainLoop.close();

    var main_dialog = try (iup.Dialog.init()
        .setTitle("Simple Notepad")
        .setSize(.Quarter, .Quarter)
        .setChildren(
        .{
            iup.VBox.init()
                .setChildren(
                .{
                    iup.Text.init()
                        .setMultiline(true)
                        .setExpand(.Yes),
                },
            ),
        },
    ).unwrap());
    defer main_dialog.deinit();

    try main_dialog.showXY(.Center, .Center);
    try iup.MainLoop.beginLoop();
}

How to build

  1. Download Zig;

  2. Install IUP shared libraries and run:

NOTE: curl is needed to download IUP binaries.

Linux

./install_iup.sh
zig build run

Windows

.\install_iup.bat
zig build run

For more information, please visit IUP's download page for your platform: https://sourceforge.net/projects/iup/files/3.30/

Dependencies for libim and libcd may be required: https://sourceforge.net/projects/imtoolkit/files/3.15/ https://sourceforge.net/projects/canvasdraw/files/5.14/

Pending work

  • Support for collections and indexed attributes (list items for example)

  • Complete the Simple Notepad example.

  • Support Linux and Windows (using shared libs)

  • Investigate how to build IUP from C sources in Zig.

  • More tests, and sanitize failing tests.

  • Additional controls (image library, matrix, GLCanvas, scintilla, plot, etc)

Feel free to place any comments/issues/PRs, it will be very nice to receive any feedback ๐Ÿš€.

Prior Art

Some great projects that served as inspiration.

License

iupforzig's People

Contributors

batiati avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

iupforzig's Issues

Complex metadata representation

Figure out the better way to represent those metadata complexities:

1. IUP elements that have attributes that are applied on children;

Example:

  • MDI attributes for Canvas for example

Proposals:

  • Render these functions in all possible elements, allowing to set them even when they are not children of the expected element.
  • Render these functions on parent element with a special signature .setXYZ(child, value); Maybe not ergonomics to declare in fluent API.

2. Complex union values

Examples:

  • Colors can be an RGB triplet or a well-known alias, like "BGCOLOR", "FGCOLOR", etc.
  • Tree.setValue expects an i32 representing the index, or a well-known alias, like "NEXT", "PREVIOUS", "ROOT", etc

Proposals

  • Status-quo: Declare an union with each possible value, for example
pub const Color = union(enum) {
    BgColor,
    FgColor,
    Rgb: Rgb,
};

pub const Selection = union(enum) {
    Next,
    Previous,
    Root,
    Index: i32
};
  • Use anytype in set; Each case may have a get behavior.
  • Declare two functions, one for each type, for example setColorRgb and setColorStr`

3. Handle or HandleName attributes

Example:

  • setImage and many others attribute should accept an Image or a string with the HandleName

Proposals

  • Status-quo: use aways string, for example setImage(image.getHandleName())
  • Use anytype in set; Each case may have a get behavior.
  • Declare two functions, one for each type, for example setImage and setImageHandleName`

Build issues

Currently, we have some issues building:

  • Find native include and libraries is broken with msvc ABI (zig issue 9002)
  • Set exe.subsystem = .Windows; and use wWinMain entrypoint did not work with exe.linkLibC
  • Do we really need linkLibC ?
  • Add option to link static or use dynamic IUP libraries
  • Latest zig 0.9.0-dev.315+1534cd2f8 compiles but fails running.

Crashing at malloc_consolidate()

Running on Linux (Ubuntu 21.04 kernel 5.11.0-18-generic) in debug or release-safe mode crashes at malloc_consolidate().

Running in release-fast and release-small works fine.

How to reproduce:

  1. Opening any existing file
malloc_consolidate(): unaligned fastbin chunk detected
The following command terminated unexpectedly:
cd /home/batiati/IUPforZig/IUPforZig && /home/batiati/IUPforZig/IUPforZig/zig-out/bin/example 
error: the following build command failed with exit code 1:
/home/batiati/IUPforZig/IUPforZig/zig-cache/o/6cece1366aaf0a2f9f1ae0f99faff783/build /snap/zig/3678/zig /home/batiati/IUPforZig/IUPforZig /home/batiati/IUPforZig/IUPforZig/zig-cache /home/batiati/.cache/zig run
  1. Clicking on "Close" button on "Find" dialog
malloc_consolidate(): invalid chunk size
The following command terminated unexpectedly:
cd /home/batiati/IUPforZig/IUPforZig && /home/batiati/IUPforZig/IUPforZig/zig-out/bin/example 
error: the following build command failed with exit code 1:
/home/batiati/IUPforZig/IUPforZig/zig-cache/o/6cece1366aaf0a2f9f1ae0f99faff783/build /snap/zig/3678/zig /home/batiati/IUPforZig/IUPforZig /home/batiati/IUPforZig/IUPforZig/zig-cache /home/batiati/.cache/zig run

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.