Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Jul 10, 2023
1 parent 44b7946 commit 7ee98e2
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 113 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ 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.6.tar.gz",
.hash = "1220ca0756f0d49e4f5be5776776fb74d359c540251e5bb6cd73b3df9b7f90e30afe",
.url = "https://github.com/MoAlyousef/zfltk/archive/refs/tags/pkg0.0.7.tar.gz",
},
}
}
```
(This is missing the hash, zig build will give you the correct hash, which you should add after the url)

In your build.zig:
```zig
const std = @import("std");
Expand Down
31 changes: 16 additions & 15 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@ install_prefix: []const u8,
finalize_cfltk: *std.Build.Step,
use_wayland: bool,

pub const SdkOpts = struct {
use_wayland: bool = false,
};

pub fn init(b: *Build) !*Sdk {
return init_with_opts(b, .{});
}

inline fn thisDir() []const u8 {
return comptime std.fs.path.dirname(@src().file) orelse @panic("error");
}

pub fn getZfltkModule(sdk: *Sdk, b: *Build) *Build.Module {
_ = sdk;
return b.createModule(.{
.source_file = .{ .path = thisDir() ++ "/src/zfltk.zig" },
});
}

pub const SdkOpts = struct {
use_wayland: bool = false,
};

pub fn init_with_opts(b: *Build, opts: SdkOpts) !*Sdk {
const install_prefix = b.install_prefix;
const zig_exe = b.zig_exe;
Expand Down Expand Up @@ -261,19 +272,9 @@ const examples = &[_]Example{
Example.init("threadawake", "examples/threadawake.zig", "Thread awake example"),
Example.init("handle", "examples/handle.zig", "Handle example"),
Example.init("flutterlike", "examples/flutterlike.zig", "Flutter-like example"),
Example.init("glwin", "examples/glwin.zig", "OpenGL window example"),
};

inline fn thisDir() []const u8 {
return comptime std.fs.path.dirname(@src().file) orelse @panic("error");
}

pub fn getZfltkModule(sdk: *Sdk, b: *Build) *Build.Module {
_ = sdk;
return b.createModule(.{
.source_file = .{ .path = thisDir() ++ "/src/zfltk.zig" },
});
}

pub fn build(b: *Build) !void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});
Expand Down
14 changes: 2 additions & 12 deletions src/box.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const c = zfltk.c;

pub const Box = struct {
const Self = @This();

pub const RawPtr = *c.Fl_Box;
pub usingnamespace zfltk.widget.methods(Self, *c.Fl_Box);

pub const Options = struct {
Expand Down Expand Up @@ -38,19 +38,9 @@ pub const Box = struct {
}

pub inline fn deinit(self: *Self) void {
c.Fl_Box_delete(self.inner);
c.Fl_Box_delete(self.raw());
app.allocator.destroy(self);
}

pub inline fn fromDynWidgetPtr(w: *c.Fl_Widget) ?Self {
if (c.Fl_Box_from_dyn_ptr(@ptrCast(w))) |v| {
return .{
.inner = v,
};
} else {
return null;
}
}
};

test "all" {
Expand Down
101 changes: 38 additions & 63 deletions src/browser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ pub fn Browser(comptime kind: BrowserKind) type {
.file => *c.Fl_File_Browser,
};

inner: RawPtr,

pub usingnamespace zfltk.widget.methods(Self, RawPtr);

pub inline fn init(opts: Widget.Options) !*Self {
Expand All @@ -44,10 +42,7 @@ pub fn Browser(comptime kind: BrowserKind) type {
const label = if (opts.label != null) opts.label.?.ptr else null;

if (init_func(opts.x, opts.y, opts.w, opts.h, label)) |ptr| {
var self = try app.allocator.create(Self);
self.inner = ptr;

return self;
return Self.fromRaw(ptr);
}

unreachable;
Expand All @@ -62,171 +57,151 @@ pub fn Browser(comptime kind: BrowserKind) type {
.file => c.Fl_File_Browser_delete,
};

deinit_func(self.inner);
}

pub inline fn raw(self: *Self) RawPtr {
return self.inner;
}

pub inline fn fromRaw(ptr: RawPtr) Self {
return .{ .inner = ptr };
}

pub inline fn fromWidget(wid: Widget) Self {
return Self.fromRaw(@ptrCast(wid.inner));
}

pub inline fn fromVoidPtr(ptr: *anyopaque) Self {
return .{ .inner = @ptrCast(ptr) };
}

pub inline fn toVoidPtr(self: *Self) *anyopaque {
return @ptrCast(self.inner);
deinit_func(self.raw());
}

pub fn remove(self: *Self, line: u32) void {
return c.Fl_Browser_remove(@ptrCast(self.inner), line);
return c.Fl_Browser_remove(@ptrCast(self.raw()), line);
}

pub fn add(self: *Self, item: [:0]const u8) void {
return c.Fl_Browser_add(@ptrCast(self.inner), item.ptr);
return c.Fl_Browser_add(@ptrCast(self.raw()), item.ptr);
}

pub fn insert(self: *Self, line: u32, item: [:0]const u8) void {
return c.Fl_Browser_insert(@ptrCast(self.inner), line, item.ptr);
return c.Fl_Browser_insert(@ptrCast(self.raw()), line, item.ptr);
}

pub fn moveItem(self: *Self, to: u32, from: u32) void {
return c.Fl_Browser_move_item(@ptrCast(self.inner), to, from);
return c.Fl_Browser_move_item(@ptrCast(self.raw()), to, from);
}

pub fn swap(self: *Self, a: u32, b: u32) void {
return c.Fl_Browser_swap(@ptrCast(self.inner), a, b);
return c.Fl_Browser_swap(@ptrCast(self.raw()), a, b);
}

pub fn clear(self: *Self) void {
return c.Fl_Browser_clear(@ptrCast(self.inner));
return c.Fl_Browser_clear(@ptrCast(self.raw()));
}

pub fn size(self: *Self) u32 {
return c.Fl_Browser_size(@ptrCast(self.inner));
return c.Fl_Browser_size(@ptrCast(self.raw()));
}

pub fn setSize(self: *Self, w: i32, h: i32) void {
return c.Fl_Browser_set_size(@ptrCast(self.inner), w, h);
return c.Fl_Browser_set_size(@ptrCast(self.raw()), w, h);
}

pub fn select(self: *Self, line: u32) void {
if (line <= self.size()) return c.Fl_Browser_select(@ptrCast(self.inner), line);
if (line <= self.size()) return c.Fl_Browser_select(@ptrCast(self.raw()), line);
}

pub fn selected(self: *Self, line: u32) bool {
return c.Fl_Browser_selected(@ptrCast(self.inner), line) != 0;
return c.Fl_Browser_selected(@ptrCast(self.raw()), line) != 0;
}

pub fn text(self: *Self, line: u32) [:0]const u8 {
return c.Fl_Browser_text(@ptrCast(self.inner), line);
return c.Fl_Browser_text(@ptrCast(self.raw()), line);
}

pub fn setText(self: *Self, line: u32, txt: [*c]const u8) void {
return c.Fl_Browser_set_text(@ptrCast(self.inner), line, txt);
return c.Fl_Browser_set_text(@ptrCast(self.raw()), line, txt);
}

pub fn load(self: *Self, path: [*c]const u8) void {
return c.Fl_Browser_load_file(@ptrCast(self.inner), path);
return c.Fl_Browser_load_file(@ptrCast(self.raw()), path);
}

pub fn textSize(self: *Self) u32 {
return c.Fl_Browser_text_size(@ptrCast(self.inner));
return c.Fl_Browser_text_size(@ptrCast(self.raw()));
}

pub fn setTextSize(self: *Self, val: u32) void {
return c.Fl_Browser_set_text_size(@ptrCast(self.inner), val);
return c.Fl_Browser_set_text_size(@ptrCast(self.raw()), val);
}

pub fn topline(self: *Self, line: u32) void {
return c.Fl_Browser_topline(@ptrCast(self.inner), line);
return c.Fl_Browser_topline(@ptrCast(self.raw()), line);
}

pub fn bottomline(self: *Self, line: u32) void {
return c.Fl_Browser_bottomline(@ptrCast(self.inner), line);
return c.Fl_Browser_bottomline(@ptrCast(self.raw()), line);
}

pub fn middleline(self: *Self, line: u32) void {
return c.Fl_Browser_middleline(@ptrCast(self.inner), line);
return c.Fl_Browser_middleline(@ptrCast(self.raw()), line);
}

pub fn formatChar(self: *Self) u8 {
return c.Fl_Browser_format_char(@ptrCast(self.inner));
return c.Fl_Browser_format_char(@ptrCast(self.raw()));
}

pub fn setFormatChar(self: *Self, char: u8) void {
return c.Fl_Browser_set_format_char(@ptrCast(self.inner), char);
return c.Fl_Browser_set_format_char(@ptrCast(self.raw()), char);
}

pub fn columnChar(self: *Self) u8 {
return c.Fl_Browser_column_char(@ptrCast(self.inner));
return c.Fl_Browser_column_char(@ptrCast(self.raw()));
}

pub fn setColumnChar(self: *Self, char: u8) void {
return c.Fl_Browser_set_column_char(@ptrCast(self.inner), char);
return c.Fl_Browser_set_column_char(@ptrCast(self.raw()), char);
}

pub fn setColumnWidths(self: *Self, arr: [:0]const i32) void {
return c.Fl_Browser_set_column_widths(@ptrCast(self.inner), arr.ptr);
return c.Fl_Browser_set_column_widths(@ptrCast(self.raw()), arr.ptr);
}

pub fn displayed(self: *Self, line: u31) bool {
return c.Fl_Browser_displayed(@ptrCast(self.inner), line) != 0;
return c.Fl_Browser_displayed(@ptrCast(self.raw()), line) != 0;
}

pub fn makeVisible(self: *Self, line: u31) void {
return c.Fl_Browser_make_visible(@ptrCast(self.inner), line);
return c.Fl_Browser_make_visible(@ptrCast(self.raw()), line);
}

pub fn position(self: *Self) u31 {
return c.Fl_Browser_position(@ptrCast(self.inner));
return c.Fl_Browser_position(@ptrCast(self.raw()));
}

pub fn setPosition(self: *Self, pos: u31) void {
return c.Fl_Browser_set_position(@ptrCast(self.inner), pos);
return c.Fl_Browser_set_position(@ptrCast(self.raw()), pos);
}

pub fn hposition(self: *Self) u31 {
return c.Fl_Browser_hposition(@ptrCast(self.inner));
return c.Fl_Browser_hposition(@ptrCast(self.raw()));
}

pub fn setHposition(self: *Self, pos: u31) void {
return c.Fl_Browser_set_hposition(@ptrCast(self.inner), pos);
return c.Fl_Browser_set_hposition(@ptrCast(self.raw()), pos);
}

pub fn hasScrollbar(self: *Self) enums.BrowserScrollbar {
return c.Fl_Browser_has_scrollbar(@ptrCast(self.inner));
return c.Fl_Browser_has_scrollbar(@ptrCast(self.raw()));
}

pub fn setHasScrollbar(self: *Self, mode: enums.BrowserScrollbar) void {
return c.Fl_Browser_set_has_scrollbar(@ptrCast(self.inner), mode);
return c.Fl_Browser_set_has_scrollbar(@ptrCast(self.raw()), mode);
}

pub fn scrollbarSize(self: *Self) u31 {
return c.Fl_Browser_scrollbar_size(@ptrCast(self.inner));
return c.Fl_Browser_scrollbar_size(@ptrCast(self.raw()));
}

pub fn setScrollbarSize(self: *Self, new_size: u31) void {
return c.Fl_Browser_set_scrollbar_size(@ptrCast(self.inner), new_size);
return c.Fl_Browser_set_scrollbar_size(@ptrCast(self.raw()), new_size);
}

pub fn sort(self: *Self) void {
return c.Fl_Browser_sort(@ptrCast(self.inner));
return c.Fl_Browser_sort(@ptrCast(self.raw()));
}

pub fn scrollbar(self: *Self) Valuator {
return .{ .inner = c.Fl_Browser_scrollbar(@ptrCast(self.inner)) };
return .{ .inner = c.Fl_Browser_scrollbar(@ptrCast(self.raw())) };
}

pub fn hscrollbar(self: *Self) .Valuator {
return .{ .inner = c.Fl_Browser_hscrollbar(@ptrCast(self.inner)) };
return .{ .inner = c.Fl_Browser_hscrollbar(@ptrCast(self.raw())) };
}
};
}
Expand Down
8 changes: 0 additions & 8 deletions src/button.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ pub fn Button(comptime kind: ButtonKind) type {
deinit_func(self.raw());
app.allocator.destroy(self);
}

pub inline fn fromDynWidgetPtr(w: *c.Fl_Widget) ?Self {
if (c.Fl_Button_from_dyn_ptr(@ptrCast(w))) |v| {
return .{ .inner = v };
}

return null;
}
};
}

Expand Down
11 changes: 11 additions & 0 deletions src/menu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ pub fn Menu(comptime kind: MenuKind) type {

unreachable;
}

pub inline fn deinit(self: *Self) void {
const deinitFn = switch (kind) {
.menu_bar => c.Fl_Menu_Bar_delete,
.choice => c.Fl_Choice_delete,
.sys_menu_bar => c.Fl_Sys_Menu_Bar_delete,
};

deinitFn(self.raw());
app.allocator.destroy(self);
}
};
}

Expand Down
10 changes: 10 additions & 0 deletions src/table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ pub fn Table(comptime kind: TableKind) type {

unreachable;
}

pub inline fn deinit(self: *Self) void {
const deinitFn = switch (kind) {
.table => c.Fl_Table_delete,
.table_row => c.Fl_Table_Row_delete,
};

deinitFn(self.raw());
app.allocator.destroy(self);
}
};
}

Expand Down
5 changes: 5 additions & 0 deletions src/tree.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub const Tree = struct {

unreachable;
}

pub inline fn deinit(self: *Self) void {
c.Fl_Tree_delete(self.RawPtr);
app.allocator.destroy(self);
}
};

pub fn methods(comptime Self: type) type {
Expand Down
Loading

0 comments on commit 7ee98e2

Please sign in to comment.