text example
This commit is contained in:
parent
d0cc3ad16a
commit
4b34eb3972
5 changed files with 82 additions and 369 deletions
33
examples/HelloText/main.cpp
Normal file
33
examples/HelloText/main.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue