Skip to content

Commit

Permalink
Add minimal example
Browse files Browse the repository at this point in the history
  • Loading branch information
desttinghim authored and ikskuh committed Apr 11, 2023
1 parent b5cc9ba commit 4455763
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ pub fn build(b: *std.build.Builder) !void {

// Replace by your app's main file.
// Here this is some code to choose the example to run
const ExampleType = enum { egl, textview, invocationhandler };
const ExampleType = enum { egl, minimal, textview, invocationhandler };
const example = b.option(ExampleType, "example", "Which example to run") orelse .egl;
const src = switch (example) {
.egl => "examples/egl/main.zig",
.minimal => "examples/minimal/main.zig",
.textview => "examples/textview/main.zig",
.invocationhandler => "examples/invocationhandler/main.zig",
};
Expand Down
44 changes: 44 additions & 0 deletions examples/minimal/main.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Example of a minimal application that loads a blank screen.

pub const panic = android.panic;

comptime {
_ = android.ANativeActivity_createFunc;
}

/// Entry point for our application.
/// This struct provides the interface to the android support package.
pub const AndroidApp = struct {
const Self = @This();

allocator: std.mem.Allocator,
activity: *android.ANativeActivity,

/// This is the entry point which initializes a application
/// that has stored its previous state.
/// `stored_state` is that state, the memory is only valid for this function.
pub fn init(allocator: std.mem.Allocator, activity: *android.ANativeActivity, stored_state: ?[]const u8) !Self {
_ = stored_state;

return Self{
.allocator = allocator,
.activity = activity,
};
}

/// This function is called when the application is successfully initialized.
/// It should create a background thread that processes the events and runs until
/// the application gets destroyed.
pub fn start(self: *Self) !void {
_ = self;
}

/// Uninitialize the application.
/// Don't forget to stop your background thread here!
pub fn deinit(self: *Self) void {
self.* = undefined;
}
};

const std = @import("std");
const android = @import("android");

0 comments on commit 4455763

Please sign in to comment.