Crafter.Graphics/examples/HelloText/main.cpp

33 lines
1.7 KiB
C++
Raw Normal View History

2026-01-27 21:33:44 +01:00
import Crafter.Event;
import Crafter.Graphics;
import std;
using namespace Crafter;
int main() {
WindowWayland window(1280, 720, "Hello Input!");
RenderingElement<false, false, false> element(
{
FractionalToMapped<std::int32_t>(0), //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.1), //relativeSizeX: the relative x size this element should be scaled to compared to its parent
FractionalToMapped<std::int32_t>(1), //relativeSizeY: the relative y size this element should be scaled to compared to its parent
FractionalToMapped<std::int32_t>(0), //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), //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
);
Font font("inter.ttf");
std::string text = "testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";
element.UpdatePosition(window);
std::vector<std::string_view> lines = element.ResizeText(window, text, 200, font, TextOverflowMode::Clip, TextScaleMode::Element); // anchor.width automatically scales with our text
element.RenderText(window, lines, 200, {0,0,0,255}, font);
window.elements.push_back(&element);
window.Render();
window.StartSync();
}