Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

eddineimad0/widow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

650 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Widow is a simple library for creating rendering windows and reading inputs written in zig.

Supported Platforms

Currently Widow supports windows Os and Linux (x11). there is no current plan to support any other platforms.

Examples

All API functions are well documented and you can check out the examples for more details on how to use.

The following sample creates a window.

const std = @import("std");
const widow = @import("widow");
const event = widow.event;
var gpa_allocator: std.heap.DebugAllocator(.{}) = .init;

pub fn main() !void {
    defer std.debug.assert(gpa_allocator.deinit() == .ok);
    const allocator = gpa_allocator.allocator();
    // first we need to preform some platform specific initialization.
    // and build a context for the current platform.
    // the context also keep a copy of the allocator you pass it
    // to use it for all allocations done by the library.
    const ctx = try widow.createWidowContext(allocator);
    defer widow.destroyWidowContext(allocator, ctx);

    // the window will require an event queue to
    // send events.
    var ev_queue = try event.EventQueue.init(allocator, 256);
    defer ev_queue.deinit();

    // create a WindowBuilder.
    var builder = widow.WindowBuilder.init();
    // customize the window.
    var mywindow = builder.withTitle("Simple Window")
        .withSize(800, 600)
        .withResize(true)
        .withDPIAware(true)
        .withPosition(200, 200)
        .withEventQueue(&ev_queue)
        .build(ctx, null) catch |err| {
        std.debug.print("Failed to build the window,{}\n", .{err});
        return;
    };

    // closes the window when done.
    defer mywindow.deinit();

    var event: event.Event = undefined;
    event_loop: while (true) {
        // wait until an event is posted.
        try mywindow.waitEvent();
        while (ev_queue.popEvent(&event)) {
            switch (event) {
                .WindowClose => |window_id| {
                    std.debug.print("closing Window #{}\n", .{window_id});
                    break :event_loop;
                },
                .Keyboard => |*key| {
                    if (key.state.isPressed()) {
                        if (key.keycode == .Q) {
                            // let's request closing the window on
                            // pressing Q key
                            mywindow.queueCloseEvent();
                        }
                    }
                },
                else => continue,
            }
        }
    }
}

Minimum Zig Version

0.15.1 The main branch will stick to stable zig releases.

Dependecies

  • zigglgen: OpenGL binding used in the gl_triangle.zig example

About

A Simple zig library for creating windows and getting inputs.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages