commit
This commit is contained in:
parent
dfe9b1abe9
commit
c82c8c0887
35 changed files with 245 additions and 10 deletions
36
examples/HelloUI/README.md
Normal file
36
examples/HelloUI/README.md
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# 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 -c example -r
|
||||
```
|
||||
|
||||
## Relevant documentation
|
||||
|
||||
[UiElement](https://crafter-graphics.docs.catcrafts.net/classCrafter_1_1UiElement.html)
|
||||
65
examples/HelloUI/main.cpp
Normal file
65
examples/HelloUI/main.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
Crafter®.Graphics
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
import Crafter.Event;
|
||||
import Crafter.Graphics;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
WindowWaylandWayland window("HelloWindow", 1280, 720);
|
||||
|
||||
UiElement& element = window.elements.emplace_back(
|
||||
0.5, //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
|
||||
0.5, //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor
|
||||
2, //bufferWidth: the width of this elements pixel buffer
|
||||
1, //bufferHeight: the height of this elements pixel buffer
|
||||
0.5f, //relativeSizeX: the relative x size this element should be scaled to compared to its parent
|
||||
0.5f, //relativeSizeY: the relative y size this element should be scaled to compared to its parent
|
||||
0.5, //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle)
|
||||
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
|
||||
false //ignoreScaling: wether this element ignores the scaling of the window, if true its size will be scaled according to the window scale
|
||||
);
|
||||
|
||||
// UiElement& element = window.elements.emplace_back(
|
||||
// 0.5,
|
||||
// 0.5,
|
||||
// 2,
|
||||
// 1,
|
||||
// uint32_t(100), //absoluteSizeX: the absolute x size in pixels this element should be scaled to
|
||||
// uint32_t(100), //absoluteSizeY: the absolute x size in pixels this element should be scaled to
|
||||
// 0.5,
|
||||
// 0.5,
|
||||
// 0,
|
||||
// false
|
||||
// );
|
||||
|
||||
EventListener<MousePoint> clickListener(&element.onMouseLeftClick, [](MousePoint point){
|
||||
// Print the coordinates where the user clicked relative to the element's top left corner.
|
||||
std::cout << std::format("Clicked on X:{} Y:{}!", point.x, point.y) << std::endl;
|
||||
});
|
||||
|
||||
element.buffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
|
||||
window.scale = 1;
|
||||
window.StartSync();
|
||||
}
|
||||
22
examples/HelloUI/project.json
Normal file
22
examples/HelloUI/project.json
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "crafter-graphics",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "example",
|
||||
"standard": "c++26",
|
||||
"source_files": ["main"],
|
||||
"module_files": [],
|
||||
"build_dir": "build",
|
||||
"output_dir": "bin",
|
||||
"type":"executable",
|
||||
"libs": [],
|
||||
"flags": ["-Wno-uninitialized"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-debug"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue