Skip to content

Commit

Permalink
update to 2024.10.0-mach
Browse files Browse the repository at this point in the history
  • Loading branch information
zenith391 committed Oct 21, 2024
1 parent fce2be3 commit dcc4706
Show file tree
Hide file tree
Showing 52 changed files with 247 additions and 204 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

**As of now, Capy is NOT ready for use in production as I'm still making breaking changes**

**Capy targets Zig version `0.13.0-dev.351+64ef45eb0` / `2024.5.0-mach` ([Nominated Zig versions](https://machengine.org/about/nominated-zig/))**
, but it also works on Zig `0.13.0`
**Capy targets Zig version `0.14.0-dev.1911+3bf89f55c` / `2024.10.0-mach` ([Nominated Zig versions](https://machengine.org/docs/nominated-zig/))**
, it doesn't work on Zig `0.13.0`

---

Expand Down Expand Up @@ -49,9 +49,10 @@ A simple application using capy:
```zig
const capy = @import("capy");
const std = @import("std");
pub usingnamespace capy.cross_platform;
pub fn main() !void {
try capy.backend.init();
try capy.init();
var window = try capy.Window.init();
try window.set(
Expand All @@ -60,7 +61,7 @@ pub fn main() !void {
capy.button(.{ .label = "Save", .onclick = @ptrCast(&buttonClicked) }),
capy.button(.{ .label = "Run", .onclick = @ptrCast(&buttonClicked) })
}),
// Expanded means the widget will take all the space it can
// 'expanded' means the widget will take all the space it can
// in the parent container
capy.expanded(
capy.textArea(.{ .text = "Hello World!" })
Expand All @@ -74,7 +75,7 @@ pub fn main() !void {
}
fn buttonClicked(button: *capy.Button) !void {
std.log.info("You clicked button with text {s}", .{button.getLabel()});
std.log.info("You clicked the button with text {s}", .{button.getLabel()});
}
```

Expand Down
10 changes: 5 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn installCapyDependencies(b: *std.Build, module: *std.Build.Module, options: Ca
},
.freestanding => {
if (target.result.isWasm()) {
std.log.warn("For targetting the Web, WebAssembly builds must now be compiled using the `wasm32-wasi` target.", .{});
std.log.warn("For targeting the Web, WebAssembly builds must now be compiled using the `wasm32-wasi` target.", .{});
}
return error.UnsupportedOs;
},
Expand All @@ -109,7 +109,7 @@ pub fn build(b: *std.Build) !void {
};

const module = b.addModule("capy", .{
.root_source_file = b.path("src/main.zig"),
.root_source_file = b.path("src/capy.zig"),
.target = target,
.optimize = optimize,
.imports = &.{},
Expand Down Expand Up @@ -184,7 +184,7 @@ pub fn build(b: *std.Build) !void {
// Unit tests
//
const tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.root_source_file = b.path("src/capy.zig"),
.target = target,
.optimize = optimize,
});
Expand All @@ -199,7 +199,7 @@ pub fn build(b: *std.Build) !void {
//
const docs = b.addObject(.{
.name = "capy",
.root_source_file = b.path("src/main.zig"),
.root_source_file = b.path("src/capy.zig"),
.target = target,
.optimize = .Debug,
});
Expand All @@ -219,7 +219,7 @@ pub fn build(b: *std.Build) !void {
// Coverage tests
//
const coverage_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.root_source_file = b.path("src/capy.zig"),
.target = target,
.optimize = optimize,
});
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
.lazy = true,
},
.zigimg = .{
.url = "https://github.com/zigimg/zigimg/archive/588f11f24cdc3b12f46082217dc830436b7f325e.tar.gz",
.hash = "1220dc313944ea71a87b4f54f26b1427ad2992a721a221cb42f7f80b8eee4e4944b7",
.url = "git+https://github.com/zigimg/zigimg#c3bd7f9d593d75c60e70f0a950f499e55bd2a965",
.hash = "1220a3427cad06407fb07843cf12395de92327dc629281ae17102fe09f5c1ead81c8",
},
},
.paths = .{""},
Expand Down
15 changes: 7 additions & 8 deletions build_capy.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ const WebServerStep = struct {
builder: *std.Build,
};

pub fn make(step: *std.Build.Step, prog_node: std.Progress.Node) !void {
// There's no progress to report on.
_ = prog_node;
pub fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) !void {
// Options are unused.
_ = options;

const self: *WebServerStep = @fieldParentPtr("step", step);
const allocator = step.owner.allocator;
Expand All @@ -91,7 +91,7 @@ const WebServerStep = struct {

fn handler(self: *WebServerStep, build: *std.Build, res: *Server) !void {
const allocator = build.allocator;
const prefix = comptime std.fs.path.dirname(@src().file).? ++ std.fs.path.sep_str;
const prefix = (comptime std.fs.path.dirname(@src().file) orelse "./") ++ std.fs.path.sep_str;

var req = try res.receiveHead();
var arena = std.heap.ArenaAllocator.init(allocator);
Expand Down Expand Up @@ -281,10 +281,9 @@ pub fn runStep(step: *std.Build.Step.Compile, options: CapyRunOptions) !*std.Bui
}

comptime {
const supported_zig = std.SemanticVersion.parse("0.13.0-dev.351+64ef45eb0") catch unreachable;
const other_supported_zig = std.SemanticVersion.parse("0.13.0") catch unreachable;
const supported_zig = std.SemanticVersion.parse("0.14.0-dev.1911+3bf89f55c") catch unreachable;
const zig_version = @import("builtin").zig_version;
if (zig_version.order(supported_zig) != .eq and zig_version.order(other_supported_zig) != .eq) {
@compileError(std.fmt.comptimePrint("unsupported Zig version ({}). Required Zig version 2024.5.0-mach: https://machengine.org/about/nominated-zig/#202450-mach", .{@import("builtin").zig_version}));
if (zig_version.order(supported_zig) != .eq) {
@compileError(std.fmt.comptimePrint("unsupported Zig version ({}). Required Zig version 2024.10.0-mach: https://machengine.org/docs/nominated-zig/#2024100-mach", .{@import("builtin").zig_version}));
}
}
2 changes: 1 addition & 1 deletion examples/7gui/flight-booker.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn bookFlight(button_: *anyopaque) !void {

/// Inaccurate sample date parsing routine.
pub fn parseDate(date: []const u8) !u64 {
var split = std.mem.split(u8, date, ".");
var split = std.mem.splitScalar(u8, date, '.');
const day = split.next() orelse return error.MissingDay;
const month = split.next() orelse return error.MissingMonth;
const year = split.next() orelse return error.MissingYear;
Expand Down
2 changes: 1 addition & 1 deletion examples/balls.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn main() !void {
balls = std.ArrayList(Ball).init(capy.internal.lasting_allocator);

// Generate random balls
var prng = std.rand.DefaultPrng.init(@as(u64, @bitCast(std.time.milliTimestamp())));
var prng = std.Random.DefaultPrng.init(@as(u64, @bitCast(std.time.milliTimestamp())));
const random = prng.random();
var i: usize = 0;
while (i < 100) : (i += 1) {
Expand Down
13 changes: 10 additions & 3 deletions examples/colors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const std = @import("std");
const capy = @import("capy");
pub usingnamespace capy.cross_platform;

var prng: std.rand.DefaultPrng = undefined; // initialized in main()
var prng: std.Random.DefaultPrng = undefined; // initialized in main()
var random = prng.random();

pub fn animateRandomColor(button_: *anyopaque) !void {
Expand All @@ -18,13 +18,20 @@ pub fn animateRandomColor(button_: *anyopaque) !void {
pub fn main() !void {
try capy.init();
var window = try capy.Window.init();
prng = std.rand.DefaultPrng.init(@as(u64, @bitCast(std.time.milliTimestamp())));
prng = std.Random.DefaultPrng.init(@as(u64, @bitCast(std.time.milliTimestamp())));

window.setPreferredSize(800, 600);

const selectedValue = capy.Atom([]const u8).alloc("");
defer selectedValue.deinit();

try window.set(capy.stack(.{
capy.rect(.{ .name = "background-rectangle", .color = capy.Color.transparent }),
capy.rect(.{ .name = "background-rectangle", .color = capy.Colors.transparent }),
capy.column(.{}, .{
capy.alignment(.{}, capy.button(.{ .label = "Random color", .onclick = animateRandomColor })),
// dropdown,
capy.label(.{})
.bind("text", selectedValue),
}),
}));
window.show();
Expand Down
4 changes: 2 additions & 2 deletions examples/demo.zig
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ fn drawRounded(cnv: *anyopaque, ctx: *capy.DrawContext) !void {

ctx.setColor(0.7, 0.9, 0.3);
ctx.setLinearGradient(.{ .x0 = 80, .y0 = 0, .x1 = 100, .y1 = 100, .stops = &.{
.{ .offset = 0.1, .color = capy.Color.yellow },
.{ .offset = 0.8, .color = capy.Color.red },
.{ .offset = 0.1, .color = capy.Colors.yellow },
.{ .offset = 0.8, .color = capy.Colors.red },
} });
ctx.roundedRectangleEx(
0,
Expand Down
2 changes: 1 addition & 1 deletion examples/fade.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn startAnimation(button_: *anyopaque) !void {
}

pub fn main() !void {
try capy.backend.init();
try capy.init();

var window = try capy.Window.init();
// const imageData = try capy.ImageData.fromBuffer(capy.internal.lasting_allocator, @embedFile("ziglogo.png"));
Expand Down
2 changes: 1 addition & 1 deletion examples/graph.zig
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub fn main() !void {
.{},
capy.rect(.{
.preferredSize = capy.Size{ .width = 100, .height = 100 },
.color = capy.Color.black,
.color = capy.Colors.black,
}),
))
.bind("x", &rectangleX),
Expand Down
20 changes: 10 additions & 10 deletions src/AnimationController.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ pub const AnimationCallback = struct {

const AnimationController = @This();

animated_atoms: ListAtom(*Atom),
animated_atoms: ListAtom(AnimationCallback),
on_frame: *EventSource,
listener: *Listener,
listener: ?*Listener,

pub fn init(allocator: std.mem.Allocator, on_frame: *EventSource) !*AnimationController {
const controller = try allocator.create(AnimationController);
controller.* = .{
.animated_atoms = ListAtom(*Atom).init(allocator),
.animated_atoms = ListAtom(AnimationCallback).init(allocator),
.on_frame = on_frame,
.listener = undefined,
};
Expand All @@ -28,18 +28,18 @@ pub fn init(allocator: std.mem.Allocator, on_frame: *EventSource) !*AnimationCon
.callback = update,
.userdata = controller,
});
listener.enabled.dependOn(.{controller.animated_atoms.length}, struct {
fn callback(length: usize) void {
try listener.enabled.dependOn(.{&controller.animated_atoms.length}, &struct {
fn callback(length: usize) bool {
return length > 0;
}
}.callback);
controller.listener = listener;
return controller;
}

fn update(ptr: *anyopaque) void {
const self: *AnimationController = @ptrCast(ptr);
var iterator = self.animatedAtoms.iterate();
fn update(ptr: ?*anyopaque) void {
const self: *AnimationController = @ptrCast(@alignCast(ptr.?));
var iterator = self.animated_atoms.iterate();
defer iterator.deinit();

while (iterator.next()) |item| {
Expand All @@ -51,11 +51,11 @@ fn update(ptr: *anyopaque) void {

pub fn deinit(self: *AnimationController) void {
self.animated_atoms.deinit();
self.listener.deinit();
if (self.listener) |listener| listener.deinit();
}

var null_animation_controller_instance = AnimationController{
.animated_atoms = ListAtom(*Atom).init(@import("internal.zig").lasting_allocator),
.animated_atoms = ListAtom(AnimationCallback).init(@import("internal.zig").lasting_allocator),
.on_frame = &@import("listener.zig").null_event_source,
.listener = null,
};
Expand Down
2 changes: 1 addition & 1 deletion src/assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn get(url: []const u8) GetError!AssetHandle {
// TODO: on wasm load from the web (in relative path)
// TODO: on pc make assets into a bundle and use @embedFile ? this would ease loading times on windows which
// notoriously BAD I/O performance
var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var buffer: [std.fs.max_path_bytes]u8 = undefined;
const cwd_path = try std.fs.realpath(".", &buffer);

// The URL path as a raw string (without percent-encoding)
Expand Down
2 changes: 1 addition & 1 deletion src/backend.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test "backend: create window" {
defer window.deinit();
window.show();

var prng = std.rand.Xoshiro256.init(0);
var prng = std.Random.Xoshiro256.init(std.testing.random_seed);
var random = prng.random();

{
Expand Down
2 changes: 1 addition & 1 deletion src/backends/android/backend.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const shared = @import("../shared.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const android = @import("android");
const trait = @import("../../trait.zig");

Expand Down
2 changes: 1 addition & 1 deletion src/backends/gles/backend.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const shared = @import("../shared.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const trait = @import("../../trait.zig");
const c = @cImport({
@cDefine("GLFW_INCLUDE_ES3", {});
Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/AudioGenerator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");

const AudioGenerator = @This();
Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/Button.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");

const Button = @This();
Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/Canvas.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");

const Canvas = @This();
Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/CheckBox.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");

const CheckBox = @This();
Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/Container.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");
// WindowBin
const wbin_new = @import("windowbin.zig").wbin_new;
Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/Dropdown.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");

const Dropdown = @This();
Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/ImageData.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");
const DrawContext = @import("Canvas.zig").DrawContext;

Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/Label.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");

const Label = @This();
Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/Monitor.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const c = @import("gtk.zig");
const Monitor = @This();

Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/NavigationSidebar.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");
const wbin_new = @import("windowbin.zig").wbin_new;
const wbin_set_child = @import("windowbin.zig").wbin_set_child;
Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/ScrollView.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");

const ScrollView = @This();
Expand Down
2 changes: 1 addition & 1 deletion src/backends/gtk/Slider.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const c = @import("gtk.zig");
const lib = @import("../../main.zig");
const lib = @import("../../capy.zig");
const common = @import("common.zig");

const Slider = @This();
Expand Down
Loading

0 comments on commit dcc4706

Please sign in to comment.