added texture rendering to the example
This commit is contained in:
BIN
examples/raylib-example/res/image.png
Normal file
BIN
examples/raylib-example/res/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 233 KiB |
@@ -109,6 +109,8 @@ pub fn main() anyerror!void {
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
|
||||
defer rl.closeWindow(); // Close window and OpenGL context
|
||||
|
||||
const image = try rl.loadImage("res/image.png");
|
||||
const image_texture = try rl.Texture.fromImage(image);
|
||||
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@@ -151,180 +153,189 @@ pub fn main() anyerror!void {
|
||||
},
|
||||
}),
|
||||
|
||||
UI.Element(.{
|
||||
.name = "child",
|
||||
.style = .{ .background_colour = .{
|
||||
.b = 255,
|
||||
}, .padding = .{ .bottom = 5 } },
|
||||
.children = &[_]UI.Node{
|
||||
UI.Element(.{
|
||||
.name = "branch1",
|
||||
// .rect = .{ .w = 200 },
|
||||
.style = .{
|
||||
.size_x = .grow,
|
||||
.padding = .{
|
||||
.bottom = 5,
|
||||
.left = 5,
|
||||
.top = 5,
|
||||
.right = 5,
|
||||
},
|
||||
// .layout = .right_to_left,
|
||||
.child_gap = 5,
|
||||
},
|
||||
.children = &[_]UI.Node{
|
||||
UI.Element(.{
|
||||
.name = "branch11",
|
||||
.style = .{
|
||||
.background_colour = .{
|
||||
.g = 128,
|
||||
.b = 128,
|
||||
.r = 128,
|
||||
},
|
||||
.size_x = .grow,
|
||||
},
|
||||
.rect = .{
|
||||
.h = 40,
|
||||
.w = 40,
|
||||
},
|
||||
}),
|
||||
UI.Element(.{
|
||||
.name = "branch12",
|
||||
.style = .{
|
||||
.background_colour = .{
|
||||
.g = 128,
|
||||
.r = 128,
|
||||
},
|
||||
.size_x = .grow,
|
||||
},
|
||||
.rect = .{
|
||||
.h = 40,
|
||||
.w = 40,
|
||||
},
|
||||
}),
|
||||
UI.Element(.{
|
||||
.name = "branch13",
|
||||
.rect = .{
|
||||
.h = 40,
|
||||
.w = 40,
|
||||
},
|
||||
.style = .{
|
||||
.background_colour = .{
|
||||
.g = 90,
|
||||
.b = 150,
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
}),
|
||||
UI.Element(.{
|
||||
.name = "branch2",
|
||||
.style = .{
|
||||
.background_colour = .{
|
||||
.r = 255,
|
||||
.g = 128,
|
||||
},
|
||||
.layout = .right_to_left,
|
||||
.child_gap = 4,
|
||||
.padding = .{
|
||||
.left = 10,
|
||||
.bottom = 10,
|
||||
.right = 10,
|
||||
.top = 10,
|
||||
},
|
||||
},
|
||||
.children = &[_]UI.Node{
|
||||
UI.Element(.{
|
||||
.name = "branch21",
|
||||
.rect = .{
|
||||
.h = 30,
|
||||
.w = 30,
|
||||
},
|
||||
.style = .{
|
||||
.rounded = 40,
|
||||
.background_colour = .{
|
||||
.r = 255,
|
||||
.b = 150,
|
||||
},
|
||||
},
|
||||
}),
|
||||
UI.Element(.{
|
||||
.name = "branch22",
|
||||
.rect = .{
|
||||
.h = 30,
|
||||
.w = 30,
|
||||
},
|
||||
.style = .{
|
||||
.rounded = 40,
|
||||
.background_colour = .{
|
||||
.r = 90,
|
||||
.b = 150,
|
||||
},
|
||||
},
|
||||
}),
|
||||
UI.Element(.{
|
||||
.name = "branch21",
|
||||
.rect = .{
|
||||
.h = 30,
|
||||
.w = 30,
|
||||
},
|
||||
.style = .{
|
||||
.rounded = 40,
|
||||
.background_colour = .{
|
||||
.r = 255,
|
||||
.b = 150,
|
||||
},
|
||||
},
|
||||
}),
|
||||
UI.Element(.{
|
||||
.name = "branch22",
|
||||
.rect = .{
|
||||
.h = 30,
|
||||
.w = 30,
|
||||
},
|
||||
.style = .{
|
||||
.rounded = 40,
|
||||
.background_colour = .{
|
||||
.r = 90,
|
||||
.b = 150,
|
||||
},
|
||||
},
|
||||
}),
|
||||
UI.Element(.{
|
||||
.name = "branch21",
|
||||
.rect = .{
|
||||
.h = 30,
|
||||
.w = 30,
|
||||
},
|
||||
.style = .{
|
||||
.rounded = 40,
|
||||
.background_colour = .{
|
||||
.r = 255,
|
||||
.b = 150,
|
||||
},
|
||||
},
|
||||
}),
|
||||
UI.Element(.{
|
||||
.name = "branch22",
|
||||
.rect = .{
|
||||
.h = 30,
|
||||
.w = 30,
|
||||
},
|
||||
.style = .{
|
||||
.rounded = 40,
|
||||
.background_colour = .{
|
||||
.r = 90,
|
||||
.b = 150,
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
}),
|
||||
// UI.Element(.{
|
||||
// .name = "child",
|
||||
// .style = .{ .background_colour = .{
|
||||
// .b = 255,
|
||||
// }, .padding = .{ .bottom = 5 } },
|
||||
// .children = &[_]UI.Node{
|
||||
// UI.Element(.{
|
||||
// .name = "branch1",
|
||||
// // .rect = .{ .w = 200 },
|
||||
// .style = .{
|
||||
// .size_x = .grow,
|
||||
// .padding = .{
|
||||
// .bottom = 5,
|
||||
// .left = 5,
|
||||
// .top = 5,
|
||||
// .right = 5,
|
||||
// },
|
||||
// // .layout = .right_to_left,
|
||||
// .child_gap = 5,
|
||||
// },
|
||||
// .children = &[_]UI.Node{
|
||||
// UI.Element(.{
|
||||
// .name = "branch11",
|
||||
// .style = .{
|
||||
// .background_colour = .{
|
||||
// .g = 128,
|
||||
// .b = 128,
|
||||
// .r = 128,
|
||||
// },
|
||||
// .size_x = .grow,
|
||||
// },
|
||||
// .rect = .{
|
||||
// .h = 40,
|
||||
// .w = 40,
|
||||
// },
|
||||
// }),
|
||||
// UI.Element(.{
|
||||
// .name = "branch12",
|
||||
// .style = .{
|
||||
// .background_colour = .{
|
||||
// .g = 128,
|
||||
// .r = 128,
|
||||
// },
|
||||
// .size_x = .grow,
|
||||
// },
|
||||
// .rect = .{
|
||||
// .h = 40,
|
||||
// .w = 40,
|
||||
// },
|
||||
// }),
|
||||
// UI.Element(.{
|
||||
// .name = "branch13",
|
||||
// .rect = .{
|
||||
// .h = 40,
|
||||
// .w = 40,
|
||||
// },
|
||||
// .style = .{
|
||||
// .background_colour = .{
|
||||
// .g = 90,
|
||||
// .b = 150,
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
// },
|
||||
// }),
|
||||
// UI.Element(.{
|
||||
// .name = "branch2",
|
||||
// .style = .{
|
||||
// .background_colour = .{
|
||||
// .r = 255,
|
||||
// .g = 128,
|
||||
// },
|
||||
// .layout = .right_to_left,
|
||||
// .child_gap = 4,
|
||||
// .padding = .{
|
||||
// .left = 10,
|
||||
// .bottom = 10,
|
||||
// .right = 10,
|
||||
// .top = 10,
|
||||
// },
|
||||
// },
|
||||
// .children = &[_]UI.Node{
|
||||
// UI.Element(.{
|
||||
// .name = "branch21",
|
||||
// .rect = .{
|
||||
// .h = 30,
|
||||
// .w = 30,
|
||||
// },
|
||||
// .style = .{
|
||||
// .rounded = 40,
|
||||
// .background_colour = .{
|
||||
// .r = 255,
|
||||
// .b = 150,
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
// UI.Element(.{
|
||||
// .name = "branch22",
|
||||
// .rect = .{
|
||||
// .h = 30,
|
||||
// .w = 30,
|
||||
// },
|
||||
// .style = .{
|
||||
// .rounded = 40,
|
||||
// .background_colour = .{
|
||||
// .r = 90,
|
||||
// .b = 150,
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
// UI.Element(.{
|
||||
// .name = "branch21",
|
||||
// .rect = .{
|
||||
// .h = 30,
|
||||
// .w = 30,
|
||||
// },
|
||||
// .style = .{
|
||||
// .rounded = 40,
|
||||
// .background_colour = .{
|
||||
// .r = 255,
|
||||
// .b = 150,
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
// UI.Element(.{
|
||||
// .name = "branch22",
|
||||
// .rect = .{
|
||||
// .h = 30,
|
||||
// .w = 30,
|
||||
// },
|
||||
// .style = .{
|
||||
// .rounded = 40,
|
||||
// .background_colour = .{
|
||||
// .r = 90,
|
||||
// .b = 150,
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
// UI.Element(.{
|
||||
// .name = "branch21",
|
||||
// .rect = .{
|
||||
// .h = 30,
|
||||
// .w = 30,
|
||||
// },
|
||||
// .style = .{
|
||||
// .rounded = 40,
|
||||
// .background_colour = .{
|
||||
// .r = 255,
|
||||
// .b = 150,
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
// UI.Element(.{
|
||||
// .name = "branch22",
|
||||
// .rect = .{
|
||||
// .h = 30,
|
||||
// .w = 30,
|
||||
// },
|
||||
// .style = .{
|
||||
// .rounded = 40,
|
||||
// .background_colour = .{
|
||||
// .r = 90,
|
||||
// .b = 150,
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
// },
|
||||
// }),
|
||||
// },
|
||||
// }),
|
||||
button(),
|
||||
button(),
|
||||
UI.Image(.{
|
||||
.texture = image_texture,
|
||||
.rect = .{
|
||||
.h = @floatFromInt(image_texture.height),
|
||||
.w = @floatFromInt(image_texture.width),
|
||||
},
|
||||
}),
|
||||
button(),
|
||||
button(),
|
||||
};
|
||||
|
||||
// root.Shoots(root.TextType(raylib.Font,(function 'getTextWidth'),(function 'getTextheight')),root.TextureType(raylib.Texture)).NodeTypes
|
||||
// root.Shoots(root.TextType(raylib.Font,(function 'getTextWidth'),(function 'getTextheight')),root.TextureType(raylib.Texture)).Node
|
||||
const root = UI.Element(.{
|
||||
.name = "root",
|
||||
.pos = .{
|
||||
@@ -383,6 +394,7 @@ pub fn main() anyerror!void {
|
||||
});
|
||||
|
||||
const commands = try UI.getRenderCommands(sized, al.allocator());
|
||||
std.debug.print("{f}\n", .{sized});
|
||||
// std.debug.print("layout time : {}ms\n", .{
|
||||
// @as(f32, @floatFromInt(timer.lap())) / @as(f32, @floatFromInt(std.time.ns_per_ms)),
|
||||
// });
|
||||
@@ -431,7 +443,15 @@ pub fn main() anyerror!void {
|
||||
t.text.colour.a,
|
||||
));
|
||||
},
|
||||
.texture => continue,
|
||||
.texture => |tex| {
|
||||
// std.debug.print("{}\n", .{tex.texture.texture});
|
||||
rl.drawTexture(
|
||||
tex.texture.texture,
|
||||
@as(i32, @intFromFloat(tex.pos.x)),
|
||||
@as(i32, @intFromFloat(tex.pos.y)),
|
||||
.white,
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user