Skip to content

Commit

Permalink
update to zig0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Aug 4, 2023
1 parent b4d22df commit 0187eb8
Show file tree
Hide file tree
Showing 31 changed files with 225 additions and 204 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If you're using the official package manager:
.version = "0.0.1",
.dependencies = .{
.zfltk = .{
.url = "https://github.com/MoAlyousef/zfltk/archive/refs/tags/pkg0.0.8.tar.gz",
.url = "https://github.com/MoAlyousef/zfltk/archive/refs/tags/pkg0.1.0.tar.gz",
},
}
}
Expand Down Expand Up @@ -154,12 +154,12 @@ Using the Zig wrapper (under development):
```zig
const zfltk = @import("zfltk");
const app = zfltk.app;
const Window = zfltk.Window;
const Button = zfltk.Button;
const Box = zfltk.Box;
const Window = zfltk.window.Window;
const Button = zfltk.button.Button;
const Box = zfltk.box.Box;
const Color = zfltk.enums.Color;
fn butCb(but: *Button(.normal), data: ?*anyopaque) void {
fn butCb(but: *Button, data: ?*anyopaque) void {
var box = Box.fromRaw(data.?);
box.setLabel("Hello World!");
Expand All @@ -177,8 +177,9 @@ pub fn main() !void {
.label = "Hello",
});
win.freePosition();
var but = try Button(.normal).init(.{
var but = try Button.init(.{
.x = 160,
.y = 220,
.w = 80,
Expand All @@ -187,6 +188,8 @@ pub fn main() !void {
.label = "Click me!",
});
but.setDownBox(.flat);
var box = try Box.init(.{
.x = 10,
.y = 10,
Expand All @@ -210,10 +213,9 @@ The messaging api can also be used:
```zig
const zfltk = @import("zfltk");
const app = zfltk.app;
const Widget = zfltk.Widget;
const Window = zfltk.Window;
const Button = zfltk.Button;
const Box = zfltk.Box;
const Window = zfltk.window.Window;
const Button = zfltk.button.Button;
const Box = zfltk.box.Box;
const enums = zfltk.enums;
pub const Message = enum(usize) {
Expand All @@ -233,7 +235,7 @@ pub fn main() !void {
.label = "Hello",
});
var but1 = try Button(.normal).init(.{
var but1 = try Button.init(.{
.x = 100,
.y = 220,
.w = 80,
Expand All @@ -242,7 +244,7 @@ pub fn main() !void {
.label = "Button 1",
});
var but2 = try Button(.normal).init(.{
var but2 = try Button.init(.{
.x = 200,
.y = 220,
.w = 80,
Expand Down Expand Up @@ -307,7 +309,7 @@ You can also mix and match for any missing functionalities in the Zig wrapper (s

Widgets also provide a `call` method which allows to call any method that wasn't wrapped yet in the bindings:
```zig
var flex = try Group(.flex).init(.{
var flex = try Flex.init(.{
.w = 400,
.h = 300,
.orientation = .vertical,
Expand Down
6 changes: 3 additions & 3 deletions examples/browser.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const zfltk = @import("zfltk");
const app = zfltk.app;
const Window = zfltk.Window;
const Browser = zfltk.Browser;
const Window = zfltk.window.Window;
const MultiBrowser = zfltk.browser.MultiBrowser;

pub fn main() !void {
try app.init();
Expand All @@ -12,7 +12,7 @@ pub fn main() !void {
});

// Available browsers are: normal, select, hold, multi and file
var browser = try Browser(.multi).init(.{
var browser = try MultiBrowser.init(.{
.x = 10,
.y = 10,
.w = 900 - 20,
Expand Down
11 changes: 5 additions & 6 deletions examples/channels.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const zfltk = @import("zfltk");
const app = zfltk.app;
const Widget = zfltk.Widget;
const Window = zfltk.Window;
const Button = zfltk.Button;
const Box = zfltk.Box;
const Window = zfltk.window.Window;
const Button = zfltk.button.Button;
const Box = zfltk.box.Box;
const enums = zfltk.enums;

pub const Message = enum(usize) {
Expand All @@ -23,7 +22,7 @@ pub fn main() !void {
.label = "Hello",
});

var but1 = try Button(.normal).init(.{
var but1 = try Button.init(.{
.x = 100,
.y = 220,
.w = 80,
Expand All @@ -32,7 +31,7 @@ pub fn main() !void {
.label = "Button 1",
});

var but2 = try Button(.normal).init(.{
var but2 = try Button.init(.{
.x = 200,
.y = 220,
.w = 80,
Expand Down
8 changes: 4 additions & 4 deletions examples/customwidget.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const zfltk = @import("zfltk");
const app = zfltk.app;
const draw = zfltk.draw;
const Window = zfltk.Window;
const Widget = zfltk.Widget;
const Button = zfltk.Button;
const Box = zfltk.Box;
const Window = zfltk.window.Window;
const Widget = zfltk.widget.Widget;
const Button = zfltk.button.Button;
const Box = zfltk.box.Box;
const enums = zfltk.enums;
const Color = enums.Color;
const Event = enums.Event;
Expand Down
41 changes: 20 additions & 21 deletions examples/editor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
const zfltk = @import("zfltk");
const app = zfltk.app;
const widget = zfltk.widget;
const Widget = widget.Widget;
const Window = zfltk.Window;
const Menu = zfltk.Menu;
const Window = zfltk.window.Window;
const MenuBar = zfltk.menu.MenuBar;
const enums = zfltk.enums;
const Color = enums.Color;
const TextDisplay = zfltk.TextDisplay;
const TextEditor = zfltk.text.TextEditor;
const dialog = zfltk.dialog;
const FileDialog = zfltk.FileDialog;
const FileDialog = zfltk.dialog.FileDialog;
const std = @import("std");

// To avoid exiting when hitting escape.
Expand All @@ -22,13 +21,13 @@ pub fn winCb(w: *Window) void {
}
}

fn newCb(_: *Menu(.menu_bar), data: ?*anyopaque) void {
var editor = TextDisplay(.editor).fromRaw(data.?);
fn newCb(_: *MenuBar, data: ?*anyopaque) void {
var editor = TextEditor.fromRaw(data.?);
editor.buffer().?.setText("");
}

pub fn openCb(_: *Menu(.menu_bar), data: ?*anyopaque) void {
var editor = TextDisplay(.editor).fromRaw(data.?);
pub fn openCb(_: *MenuBar, data: ?*anyopaque) void {
var editor = TextEditor.fromRaw(data.?);
var dlg = try FileDialog(.file).init(.{});
dlg.setFilter("*.{txt,zig}");
dlg.show();
Expand All @@ -38,8 +37,8 @@ pub fn openCb(_: *Menu(.menu_bar), data: ?*anyopaque) void {
}
}

pub fn saveCb(_: *Menu(.menu_bar), data: ?*anyopaque) void {
var editor = TextDisplay(.editor).fromRaw(data.?);
pub fn saveCb(_: *MenuBar, data: ?*anyopaque) void {
var editor = TextEditor.fromRaw(data.?);
var dlg = try FileDialog(.save_file).init(.{ .save_as_confirm = true });
dlg.setFilter("*.{txt,zig}");
dlg.show();
Expand All @@ -49,27 +48,27 @@ pub fn saveCb(_: *Menu(.menu_bar), data: ?*anyopaque) void {
}
}

pub fn quitCb(_: *Menu(.menu_bar), data: ?*anyopaque) void {
pub fn quitCb(_: *MenuBar, data: ?*anyopaque) void {
var win = widget.Widget.fromRaw(data.?);
win.hide();
}

pub fn cutCb(_: *Menu(.menu_bar), data: ?*anyopaque) void {
const editor = TextDisplay(.editor).fromRaw(data.?);
pub fn cutCb(_: *MenuBar, data: ?*anyopaque) void {
const editor = TextEditor.fromRaw(data.?);
editor.cut();
}

pub fn copyCb(_: *Menu(.menu_bar), data: ?*anyopaque) void {
const editor = TextDisplay(.editor).fromRaw(data.?);
pub fn copyCb(_: *MenuBar, data: ?*anyopaque) void {
const editor = TextEditor.fromRaw(data.?);
_ = editor.copy();
}

pub fn pasteCb(_: *Menu(.menu_bar), data: ?*anyopaque) void {
const editor = TextDisplay(.editor).fromRaw(data.?);
pub fn pasteCb(_: *MenuBar, data: ?*anyopaque) void {
const editor = TextEditor.fromRaw(data.?);
editor.paste();
}

pub fn helpCb(_: *Menu(.menu_bar)) void {
pub fn helpCb(_: *MenuBar) void {
dialog.message(300, 200, "This editor was built using fltk and zig!");
}

Expand All @@ -86,9 +85,9 @@ pub fn main() !void {
});

win.freePosition();
var mymenu = try Menu(.menu_bar).init(.{ .w = 800, .h = 35 });
var mymenu = try MenuBar.init(.{ .w = 800, .h = 35 });

var editor = try TextDisplay(.editor).init(.{
var editor = try TextEditor.init(.{
.x = 2,
.y = 37,
.w = 800 - 2,
Expand Down
7 changes: 3 additions & 4 deletions examples/editormsgs.zig
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const zfltk = @import("zfltk");
const app = zfltk.app;
const widget = zfltk.widget;
const Widget = widget.Widget;
const window = zfltk.window;
const menu = zfltk.menu;
const enums = zfltk.enums;
const Color = enums.Color;
const text = zfltk.text;
const dialog = zfltk.dialog;
const FileDialog = zfltk.FileDialog;
const FileDialog = zfltk.dialog.FileDialog;
const std = @import("std");

pub const Message = enum(usize) {
Expand Down Expand Up @@ -38,10 +37,10 @@ pub fn main() !void {
app.setBackground(Color.fromRgb(211, 211, 211));
var win = try window.Window.init(.{ .w = 800, .h = 600, .label = "Editor" });
win.freePosition();
var mymenu = try menu.Menu(.menu_bar).init(.{ .w = 800, .h = 35 });
var mymenu = try menu.MenuBar.init(.{ .w = 800, .h = 35 });
var buf = try text.TextBuffer.init();
defer buf.deinit();
var editor = try text.TextDisplay(.editor).init(.{
var editor = try text.TextEditor.init(.{
.x = 2,
.y = 37,
.w = 800 - 2,
Expand Down
15 changes: 7 additions & 8 deletions examples/flex.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const zfltk = @import("zfltk");
const app = zfltk.app;
const Window = zfltk.Window;
const Box = zfltk.Box;
const Button = zfltk.Button;
const Group = zfltk.Group;
const Color = enums.Color;
const enums = zfltk.enums;
const Window = zfltk.window.Window;
const Box = zfltk.box.Box;
const Button = zfltk.button.Button;
const Flex = zfltk.group.Flex;
const Color = zfltk.enums.Color;

pub fn main() !void {
try app.init();
Expand All @@ -17,7 +16,7 @@ pub fn main() !void {
.label = "Hello",
});

var flex = try Group(.flex).init(.{
var flex = try Flex.init(.{
.w = 400,
.h = 300,

Expand All @@ -29,7 +28,7 @@ pub fn main() !void {

win.resizable(flex);

var btn = try Button(.normal).init(.{
var btn = try Button.init(.{
.h = 48,
.label = "Button",
});
Expand Down
4 changes: 2 additions & 2 deletions examples/flutterlike.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const HEIGHT: i32 = 400;

var COUNT: i32 = 0;

fn btnCb(_: *button.Button(.normal), data: ?*anyopaque) void {
fn btnCb(_: *button.Button, data: ?*anyopaque) void {
var count = box.Box.fromRaw(data.?);
COUNT += 1;
var buf: [250]u8 = undefined;
Expand All @@ -38,7 +38,7 @@ pub fn main() !void {
bar.setLabelAlign(Align.left | Align.inside);
var text = try box.Box.init(.{ .x = 250, .y = 180, .w = 100, .h = 40, .label = "You have pushed the button this many times:" });
var count = try box.Box.init(.{ .x = 250, .y = 220, .w = 100, .h = 40, .label = "0" });
var but = try button.Button(.normal).init(.{ .x = WIDTH - 100, .y = HEIGHT - 100, .w = 60, .h = 60, .label = "@+6plus" });
var but = try button.Button.init(.{ .x = WIDTH - 100, .y = HEIGHT - 100, .w = 60, .h = 60, .label = "@+6plus" });
win.end();
win.resizable(win);
win.show();
Expand Down
2 changes: 1 addition & 1 deletion examples/glwin.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const zfltk = @import("zfltk");
const app = zfltk.app;
const GlutWindow = zfltk.GlutWindow;
const GlutWindow = zfltk.window.GlutWindow;
const Mode = zfltk.enums.Mode;

extern fn glClearColor(r: f32, g: f32, b: f32, a: f32) void;
Expand Down
12 changes: 6 additions & 6 deletions examples/handle.zig
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const zfltk = @import("zfltk");
const app = zfltk.app;
const Window = zfltk.Window;
const Button = zfltk.Button;
const Box = zfltk.Box;
const Window = zfltk.window.Window;
const Button = zfltk.button.Button;
const Box = zfltk.box.Box;
const Color = zfltk.enums.Color;
const Event = zfltk.enums.Event;
const std = @import("std");
const draw = zfltk.draw;

fn butCb(but: *Button(.normal), data: ?*anyopaque) void {
fn butCb(but: *Button, data: ?*anyopaque) void {
var box = Box.fromRaw(data.?);

box.setLabel("Hello World!");
Expand All @@ -17,7 +17,7 @@ fn butCb(but: *Button(.normal), data: ?*anyopaque) void {
}

fn boxEventHandler(_: *Box, ev: Event, data: ?*anyopaque) bool {
const btn = Button(.normal).fromRaw(data.?);
const btn = Button.fromRaw(data.?);
switch (ev) {
.push => {
std.debug.print("Click the button: {s}\n", .{btn.label()});
Expand All @@ -43,7 +43,7 @@ pub fn main() !void {
.label = "Hello",
});

var but = try Button(.normal).init(.{
var but = try Button.init(.{
.x = 160,
.y = 220,
.w = 80,
Expand Down
10 changes: 5 additions & 5 deletions examples/image.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const zfltk = @import("zfltk");
const app = zfltk.app;
const SharedImage = zfltk.image.SharedImage;
const Image = zfltk.Image;
const Window = zfltk.Window;
const Box = zfltk.Box;
const Group = zfltk.Group;
const Image = zfltk.image.Image;
const Window = zfltk.window.Window;
const Box = zfltk.box.Box;
const Scroll = zfltk.group.Scroll;
const Align = zfltk.enums.Align;
const std = @import("std");

Expand All @@ -18,7 +18,7 @@ pub fn main() !void {
.label = "Image demo",
});

var scroll = try Group(.scroll).init(.{
var scroll = try Scroll.init(.{
.w = 415,
.h = 140,
});
Expand Down
Loading

0 comments on commit 0187eb8

Please sign in to comment.