Autopositioning, custom fonts

This commit is contained in:
2025-11-08 12:27:38 +00:00
parent 9aae7b6173
commit 065f07bc58
4 changed files with 372 additions and 83 deletions

View File

@@ -1,42 +1,17 @@
#include <quip.h>
int main() {
bool goingDown = true, goingRight = true;
Quip::Window window("Quip Window", 800, 600, [&window, &goingDown, &goingRight]() {
auto* imagewidget = window.getChild("image");
auto& image = std::get<Quip::Widget::Image>(*imagewidget);
if (goingDown) {
image.ypos ++;
if (image.ypos + image.height > window.height) {
goingDown = false;
}
} else {
image.ypos --;
if (image.ypos < 0) {
goingDown = true;
}
}
if (goingRight) {
image.xpos ++;
if (image.xpos + image.width > window.width) {
goingRight = false;
}
} else {
image.xpos --;
if (image.xpos < 0) {
goingRight = true;
}
}
});
int buttonPresses = 0;
window.addChild("textLabel", Quip::Widget::TextLabel("Hi there!", 10, 10));
window.addChild("button", Quip::Widget::Button("Click me!", [&window, &buttonPresses]() {
Quip::Window window("Quip Window", 800, 600);
Quip::Font font("/usr/share/fonts/noto/NotoSans-Regular.ttf", 16);
window.addChild("image", Quip::Widget::Image("dingus.png", 100, 100));
window.addChild("textLabel", Quip::Widget::TextLabel("Hi there!", font));
window.addChild("button", Quip::Widget::Button(Quip::Widget::TextLabel("Click me!", font), [&window, &buttonPresses] {
auto* widget = window.getChild("textLabel");
if (widget && std::holds_alternative<Quip::Widget::TextLabel>(*widget)) {
buttonPresses++;
std::get<Quip::Widget::TextLabel>(*widget).text = "You have clicked the button " + std::to_string(buttonPresses) + " times!";
}
}, 10, 50));
window.addChild("image", Quip::Widget::Image("dingus.png", 300, 300, 100, 100));
}));
return window.run();
}