Files
quip/example/example.cpp

43 lines
1.5 KiB
C++
Raw Normal View History

2025-11-01 15:54:37 +00:00
#include <quip.h>
int main() {
2025-11-02 17:48:43 +00:00
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;
}
}
});
2025-11-01 15:54:37 +00:00
int buttonPresses = 0;
window.addChild("textLabel", Quip::Widget::TextLabel("Hi there!", 10, 10));
window.addChild("button", Quip::Widget::Button("Click me!", [&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));
2025-11-02 17:48:43 +00:00
window.addChild("image", Quip::Widget::Image("dingus.png", 300, 300, 100, 100));
2025-11-01 15:54:37 +00:00
return window.run();
}