merged uielement

This commit is contained in:
Jorijn van der Graaf 2025-11-25 18:52:32 +01:00
commit 02a6a64c56
12 changed files with 200 additions and 506 deletions

View file

@ -6,7 +6,7 @@ using namespace Crafter;
int main() {
WindowWayland window(1280, 720, "Hello Input!");
UiElementBufferMouseBuffer* element = new UiElementBufferMouseBuffer(
UiElement* element = new UiElement(
2, //bufferWidth: the width of this elements pixel buffer
1, //bufferHeight: the height of this elements pixel buffer
FractionalToMapped(0.5), //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
@ -22,8 +22,9 @@ int main() {
window.elements.push_back(element);
window.mouseElements.push_back(element);
element->buffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
element->UpdatePosition(window);
window.ScaleMouse(element->UiElementMouse::transform, element->UiElement::transform);
window.ScaleMouse(element->mouseTransform, element->transform);
EventListener<MousePoint> clickListener(&element->onMouseLeftClick, [element, &window](MousePoint point){
// Print the coordinates where the user clicked relative to the element's top left corner.
@ -35,11 +36,9 @@ int main() {
std::cout << std::format("Clicked on Fraction X:{} Y:{}!", MappedToFractionalBoundless(point.x), MappedToFractionalBoundless(point.y)) << std::endl;
// Screen space
std::cout << std::format("Clicked on Screen X:{} Y:{}!\n", MappedToPixelBoundless(point.x, MappedToPixelBoundless(element->UiElementMouse::transform.scaled.width, window.width)), MappedToPixelBoundless(element->UiElementMouse::transform.scaled.height, window.height)) << std::endl;
std::cout << std::format("Clicked on Screen X:{} Y:{}!\n", MappedToPixelBoundless(point.x, MappedToPixelBoundless(element->mouseTransform.scaled.width, window.width)), MappedToPixelBoundless(point.y, window.height)) << std::endl;
});
element->buffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
window.Render();
window.StartSync();
}