glfw: allow to choose platform in InitHints
This commit is contained in:
parent
8b41d754ee
commit
99bf7df61b
1 changed files with 11 additions and 2 deletions
13
src/main.zig
13
src/main.zig
|
@ -82,7 +82,11 @@ pub inline fn init(hints: InitHints) error{ PlatformUnavailable, PlatformError }
|
||||||
inline for (comptime std.meta.fieldNames(InitHints)) |field_name| {
|
inline for (comptime std.meta.fieldNames(InitHints)) |field_name| {
|
||||||
const init_hint = @field(InitHint, field_name);
|
const init_hint = @field(InitHint, field_name);
|
||||||
const init_value = @field(hints, field_name);
|
const init_value = @field(hints, field_name);
|
||||||
initHint(init_hint, init_value);
|
if (@TypeOf(init_value) == PlatformType) {
|
||||||
|
initHint(init_hint, @enumToInt(init_value));
|
||||||
|
} else {
|
||||||
|
initHint(init_hint, init_value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.glfwInit() == c.GLFW_TRUE) return;
|
if (c.glfwInit() == c.GLFW_TRUE) return;
|
||||||
|
@ -169,6 +173,11 @@ pub const InitHints = struct {
|
||||||
/// specifies whether to create a basic menu bar, either from a nib or manually, when the first
|
/// specifies whether to create a basic menu bar, either from a nib or manually, when the first
|
||||||
/// window is created, which is when AppKit is initialized.
|
/// window is created, which is when AppKit is initialized.
|
||||||
cocoa_menubar: bool = true,
|
cocoa_menubar: bool = true,
|
||||||
|
|
||||||
|
/// Platform selection init hint.
|
||||||
|
///
|
||||||
|
/// Possible values are `PlatformType` enums.
|
||||||
|
platform: PlatformType = .any,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Initialization hints for passing into glfw.initHint
|
/// Initialization hints for passing into glfw.initHint
|
||||||
|
@ -223,6 +232,7 @@ pub const AnglePlatformType = enum(c_int) {
|
||||||
/// Platform type hints for glfw.InitHint.platform
|
/// Platform type hints for glfw.InitHint.platform
|
||||||
pub const PlatformType = enum(c_int) {
|
pub const PlatformType = enum(c_int) {
|
||||||
/// Enables automatic platform detection.
|
/// Enables automatic platform detection.
|
||||||
|
/// Will default to X11 on wayland.
|
||||||
any = c.GLFW_ANY_PLATFORM,
|
any = c.GLFW_ANY_PLATFORM,
|
||||||
win32 = c.GLFW_PLATFORM_WIN32,
|
win32 = c.GLFW_PLATFORM_WIN32,
|
||||||
cocoa = c.GLFW_PLATFORM_COCOA,
|
cocoa = c.GLFW_PLATFORM_COCOA,
|
||||||
|
@ -254,7 +264,6 @@ pub const PlatformType = enum(c_int) {
|
||||||
fn initHint(hint: InitHint, value: anytype) void {
|
fn initHint(hint: InitHint, value: anytype) void {
|
||||||
switch (@typeInfo(@TypeOf(value))) {
|
switch (@typeInfo(@TypeOf(value))) {
|
||||||
.Int, .ComptimeInt => {
|
.Int, .ComptimeInt => {
|
||||||
std.debug.assert(value == c.GLFW_TRUE or value == c.GLFW_FALSE);
|
|
||||||
c.glfwInitHint(@enumToInt(hint), @intCast(c_int, value));
|
c.glfwInitHint(@enumToInt(hint), @intCast(c_int, value));
|
||||||
},
|
},
|
||||||
.Bool => c.glfwInitHint(@enumToInt(hint), @intCast(c_int, @boolToInt(value))),
|
.Bool => c.glfwInitHint(@enumToInt(hint), @intCast(c_int, @boolToInt(value))),
|
||||||
|
|
Loading…
Add table
Reference in a new issue