Skip to content

Commit

Permalink
Partial support for #3
Browse files Browse the repository at this point in the history
  • Loading branch information
batiati committed Jul 19, 2021
1 parent 9393be0 commit 1dae92e
Show file tree
Hide file tree
Showing 80 changed files with 28,177 additions and 2,849 deletions.
1 change: 1 addition & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ A [Zig language](https://ziglang.org/) idiomatic and type-checked bindings for [
- [Image](docs/image.md)
- [List](docs/list.md)
- [Tree](docs/tree.md)
- [MDI](docs/mdi.md)
- [Simple notepad (in progress)](docs/simple_notepad.md)

![Simple Notepad Windows](docs/SimpleNotepadWindows.gif)
Expand Down
Binary file added docs/MdiWindows.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions docs/mdi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# IUP for Zig
[![Lines of code](https://img.shields.io/tokei/lines/github/batiati/IUPforZig)]()
[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/batiati/IUPforZig)]()
[![made with Zig](https://img.shields.io/badge/made%20with%20%E2%9D%A4%20-Zig-orange)]()
[![made with Zig](https://img.shields.io/badge/unlicensed-public%20domain-brightgreen)]()

## WIP Work in Progress

A [Zig language](https://ziglang.org/) idiomatic and type-checked bindings for [IUP Portable User Interface Toolkit](https://webserver2.tecgraf.puc-rio.br/iup/)

## MDI example

Creates a MDI dialog with multiple children

Source code: [mdi_example.zig](../src/mdi_example.zig).

> Type `zig build mdi` to run this example.
Converted from original example in C
https://webserver2.tecgraf.puc-rio.br/iup/examples/C/mdi.c

## Screenshots

Windows Classic

![MDI Windows](MdiWindows.gif)

18 changes: 9 additions & 9 deletions src/MainLoop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const iup = @import("iup.zig");
/// Global handler for unhandled errors thrown inside callback functions
pub const ErrorHandlerFn = fn (Element, anyerror) anyerror!void;

const Self = @This();
const MainLoop = @This();
const Element = iup.Element;

var exitError: ?anyerror = null;
var errorHandler: ?ErrorHandlerFn = null;
var exit_error: ?anyerror = null;
var error_handler: ?ErrorHandlerFn = null;

///
/// Initializes the IUP toolkit. Must be called before any other IUP function.
Expand All @@ -21,8 +21,8 @@ pub fn open() iup.Error!void {
///
/// Sets a callback function to handle errors returned inside the main loop
/// Rethrow the error to terminate the application
pub fn setErrorHandler(errorHandler: ?ErrorHandlerFn) void {
Self.errorHandler = errorHandler;
pub fn setErrorHandler(value: ?ErrorHandlerFn) void {
MainLoop.error_handler = value;
}

///
Expand All @@ -34,11 +34,11 @@ pub fn exitLoop() void {
///
/// Called by the message loop
pub fn onError(element: Element, err: anyerror) i32 {
if (Self.errorHandler) |func| {
if (MainLoop.error_handler) |func| {
if (func(element, err)) {
return interop.consts.IUP_DEFAULT;
} else |rethrow| {
exitError = rethrow;
} else |rethrown| {
MainLoop.exit_error = rethrown;
}
}

Expand All @@ -60,7 +60,7 @@ pub fn onError(element: Element, err: anyerror) i32 {
/// causing the IupMainLoop to return. To avoid that set LOCKLOOP=YES before hiding the last dialog.
pub fn beginLoop() !void {
interop.beginLoop();
if (exitError) |err| return err;
if (exit_error) |err| return err;
}

///
Expand Down
12 changes: 6 additions & 6 deletions src/button_example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ fn create_dialog() !*Dialog {
.setTitle("Button with image")
.setName("btn_image")
.setCanFocus(false)
.setImPress(img_press.getHandleName())
.setImage(img_release.getHandleName())
.setIMinActive(img_inactive.getHandleName()) //wrong name!
.setImPress(img_press)
.setImage(img_release)
.setIMinActive(img_inactive) //wrong name!
.setButtonCallback(btn_image_button),
Button.init()
.setTitle("on/off")
Expand Down Expand Up @@ -133,7 +133,7 @@ const images = struct {
/// Defines pressed button's image
pub fn getRelease() !*Image {
return try (Image.init(16, 16, pixelmap[0..])
.setHandleName("img_release")
.setHandle("img_release")
.setColors(1, .{ .r = 215, .g = 215, .b = 215 })
.setColors(2, .{ .r = 40, .g = 40, .b = 40 })
.setColors(3, .{ .r = 30, .g = 50, .b = 210 })
Expand All @@ -143,7 +143,7 @@ const images = struct {

pub fn getPress() !*Image {
return try (Image.init(16, 16, pixelmap[0..])
.setHandleName("img_press")
.setHandle("img_press")
.setColors(1, .{ .r = 40, .g = 40, .b = 40 })
.setColors(2, .{ .r = 215, .g = 215, .b = 215 })
.setColors(3, .{ .r = 0, .g = 20, .b = 180 })
Expand All @@ -153,7 +153,7 @@ const images = struct {

pub fn getInactive() !*Image {
return try (Image.init(16, 16, pixelmap[0..])
.setHandleName("img_inactive")
.setHandle("img_inactive")
.setColors(1, .{ .r = 215, .g = 215, .b = 215 })
.setColors(2, .{ .r = 40, .g = 40, .b = 40 })
.setColors(3, .{ .r = 100, .g = 100, .b = 100 })
Expand Down
6 changes: 6 additions & 0 deletions src/commons.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const interop = @import("interop.zig");
const ascii = std.ascii;
const testing = std.testing;

pub const NativeType = enum { Void, Control, Canvas, Dialog, Image, Menu, Other };

pub const Error = error{
///
/// Open function must be called before any action
Expand All @@ -20,6 +22,10 @@ pub const Error = error{
///
/// Wrong child usage
InvalidChild,

///
/// Wrong element usage
InvalidElement,
};

pub const CallbackResult = error{
Expand Down
Loading

0 comments on commit 1dae92e

Please sign in to comment.