Add init function for cleaner usage
This commit is contained in:
parent
d15b25dba6
commit
af734cda73
12 changed files with 156 additions and 91 deletions
|
|
@ -1,10 +1,6 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "uui/config.hpp"
|
||||
#include "uui/opengl/application.hpp"
|
||||
#include "uui/opengl/component.hpp"
|
||||
#include "uui/opengl/flex.hpp"
|
||||
#include "uui/opengl/label.hpp"
|
||||
#include "uui/opengl/uui.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
@ -16,67 +12,89 @@ int main()
|
|||
{
|
||||
uui::GlApplication app;
|
||||
// uui::GlApplication app2; // exception : application already created
|
||||
auto window = app.create_window(800, 600, "OpenGl!");
|
||||
app.create_window(800, 600, "OpenGl!", [](uui::GlWindow& window) {
|
||||
window.create_component(0, 100, 0.5f, 50, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.8f, 0.1f, 0.5f);
|
||||
});
|
||||
|
||||
auto comp = window->create_component(0, 100, 0.5f, 50);
|
||||
comp->set_background_color(0.8f, 0.1f, 0.5f);
|
||||
window.create_component(0.25f, 50, 0.4f, 150, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.3f, 0.8f, 0.4f, 0.5f);
|
||||
});
|
||||
|
||||
comp = window->create_component(0.25f, 50, 0.4f, 150);
|
||||
comp->set_background_color(0.3f, 0.8f, 0.4f, 0.5f);
|
||||
window.create_label(50, 50, "Hello World!", {0.5f, 1.0f, 0.5f, 1.0f}, [](uui::GlLabel& label) {
|
||||
label.set_background_color(0.1f, 0.2f, 0.5f, 0.8f);
|
||||
});
|
||||
|
||||
auto label = window->create_label(50, 50, "Hello World!", {0.5f, 1.0f, 0.5f, 1.0f});
|
||||
label->set_background_color(0.1f, 0.2f, 0.5f, 0.8f);
|
||||
window.create_label(0.5f, 0.5f, "Hello World!", {1.0f, 1.0f, 1.0f, 0.5f}, [](uui::GlLabel& label) {
|
||||
label.set_background_color(0.5f, 0.5f, 0.1f);
|
||||
});
|
||||
window.create_label(0.75f, 0.75f, "Hello World!", {1.0f, 1.0f, 1.0f, 0.1f}, {});
|
||||
|
||||
label = window->create_label(0.5f, 0.5f, "Hello World!", {1.0f, 1.0f, 1.0f, 0.5f});
|
||||
label->set_background_color(0.5f, 0.5f, 0.1f);
|
||||
label = window->create_label(0.75f, 0.75f, "Hello World!", {1.0f, 1.0f, 1.0f, 0.1f});
|
||||
window.create_flex(200, 0.6f, uui::Direction::HORIZONTAL, [](uui::GlFlex& flex) {
|
||||
flex.create_component(100, 50, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.2f, 0.75f, 0.25f);
|
||||
});
|
||||
flex.create_label("test", {0.8f, 0.2f, 0.2f, 1.0f}, {});
|
||||
flex.create_component(100, 20, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.2f, 0.25f, 0.75f);
|
||||
});
|
||||
});
|
||||
|
||||
auto flex = window->create_flex(200, 0.6f, uui::Direction::HORIZONTAL);
|
||||
comp = flex->create_component(100, 50);
|
||||
comp->set_background_color(0.2f, 0.75f, 0.25f);
|
||||
flex->create_label("test", {0.8f, 0.2f, 0.2f, 1.0f});
|
||||
comp = flex->create_component(100, 20);
|
||||
comp->set_background_color(0.2f, 0.25f, 0.75f);
|
||||
window.create_flex(50, 400, uui::Direction::VERTICAL, [](uui::GlFlex& flex) {
|
||||
flex.create_component(50, 100, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.2f, 0.75f, 0.25f);
|
||||
});
|
||||
flex.create_label("test", {0.8f, 0.2f, 0.2f, 1.0f}, {});
|
||||
flex.create_component(100, 20, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.2f, 0.25f, 0.75f);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
flex = window->create_flex(50, 400, uui::Direction::VERTICAL);
|
||||
comp = flex->create_component(50, 100);
|
||||
comp->set_background_color(0.2f, 0.75f, 0.25f);
|
||||
flex->create_label("test", {0.8f, 0.2f, 0.2f, 1.0f});
|
||||
comp = flex->create_component(100, 20);
|
||||
comp->set_background_color(0.2f, 0.25f, 0.75f);
|
||||
app.create_window(800, 600, "OpenGl 2", [](uui::GlWindow& window) {
|
||||
window.create_stack(200, 0.6f, uui::Direction::HORIZONTAL, [](uui::GlStack& stack) {
|
||||
stack.create_component(100, 50, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.2f, 0.75f, 0.25f);
|
||||
});
|
||||
stack.create_label("test", {0.8f, 0.2f, 0.2f, 1.0f}, {});
|
||||
stack.create_component(100, 20, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.2f, 0.25f, 0.75f);
|
||||
});
|
||||
});
|
||||
|
||||
window = app.create_window(800, 600, "OpenGl 2");
|
||||
|
||||
auto stack = window->create_stack(200, 0.6f, uui::Direction::HORIZONTAL);
|
||||
comp = stack->create_component(100, 50);
|
||||
comp->set_background_color(0.2f, 0.75f, 0.25f);
|
||||
stack->create_label("test", {0.8f, 0.2f, 0.2f, 1.0f});
|
||||
comp = stack->create_component(100, 20);
|
||||
comp->set_background_color(0.2f, 0.25f, 0.75f);
|
||||
|
||||
stack = window->create_stack(50, 400, uui::Direction::VERTICAL);
|
||||
comp = stack->create_component(50, 100);
|
||||
comp->set_background_color(0.2f, 0.75f, 0.25f);
|
||||
stack->create_label("test", {0.8f, 0.2f, 0.2f, 1.0f});
|
||||
comp = stack->create_component(100, 20);
|
||||
comp->set_background_color(0.2f, 0.25f, 0.75f);
|
||||
window.create_stack(50, 400, uui::Direction::VERTICAL, [](uui::GlStack& stack) {
|
||||
stack.create_component(100, 50, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.2f, 0.75f, 0.25f);
|
||||
});
|
||||
stack.create_label("test", {0.8f, 0.2f, 0.2f, 1.0f}, {});
|
||||
stack.create_component(100, 20, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.2f, 0.25f, 0.75f);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.run();
|
||||
}
|
||||
cout << "\nStarting example 2" << endl;
|
||||
{
|
||||
uui::GlApplication app;
|
||||
auto window_1 = app.create_window(800, 600, "OpenGl!");
|
||||
auto comp = window_1->create_component(0.25f, 0.25f, 0.5f, 0.5f);
|
||||
comp->set_background_color(0.8f, 0.1f, 0.5f);
|
||||
comp = window_1->create_component(0.75f, 0.75f, 0.25f, 0.25f);
|
||||
comp->set_background_color(0.2f, 0.1f, 0.5f);
|
||||
app.create_window(800, 600, "OpenGl!", [](uui::GlWindow& window) {
|
||||
window.create_component(0.25f, 0.25f, 0.5f, 0.5f, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.8f, 0.1f, 0.5f);
|
||||
});
|
||||
window.create_component(0.75f, 0.75f, 0.25f, 0.25f, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.2f, 0.1f, 0.5f);
|
||||
});
|
||||
});
|
||||
|
||||
auto window_2 = app.create_window(600, 600, "OpenGL 2!");
|
||||
comp = window_2->create_component(0, 0.5f, 100, 0.5f);
|
||||
comp->set_background_color(0.2f, 0.5f, 0.3f);
|
||||
auto label = window_2->create_label(50, 50, "Hello World!", {0.5f, 1.0f, 0.5f, 1.0f});
|
||||
label->set_background_color(0.1f, 0.2f, 0.5f);
|
||||
app.create_window(600, 600, "OpenGL 2!", [](uui::GlWindow& window) {
|
||||
window.create_component(0, 0.5f, 100, 0.5f, [](uui::GlComponent& component) {
|
||||
component.set_background_color(0.2f, 0.5f, 0.3f);
|
||||
});
|
||||
window.create_label(50, 50, "Hello World!", {0.5f, 1.0f, 0.5f, 1.0f}, [](uui::GlLabel& label) {
|
||||
label.set_background_color(0.1f, 0.2f, 0.5f);
|
||||
});
|
||||
});
|
||||
app.run();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue