text example
This commit is contained in:
parent
d0cc3ad16a
commit
4b34eb3972
5 changed files with 82 additions and 369 deletions
32
examples/HelloText/README.md
Normal file
32
examples/HelloText/README.md
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# HelloWindow Example
|
||||
|
||||
## Description
|
||||
|
||||
This example demonstrates how to draw pixels to a window.
|
||||
|
||||
## Expected Result
|
||||
|
||||
A window with a green and blue colored square, when clicking on the square it logs the coordinates relative to the square.
|
||||
|
||||
## Highlighted Code Snippet
|
||||
|
||||
```cpp
|
||||
UiElement& element = window.elements.emplace_back(
|
||||
0.5,
|
||||
0.5,
|
||||
2,
|
||||
1,
|
||||
0.5f,
|
||||
0.5f,
|
||||
0.5,
|
||||
0.5,
|
||||
0,
|
||||
false
|
||||
);
|
||||
```
|
||||
|
||||
## How to Run
|
||||
|
||||
```bash
|
||||
crafter-build build executable -r
|
||||
```
|
||||
BIN
examples/HelloText/inter.ttf
Normal file
BIN
examples/HelloText/inter.ttf
Normal file
Binary file not shown.
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();
|
||||
}
|
||||
|
||||
17
examples/HelloText/project.json
Normal file
17
examples/HelloText/project.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "crafter-graphics",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "executable",
|
||||
"implementations": ["main"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-wayland-debug"
|
||||
}
|
||||
],
|
||||
"debug": true,
|
||||
"additional_files": ["inter.ttf"]
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue