Crafter.Graphics/examples/HelloGrid/main.cpp

61 lines
2.1 KiB
C++
Raw Permalink Normal View History

2025-11-27 00:38:47 +01:00
import Crafter.Event;
import Crafter.Graphics;
import std;
using namespace Crafter;
int main() {
WindowWayland window(1280, 720, "Hello Grid!");
// Create a GridElement with 3 columns and 2 rows
GridElement grid(
3, // columns
2, // rows
FractionalToMapped(0.1), // spacingX
FractionalToMapped(0.1), // spacingY
FractionalToMapped(0), // anchorX
FractionalToMapped(0), // anchorY
FractionalToMapped(1), // relativeWidth
FractionalToMapped(1), // relativeHeight
FractionalToMapped(0), // anchorOffsetX
FractionalToMapped(0), // anchorOffsetY
0, // z
false // ignoreScaling
);
for (int i = 0; i < 6; i++) {
RenderingElementScaling* rendering = new RenderingElementScaling(
OpaqueType::FullyOpaque,
1,
1,
FractionalToMapped(0.5), // anchorX
FractionalToMapped(0.5), // anchorY
FractionalToMapped(1.0), // relativeSizeX (will be overridden by grid)
FractionalToMapped(1.0), // relativeSizeY (will be overridden by grid)
FractionalToMapped(0.0), // anchorOffsetX
FractionalToMapped(0.0), // anchorOffsetY
0, // z
false // ignoreScaling
);
// // Set different colors for each element
switch (i % 6) {
case 0: rendering->buffer = {{255, 0, 0, 255}}; break; // Red
case 1: rendering->buffer = {{0, 255, 0, 255}}; break; // Green
case 2: rendering->buffer = {{0, 0, 255, 255}}; break; // Blue
case 3: rendering->buffer = {{255, 255, 0, 255}}; break; // Yellow
case 4: rendering->buffer = {{255, 0, 255, 255}}; break; // Magenta
case 5: rendering->buffer = {{0, 255, 255, 255}}; break; // Cyan
}
grid.children.push_back(rendering);
}
// Add the grid to the window
window.elements.push_back(&grid);
// Update positions to arrange children in grid
grid.UpdatePosition(window);
window.Render();
window.StartSync();
}