the great text and type rewrite

This commit is contained in:
Jorijn van der Graaf 2025-12-30 23:28:38 +01:00
commit d0cc3ad16a
15 changed files with 628 additions and 318 deletions

View file

@ -8,12 +8,12 @@ int main() {
RenderingElement<true, true, false> element(
{
FractionalToMapped(0.5), //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
FractionalToMapped(0.5), //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor
FractionalToMapped(0.5), //relativeSizeX: the relative x size this element should be scaled to compared to its parent
FractionalToMapped(0.5), //relativeSizeY: the relative y size this element should be scaled to compared to its parent
FractionalToMapped(0.5), //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle)
FractionalToMapped(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)
FractionalToMapped<std::int32_t>(0.5), //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
FractionalToMapped<std::int32_t>(0.5), //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor
FractionalToMapped<std::int32_t>(0.5), //relativeSizeX: the relative x size this element should be scaled to compared to its parent
FractionalToMapped<std::int32_t>(0.5), //relativeSizeY: the relative y size this element should be scaled to compared to its parent
FractionalToMapped<std::int32_t>(0.5), //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle)
FractionalToMapped<std::int32_t>(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
},
OpaqueType::FullyOpaque,
@ -21,32 +21,23 @@ int main() {
1
);
MouseElement mouse({
FractionalToMapped(0), //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
FractionalToMapped(0), //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor
FractionalToMapped(1), //relativeSizeX: the relative x size this element should be scaled to compared to its parent
FractionalToMapped(1), //relativeSizeY: the relative y size this element should be scaled to compared to its parent
FractionalToMapped(0), //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle)
FractionalToMapped(0), //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
}, window);
MouseElement mouse(window);
element.children.push_back(&mouse);
window.elements.push_back(&element);
element.scalingBuffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
element.UpdatePosition(window);
EventListener<MousePoint> clickListener(&mouse.onMouseLeftClick, [&mouse, &window](MousePoint point){
EventListener<MousePoint> clickListener(&mouse.onMouseLeftClick, [&mouse, &window](MousePoint point) {
// Print the coordinates where the user clicked relative to the element's top left corner.
//Mapped space
std::cout << std::format("Clicked on Mapped X:{} Y:{}!", point.x, point.y) << std::endl;
// Fraction space
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(mouse.scaled.width, window.width)), MappedToPixelBoundless(point.y, MappedToPixelBoundless(mouse.scaled.width, window.height))) << std::endl;
std::println("Clicked on Mapped X:{} Y:{}!\nClicked on Fraction X:{} Y:{}!\nClicked on Screen X:{} Y:{}!\n",
//Mapped space
point.x, point.y,
// Fraction space
MappedToFractionalBoundless(point.x), MappedToFractionalBoundless(point.y),
// Screen space
MappedToAbsoluteBoundless(point.x, MappedToAbsoluteBoundless(mouse.mouseScaled.width, window.width)), MappedToAbsoluteBoundless(point.y, MappedToAbsoluteBoundless(mouse.mouseScaled.width, window.height))
);
});
window.Render();