Crafter.Graphics/examples/HelloUI/main.cpp

30 lines
1.7 KiB
C++
Raw Normal View History

2025-06-13 23:59:36 +02:00
import Crafter.Event;
import Crafter.Graphics;
2025-11-16 18:52:52 +01:00
import std;
2025-06-13 23:59:36 +02:00
using namespace Crafter;
int main() {
2025-11-22 20:58:42 +01:00
Window<true, false, false, false> window(1280, 720);
2025-06-13 23:59:36 +02:00
2025-11-22 20:58:42 +01:00
UiElement<true, true>& element = window.CreateElement<true, true>(
2025-06-14 01:45:33 +02:00
2, //bufferWidth: the width of this elements pixel buffer
1, //bufferHeight: the height of this elements pixel buffer
2025-11-22 20:58:42 +01:00
0.5, //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
0.5, //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor
2025-06-14 01:45:33 +02:00
0.5f, //relativeSizeX: the relative x size this element should be scaled to compared to its parent
0.5f, //relativeSizeY: the relative y size this element should be scaled to compared to its parent
0.5, //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle)
0.5, //anchorOffsetY: the amount this element's anchor should be offset from the top left corner (0.5 to place it in the middle)
0, //z: this elements Z position
false //ignoreScaling: wether this element ignores the scaling of the window, if true its size will be scaled according to the window scale
);
2025-11-22 20:58:42 +01:00
// EventListener<MousePoint> clickListener(&element.onMouseLeftClick, [](MousePoint point){
// // Print the coordinates where the user clicked relative to the element's top left corner.
// std::cout << std::format("Clicked on X:{} Y:{}!", point.x, point.y) << std::endl;
// });
2025-06-14 01:45:33 +02:00
2025-11-22 20:58:42 +01:00
element.buffer.buffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
window.framebuffer.Render();
2025-06-13 23:59:36 +02:00
window.StartSync();
}