Skip to content

frmdstryr/zig-gtk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zig-gtk

Auto generated zig bindings for GTK 4.

Examples

Creating widgets

const window = gtk.ApplicationWindow.new(app).?;
window.setTitle("Console");
const header_bar = gtk.HeaderBar.new().?;
window.setTitlebar(header_bar.asWidget());

const box = gtk.Box.new(.Vertical, 10).?;
box.setMargins(.{.top=10, .bottom=10, .start=10, .end=10});
window.setChild(box.asWidget());

Signals

const view = gtk.ColumnView.new(null).?;
view.setModel(@ptrCast(selection));
view.setHexpand(true);
view.setVexpand(true);

if (gtk.SignalListItemFactory.new()) |f| {
    _ = f.connectSetup(App, &PlacementWindow.onColSetupActive, app);
    _ = f.connectBind(App, &PlacementWindow.onColBindActive, app);
    view.appendColumn(
        gtk.ColumnViewColumn.new("Active", f.asListItemFactory()).?
    );
}

Structs

pub fn appendToBuffer(self: *Self, msg: []const u8) void {
    if (self.text_view.getBuffer()) |text_buffer| {
        var end_iter: gtk.TextIter = undefined;
        text_buffer.getEndIter(&end_iter);
        text_buffer.placeCursor(&end_iter);
        text_buffer.insertAtCursor(msg.ptr, @intCast(msg.len));
    }
}

Custom types

const PlacementEntryObject = gobject.registerType(PlacementEntry, "PlacementEntry");

const model = gio.ListStore.new(PlacementEntryObject.gType()).?;
if (app.document) |doc| {
    for (doc.placements.items) |entry| {
        const obj = PlacementEntryObject.new().?;
        obj.data = entry.*; // Custom data is allocated by glib
        model.append(obj.asObject());
    }
}

Naming convention

Type names and method names of the original C library were changed to follow the Zig Style Guide. For example, a method like gtk_grid_view_set_single_click_activate(grid_view, single_click_activate) in GTK C becomes a method belonging to the GridView struct and can be called like grid_view.setSingleClickActivate(single_click_activate) in zig-gtk.

Status

Bindings are generated automatically using python gen.py. You need to be on 3.10 and install PyGObject

Usage

zig-gtk depends on zig-wayland.

See the example for usage.

About

GTK4 Bindings for Zig

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Zig 99.6%
  • Python 0.4%