Add parameters structures
* Changed C++ version from 17 to 20 (using designated initializers)
This commit is contained in:
parent
73934d0e34
commit
6427c7aeb7
19 changed files with 142 additions and 149 deletions
|
|
@ -22,8 +22,8 @@ protected:
|
||||||
|
|
||||||
uui::position_t position_x;
|
uui::position_t position_x;
|
||||||
uui::position_t position_y;
|
uui::position_t position_y;
|
||||||
uui::position_t size_width;
|
uui::size_t size_width;
|
||||||
uui::position_t size_height;
|
uui::size_t size_height;
|
||||||
|
|
||||||
bool coord_all_relative;
|
bool coord_all_relative;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,9 @@ protected:
|
||||||
|
|
||||||
GlComponent(
|
GlComponent(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||||
std::size_t parent_index, const position_t x, const position_t y, const position_t width,
|
std::size_t parent_index, const ComponentParams& params);
|
||||||
const position_t height);
|
GlComponent(std::shared_ptr<GlWindow> window, std::size_t window_index, const ComponentParams& params):
|
||||||
GlComponent(
|
GlComponent(window, window_index, std::static_pointer_cast<GlContainer>(window), window_index, params)
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
|
||||||
const position_t width, const position_t height):
|
|
||||||
GlComponent(
|
|
||||||
window, window_index, std::static_pointer_cast<GlContainer>(window), window_index, x, y, width, height)
|
|
||||||
{}
|
{}
|
||||||
GlComponent(const GlComponent&) = delete;
|
GlComponent(const GlComponent&) = delete;
|
||||||
GlComponent(GlComponent&&) = default;
|
GlComponent(GlComponent&&) = default;
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,9 @@ class GlFlex: virtual public GlStack, virtual public Flex
|
||||||
protected:
|
protected:
|
||||||
GlFlex(
|
GlFlex(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||||
std::size_t parent_index, const position_t x, const position_t y, const Direction direction);
|
std::size_t parent_index, const StackParams& params);
|
||||||
GlFlex(
|
GlFlex(std::shared_ptr<GlWindow> window, std::size_t window_index, const StackParams& params):
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
GlFlex(window, window_index, window, window_index, params)
|
||||||
const Direction direction):
|
|
||||||
GlFlex(window, window_index, window, window_index, x, y, direction)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::tuple<int, int> get_child_position(const std::size_t child_index) const override;
|
std::tuple<int, int> get_child_position(const std::size_t child_index) const override;
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,9 @@ protected:
|
||||||
|
|
||||||
GlLabel(
|
GlLabel(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||||
std::size_t parent_index, const position_t x, const position_t y, const std::string& text,
|
std::size_t parent_index, const LabelParams& params);
|
||||||
const std::tuple<float, float, float, float>& text_color);
|
GlLabel(std::shared_ptr<GlWindow> window, std::size_t window_index, const LabelParams& params):
|
||||||
GlLabel(
|
GlLabel(window, window_index, window, window_index, params)
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
|
||||||
const std::string& text, const std::tuple<float, float, float, float>& text_color):
|
|
||||||
GlLabel(window, window_index, window, window_index, x, y, text, text_color)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void render() final;
|
void render() final;
|
||||||
|
|
|
||||||
|
|
@ -15,19 +15,15 @@ class GlStack: virtual public GlComponent, virtual public GlContainer, virtual p
|
||||||
friend class GlWindow;
|
friend class GlWindow;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void create_component(const position_t width, const position_t height, InitFunction<Component> init) override;
|
void create_component(const StackComponentParams& params, InitFunction<Component> init) override;
|
||||||
void create_label(
|
void create_label(const StackLabelParams& params, InitFunction<Label> init) override;
|
||||||
const std::string& text, const std::tuple<float, float, float, float>& text_color,
|
|
||||||
InitFunction<Label> init) override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GlStack(
|
GlStack(
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||||
std::size_t parent_index, const position_t x, const position_t y, const Direction direction);
|
std::size_t parent_index, const StackParams& params);
|
||||||
GlStack(
|
GlStack(std::shared_ptr<GlWindow> window, std::size_t window_index, const StackParams& params):
|
||||||
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
GlStack(window, window_index, window, window_index, params)
|
||||||
const Direction direction):
|
|
||||||
GlStack(window, window_index, window, window_index, x, y, direction)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::tuple<int, int> get_child_position(const std::size_t child_index) const override;
|
std::tuple<int, int> get_child_position(const std::size_t child_index) const override;
|
||||||
|
|
|
||||||
|
|
@ -26,15 +26,10 @@ public:
|
||||||
GlWindow(GlWindow&&) = delete;
|
GlWindow(GlWindow&&) = delete;
|
||||||
~GlWindow();
|
~GlWindow();
|
||||||
|
|
||||||
void create_component(
|
void create_component(const ComponentParams& params, InitFunction<Component> init) final;
|
||||||
const position_t x, const position_t y, const position_t width, const position_t height,
|
void create_label(const LabelParams& params, InitFunction<Label> init) final;
|
||||||
InitFunction<Component> init) final;
|
void create_flex(const StackParams& params, InitFunction<Flex> init) final;
|
||||||
void create_label(
|
void create_stack(const StackParams& params, InitFunction<Stack> init) final;
|
||||||
const position_t x, const position_t y, const std::string& text,
|
|
||||||
const std::tuple<float, float, float, float>& text_color, InitFunction<Label> init) final;
|
|
||||||
void create_flex(const position_t x, const position_t y, const Direction direction, InitFunction<Flex> init) final;
|
|
||||||
void create_stack(
|
|
||||||
const position_t x, const position_t y, const Direction direction, InitFunction<Stack> init) final;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void render() final;
|
void render() final;
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,8 @@ namespace uui
|
||||||
class Stack: virtual public Component
|
class Stack: virtual public Component
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void create_component(const position_t width, const position_t height, InitFunction<Component> init) = 0;
|
virtual void create_component(const StackComponentParams& params, InitFunction<Component> init) = 0;
|
||||||
virtual void create_label(
|
virtual void create_label(const StackLabelParams& params, InitFunction<Label> init) = 0;
|
||||||
const std::string& text, const std::tuple<float, float, float, float>& text_color,
|
|
||||||
InitFunction<Label> init) = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Direction direction;
|
Direction direction;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <tuple>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
namespace uui
|
namespace uui
|
||||||
|
|
@ -8,9 +9,43 @@ namespace uui
|
||||||
template<typename T> using InitFunction = const std::function<void(T&)>&;
|
template<typename T> using InitFunction = const std::function<void(T&)>&;
|
||||||
typedef std::variant<int, float> position_t;
|
typedef std::variant<int, float> position_t;
|
||||||
typedef std::variant<int, float> size_t;
|
typedef std::variant<int, float> size_t;
|
||||||
|
typedef std::tuple<float, float, float, float> color_t;
|
||||||
|
|
||||||
enum Direction
|
enum Direction
|
||||||
{
|
{
|
||||||
HORIZONTAL,
|
HORIZONTAL,
|
||||||
VERTICAL
|
VERTICAL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ComponentParams
|
||||||
|
{
|
||||||
|
uui::position_t x;
|
||||||
|
uui::position_t y;
|
||||||
|
uui::size_t width;
|
||||||
|
uui::size_t height;
|
||||||
|
};
|
||||||
|
struct LabelParams
|
||||||
|
{
|
||||||
|
uui::position_t x;
|
||||||
|
uui::position_t y;
|
||||||
|
const std::string& text;
|
||||||
|
const uui::color_t& text_color;
|
||||||
|
};
|
||||||
|
struct StackParams
|
||||||
|
{
|
||||||
|
const uui::position_t x;
|
||||||
|
const uui::position_t y;
|
||||||
|
const uui::Direction direction;
|
||||||
|
};
|
||||||
|
struct StackComponentParams
|
||||||
|
{
|
||||||
|
uui::size_t width;
|
||||||
|
uui::size_t height;
|
||||||
|
};
|
||||||
|
struct StackLabelParams
|
||||||
|
{
|
||||||
|
const std::string& text;
|
||||||
|
const uui::color_t& text_color;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace uui
|
} // namespace uui
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "uui/application.hpp"
|
#include "uui/application.hpp"
|
||||||
#include "uui/container.hpp"
|
#include "uui/container.hpp"
|
||||||
|
|
@ -24,16 +23,10 @@ public:
|
||||||
|
|
||||||
std::shared_ptr<FontManager> font_manager;
|
std::shared_ptr<FontManager> font_manager;
|
||||||
|
|
||||||
virtual void create_component(
|
virtual void create_component(const ComponentParams& params, InitFunction<Component> init) = 0;
|
||||||
const position_t x, const position_t y, const position_t width, const position_t height,
|
virtual void create_label(const LabelParams& params, InitFunction<Label> init) = 0;
|
||||||
InitFunction<Component> init) = 0;
|
virtual void create_flex(const StackParams& params, InitFunction<Flex> init) = 0;
|
||||||
virtual void create_label(
|
virtual void create_stack(const StackParams& params, InitFunction<Stack> init) = 0;
|
||||||
const position_t x, const position_t y, const std::string& text,
|
|
||||||
const std::tuple<float, float, float, float>& text_color, InitFunction<Label> init) = 0;
|
|
||||||
virtual void create_flex(
|
|
||||||
const position_t x, const position_t y, const Direction direction, InitFunction<Flex> init) = 0;
|
|
||||||
virtual void create_stack(
|
|
||||||
const position_t x, const position_t y, const Direction direction, InitFunction<Stack> init) = 0;
|
|
||||||
|
|
||||||
int width() { return _width; };
|
int width() { return _width; };
|
||||||
int height() { return _height; };
|
int height() { return _height; };
|
||||||
|
|
|
||||||
2
make.py
2
make.py
|
|
@ -18,7 +18,7 @@ class Config:
|
||||||
OBJECT_DIR = Path('obj')
|
OBJECT_DIR = Path('obj')
|
||||||
SOURCE_DIR = Path('src')
|
SOURCE_DIR = Path('src')
|
||||||
|
|
||||||
COMMON_FLAGS = '-std=c++17 -fno-semantic-interposition'
|
COMMON_FLAGS = '-std=c++20 -fno-semantic-interposition'
|
||||||
COMMON_DEBUG_FLAGS = '-g -Og -DDEBUG'
|
COMMON_DEBUG_FLAGS = '-g -Og -DDEBUG'
|
||||||
COMMON_RELEASE_FLAGS = '-O2 -flto=auto'
|
COMMON_RELEASE_FLAGS = '-O2 -flto=auto'
|
||||||
COMPILE_FLAGS = f'-Wall -Wextra -Wpedantic -Wconversion -I{INCLUDE_DIR} `pkg-config --cflags glfw3 vulkan gl x11 freetype2`'
|
COMPILE_FLAGS = f'-Wall -Wextra -Wpedantic -Wconversion -I{INCLUDE_DIR} `pkg-config --cflags glfw3 vulkan gl x11 freetype2`'
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,9 @@ int main()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto app = uui::create_application(uui::Application::OPENGL);
|
auto app = uui::create_application(uui::Application::OPENGL);
|
||||||
// auto app2 = uui::create_application(uui::Application::OPENGL); // exception : application already created
|
|
||||||
app->create_window(800, 600, "OpenGl!", [](uui::Window& window) {
|
app->create_window(800, 600, "OpenGl!", [](uui::Window& window) {
|
||||||
for(int i = 0; i < 100; i += 1)
|
for(int i = 0; i < 100; i += 1)
|
||||||
window.create_label(4 * i, 4 * i, "Hello World!", {1.0f, 1.0f, 1.0f, 0.5f}, {});
|
window.create_label({4 * i, 4 * i, "Hello World!", {1.0f, 1.0f, 1.0f, 0.5f}}, nullptr);
|
||||||
});
|
});
|
||||||
app->run();
|
app->run();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,55 +13,64 @@ int main()
|
||||||
auto app = uui::create_application(uui::Application::OPENGL);
|
auto app = uui::create_application(uui::Application::OPENGL);
|
||||||
// auto app2 = uui::create_application(uui::Application::OPENGL); // exception : application already created
|
// auto app2 = uui::create_application(uui::Application::OPENGL); // exception : application already created
|
||||||
app->create_window(800, 600, "OpenGl!", [](uui::Window& window) {
|
app->create_window(800, 600, "OpenGl!", [](uui::Window& window) {
|
||||||
window.create_component(0, 100, 0.5f, 50, [](uui::Component& component) {
|
window.create_component({.x = 0, .y = 100, .width = 0.5f, .height = 50}, [](uui::Component& component) {
|
||||||
component.set_background_color(0.8f, 0.1f, 0.5f);
|
component.set_background_color(0.8f, 0.1f, 0.5f);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.create_component(0.25f, 50, 0.4f, 150, [](uui::Component& component) {
|
window.create_component(
|
||||||
component.set_background_color(0.3f, 0.8f, 0.4f, 0.5f);
|
{.x = 0.25f, .y = 50, .width = 0.4f, .height = 150},
|
||||||
});
|
[](uui::Component& component) { component.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::Label& label) {
|
window.create_label(
|
||||||
label.set_background_color(0.1f, 0.2f, 0.5f, 0.8f);
|
{.x = 50, .y = 50, .text = "Hello World!", .text_color = {0.5f, 1.0f, 0.5f, 1.0f}},
|
||||||
});
|
[](uui::Label& label) { 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::Label& label) {
|
window.create_label({0.5f, 0.5f, "Hello World!", {1.0f, 1.0f, 1.0f, 0.5f}}, [](uui::Label& label) {
|
||||||
label.set_background_color(0.5f, 0.5f, 0.1f);
|
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}, {});
|
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::Flex& flex) {
|
window.create_flex({200, 0.6f, uui::Direction::HORIZONTAL}, [](uui::Flex& flex) {
|
||||||
flex.create_component(
|
flex.create_component({.width = 100, .height = 50}, [](uui::Component& component) {
|
||||||
100, 50, [](uui::Component& component) { component.set_background_color(0.2f, 0.75f, 0.25f); });
|
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(
|
flex.create_label({.text = "test", .text_color = {0.8f, 0.2f, 0.2f, 1.0f}}, {});
|
||||||
100, 20, [](uui::Component& component) { component.set_background_color(0.2f, 0.25f, 0.75f); });
|
flex.create_component({100, 20}, [](uui::Component& component) {
|
||||||
|
component.set_background_color(0.2f, 0.25f, 0.75f);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
window.create_flex(50, 400, uui::Direction::VERTICAL, [](uui::Flex& flex) {
|
window.create_flex({50, 400, uui::Direction::VERTICAL}, [](uui::Flex& flex) {
|
||||||
flex.create_component(
|
flex.create_component({50, 100}, [](uui::Component& component) {
|
||||||
50, 100, [](uui::Component& component) { component.set_background_color(0.2f, 0.75f, 0.25f); });
|
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(
|
flex.create_label({"test", {0.8f, 0.2f, 0.2f, 1.0f}}, {});
|
||||||
100, 20, [](uui::Component& component) { component.set_background_color(0.2f, 0.25f, 0.75f); });
|
flex.create_component({100, 20}, [](uui::Component& component) {
|
||||||
|
component.set_background_color(0.2f, 0.25f, 0.75f);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app->create_window(800, 600, "OpenGl 2", [](uui::Window& window) {
|
app->create_window(800, 600, "OpenGl 2", [](uui::Window& window) {
|
||||||
window.create_stack(200, 0.6f, uui::Direction::HORIZONTAL, [](uui::Stack& stack) {
|
window.create_stack(
|
||||||
stack.create_component(
|
{.x = 200, .y = 0.6f, .direction = uui::Direction::HORIZONTAL}, [](uui::Stack& stack) {
|
||||||
100, 50, [](uui::Component& component) { component.set_background_color(0.2f, 0.75f, 0.25f); });
|
stack.create_component({.width = 100, .height = 50}, [](uui::Component& component) {
|
||||||
stack.create_label("test", {0.8f, 0.2f, 0.2f, 1.0f}, {});
|
component.set_background_color(0.2f, 0.75f, 0.25f);
|
||||||
stack.create_component(
|
});
|
||||||
100, 20, [](uui::Component& component) { component.set_background_color(0.2f, 0.25f, 0.75f); });
|
stack.create_label({.text = "test", .text_color = {0.8f, 0.2f, 0.2f, 1.0f}}, {});
|
||||||
|
stack.create_component({.width = 100, .height = 20}, [](uui::Component& component) {
|
||||||
|
component.set_background_color(0.2f, 0.25f, 0.75f);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
window.create_stack(50, 400, uui::Direction::VERTICAL, [](uui::Stack& stack) {
|
window.create_stack({.x = 50, .y = 400, .direction = uui::Direction::VERTICAL}, [](uui::Stack& stack) {
|
||||||
stack.create_component(
|
stack.create_component({.width = 100, .height = 50}, [](uui::Component& component) {
|
||||||
100, 50, [](uui::Component& component) { component.set_background_color(0.2f, 0.75f, 0.25f); });
|
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(
|
stack.create_label({.text = "test", .text_color = {0.8f, 0.2f, 0.2f, 1.0f}}, {});
|
||||||
100, 20, [](uui::Component& component) { component.set_background_color(0.2f, 0.25f, 0.75f); });
|
stack.create_component({.width = 100, .height = 20}, [](uui::Component& component) {
|
||||||
|
component.set_background_color(0.2f, 0.25f, 0.75f);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -71,19 +80,19 @@ int main()
|
||||||
{
|
{
|
||||||
auto app = uui::create_application(uui::Application::OPENGL);
|
auto app = uui::create_application(uui::Application::OPENGL);
|
||||||
app->create_window(800, 600, "OpenGl!", [](uui::Window& window) {
|
app->create_window(800, 600, "OpenGl!", [](uui::Window& window) {
|
||||||
window.create_component(0.25f, 0.25f, 0.5f, 0.5f, [](uui::Component& component) {
|
window.create_component({0.25f, 0.25f, 0.5f, 0.5f}, [](uui::Component& component) {
|
||||||
component.set_background_color(0.8f, 0.1f, 0.5f);
|
component.set_background_color(0.8f, 0.1f, 0.5f);
|
||||||
});
|
});
|
||||||
window.create_component(0.75f, 0.75f, 0.25f, 0.25f, [](uui::Component& component) {
|
window.create_component({0.75f, 0.75f, 0.25f, 0.25f}, [](uui::Component& component) {
|
||||||
component.set_background_color(0.2f, 0.1f, 0.5f);
|
component.set_background_color(0.2f, 0.1f, 0.5f);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app->create_window(600, 600, "OpenGL 2!", [](uui::Window& window) {
|
app->create_window(600, 600, "OpenGL 2!", [](uui::Window& window) {
|
||||||
window.create_component(0, 0.5f, 100, 0.5f, [](uui::Component& component) {
|
window.create_component({0, 0.5f, 100, 0.5f}, [](uui::Component& component) {
|
||||||
component.set_background_color(0.2f, 0.5f, 0.3f);
|
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::Label& label) {
|
window.create_label({50, 50, "Hello World!", {0.5f, 1.0f, 0.5f, 1.0f}}, [](uui::Label& label) {
|
||||||
label.set_background_color(0.1f, 0.2f, 0.5f);
|
label.set_background_color(0.1f, 0.2f, 0.5f);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,23 +4,12 @@ int main()
|
||||||
{
|
{
|
||||||
auto app = uui::create_application(uui::Application::OPENGL);
|
auto app = uui::create_application(uui::Application::OPENGL);
|
||||||
app->create_window(800, 600, "UUI sample", [](uui::Window& window) {
|
app->create_window(800, 600, "UUI sample", [](uui::Window& window) {
|
||||||
window.create_component(
|
window.create_component({.x = 0, .y = 0, .width = 200, .height = 100}, [](uui::Component& component) {
|
||||||
0, 0, 200, 100, [](uui::Component& component) { component.set_background_color(1.0f, 0.f, 0.f, 0.5f); });
|
component.set_background_color(1.0f, 0.f, 0.f, 0.5f);
|
||||||
window.create_label(0.5f, 0.5f, "Hello world!", {0.8f, 0.8f, 0.8f, 1.0f}, nullptr);
|
});
|
||||||
|
window.create_label(
|
||||||
|
{.x = 0.5f, .y = 0.5f, .text = "Hello world!", .text_color = {0.8f, 0.8f, 0.8f, 1.0f}}, nullptr);
|
||||||
});
|
});
|
||||||
app->run();
|
app->run();
|
||||||
// app->run();
|
|
||||||
|
|
||||||
// app = uui::create_application(uui::Application::OPENGL);
|
|
||||||
// app->create_window(800, 600, "test", [](uui::Window& window) {
|
|
||||||
// window.create_flex(10, 10, uui::HORIZONTAL, [](uui::Flex& flex) {
|
|
||||||
// flex.create_label("Hello!", {0.5f, 0.f, 0.f, 1.0f}, [](uui::Label& label) {
|
|
||||||
// label.set_background_color(0.2f, 0.2f, 0.6f, 1.0f);
|
|
||||||
// });
|
|
||||||
// flex.create_label("World!", {1.0, 1.0, 1.0, 1.0}, {});
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// app->run();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
uui::GlComponent::GlComponent(
|
uui::GlComponent::GlComponent(
|
||||||
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
||||||
std::size_t parent_index, const position_t x, const position_t y, const position_t width, const position_t height)
|
std::size_t parent_index, const ComponentParams& params)
|
||||||
{
|
{
|
||||||
if constexpr(uui::Application::debug_mode)
|
if constexpr(uui::Application::debug_mode)
|
||||||
std::cout << "Creating a GlComponent " << parent_index << std::endl;
|
std::cout << "Creating a GlComponent " << parent_index << std::endl;
|
||||||
|
|
@ -23,10 +23,10 @@ uui::GlComponent::GlComponent(
|
||||||
|
|
||||||
initialized = false;
|
initialized = false;
|
||||||
|
|
||||||
position_x = x;
|
position_x = params.x;
|
||||||
position_y = y;
|
position_y = params.y;
|
||||||
size_width = width;
|
size_width = params.width;
|
||||||
size_height = height;
|
size_height = params.height;
|
||||||
|
|
||||||
coord_all_relative = true;
|
coord_all_relative = true;
|
||||||
auto parse_coords = [&](position_t& value) {
|
auto parse_coords = [&](position_t& value) {
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
uui::GlFlex::GlFlex(
|
uui::GlFlex::GlFlex(
|
||||||
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
||||||
std::size_t parent_index, const position_t x, const position_t y, const Direction direction):
|
std::size_t parent_index, const StackParams& params):
|
||||||
GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f),
|
GlComponent(window, window_index, parent, parent_index, {params.x, params.y, 0.0f, 0.0f}),
|
||||||
GlStack(window, window_index, parent, parent_index, x, y, direction)
|
GlStack(window, window_index, parent, parent_index, params)
|
||||||
{
|
{
|
||||||
if constexpr(uui::GlApplication::debug_mode)
|
if constexpr(uui::GlApplication::debug_mode)
|
||||||
std::cout << "Creating a GlFlex " << parent_index << std::endl;
|
std::cout << "Creating a GlFlex " << parent_index << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "uui/types.hpp"
|
|
||||||
#include "uui/opengl/application.hpp"
|
#include "uui/opengl/application.hpp"
|
||||||
#include "uui/opengl/gl_utils.hpp"
|
#include "uui/opengl/gl_utils.hpp"
|
||||||
#include "uui/shader.hpp"
|
#include "uui/shader.hpp"
|
||||||
|
#include "uui/types.hpp"
|
||||||
|
|
||||||
uui::GlFontManager::GlFontManager()
|
uui::GlFontManager::GlFontManager()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,9 @@
|
||||||
|
|
||||||
uui::GlLabel::GlLabel(
|
uui::GlLabel::GlLabel(
|
||||||
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
||||||
std::size_t parent_index, const position_t x, const position_t y, const std::string& text,
|
std::size_t parent_index, const LabelParams& params):
|
||||||
const std::tuple<float, float, float, float>& text_color):
|
GlComponent(window, window_index, parent, parent_index, {params.x, params.y, 0.0f, 0.0f}),
|
||||||
GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f),
|
text(params.text), text_color(params.text_color)
|
||||||
text(text), text_color(text_color)
|
|
||||||
{
|
{
|
||||||
if constexpr(uui::Application::debug_mode)
|
if constexpr(uui::Application::debug_mode)
|
||||||
std::cout << "Creating GlLabel " << parent_index << std::endl;
|
std::cout << "Creating GlLabel " << parent_index << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -7,20 +7,19 @@
|
||||||
|
|
||||||
uui::GlStack::GlStack(
|
uui::GlStack::GlStack(
|
||||||
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
std::shared_ptr<uui::GlWindow> window, std::size_t window_index, std::shared_ptr<uui::GlContainer> parent,
|
||||||
std::size_t parent_index, const position_t x, const position_t y, const Direction direction):
|
std::size_t parent_index, const StackParams& params):
|
||||||
GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f)
|
GlComponent(window, window_index, parent, parent_index, {params.x, params.y, 0.0f, 0.0f})
|
||||||
{
|
{
|
||||||
if constexpr(uui::GlApplication::debug_mode)
|
if constexpr(uui::GlApplication::debug_mode)
|
||||||
std::cout << "Creating GlStack " << parent_index << std::endl;
|
std::cout << "Creating GlStack " << parent_index << std::endl;
|
||||||
|
|
||||||
this->direction = direction;
|
direction = params.direction;
|
||||||
|
|
||||||
type = Type::STACK;
|
type = Type::STACK;
|
||||||
coord_all_relative = false;
|
coord_all_relative = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uui::GlStack::create_component(
|
void uui::GlStack::create_component(const StackComponentParams& params, uui::InitFunction<uui::Component> init)
|
||||||
const uui::position_t width, const uui::position_t height, uui::InitFunction<uui::Component> init)
|
|
||||||
{
|
{
|
||||||
if(!initialized)
|
if(!initialized)
|
||||||
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
||||||
|
|
@ -28,7 +27,7 @@ void uui::GlStack::create_component(
|
||||||
glfwMakeContextCurrent(gl_window->glfw_window);
|
glfwMakeContextCurrent(gl_window->glfw_window);
|
||||||
std::shared_ptr<uui::GlComponent> component(new uui::GlComponent(
|
std::shared_ptr<uui::GlComponent> component(new uui::GlComponent(
|
||||||
gl_window, gl_window->components.size(), std::dynamic_pointer_cast<uui::GlContainer>(shared_from_this()),
|
gl_window, gl_window->components.size(), std::dynamic_pointer_cast<uui::GlContainer>(shared_from_this()),
|
||||||
components.size(), 0, 0, width, height));
|
components.size(), {0, 0, params.width, params.height}));
|
||||||
push_child(component);
|
push_child(component);
|
||||||
component->init();
|
component->init();
|
||||||
std::tie(component->position_x, component->position_y) = get_child_position(components.size() - 1);
|
std::tie(component->position_x, component->position_y) = get_child_position(components.size() - 1);
|
||||||
|
|
@ -38,9 +37,7 @@ void uui::GlStack::create_component(
|
||||||
init(*component);
|
init(*component);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uui::GlStack::create_label(
|
void uui::GlStack::create_label(const StackLabelParams& params, uui::InitFunction<uui::Label> init)
|
||||||
const std::string& text, const std::tuple<float, float, float, float>& text_color,
|
|
||||||
uui::InitFunction<uui::Label> init)
|
|
||||||
{
|
{
|
||||||
if(!initialized)
|
if(!initialized)
|
||||||
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
||||||
|
|
@ -48,7 +45,7 @@ void uui::GlStack::create_label(
|
||||||
glfwMakeContextCurrent(gl_window->glfw_window);
|
glfwMakeContextCurrent(gl_window->glfw_window);
|
||||||
std::shared_ptr<uui::GlLabel> label(new uui::GlLabel(
|
std::shared_ptr<uui::GlLabel> label(new uui::GlLabel(
|
||||||
gl_window, gl_window->components.size(), std::dynamic_pointer_cast<uui::GlContainer>(shared_from_this()),
|
gl_window, gl_window->components.size(), std::dynamic_pointer_cast<uui::GlContainer>(shared_from_this()),
|
||||||
components.size(), 0, 0, text, text_color));
|
components.size(), {0, 0, params.text, params.text_color}));
|
||||||
push_child(std::static_pointer_cast<uui::GlComponent>(label));
|
push_child(std::static_pointer_cast<uui::GlComponent>(label));
|
||||||
label->init();
|
label->init();
|
||||||
std::tie(label->position_x, label->position_y) = get_child_position(components.size() - 1);
|
std::tie(label->position_x, label->position_y) = get_child_position(components.size() - 1);
|
||||||
|
|
|
||||||
|
|
@ -267,16 +267,13 @@ void uui::GlWindow::render()
|
||||||
_render_needed = false;
|
_render_needed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uui::GlWindow::create_component(
|
void uui::GlWindow::create_component(const uui::ComponentParams& params, uui::InitFunction<Component> init)
|
||||||
const uui::position_t x, const uui::position_t y, const uui::position_t width, const uui::position_t height,
|
|
||||||
uui::InitFunction<Component> init)
|
|
||||||
{
|
{
|
||||||
if(!_initialized)
|
if(!_initialized)
|
||||||
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
||||||
|
|
||||||
glfwMakeContextCurrent(glfw_window);
|
glfwMakeContextCurrent(glfw_window);
|
||||||
std::shared_ptr<uui::GlComponent> component(
|
std::shared_ptr<uui::GlComponent> component(new uui::GlComponent(shared_from_this(), components.size(), params));
|
||||||
new uui::GlComponent(shared_from_this(), components.size(), x, y, width, height));
|
|
||||||
push_child(component);
|
push_child(component);
|
||||||
component->init();
|
component->init();
|
||||||
|
|
||||||
|
|
@ -284,16 +281,13 @@ void uui::GlWindow::create_component(
|
||||||
init(*component);
|
init(*component);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uui::GlWindow::create_label(
|
void uui::GlWindow::create_label(const LabelParams& params, uui::InitFunction<Label> init)
|
||||||
const uui::position_t x, const uui::position_t y, const std::string& text,
|
|
||||||
const std::tuple<float, float, float, float>& text_color, uui::InitFunction<Label> init)
|
|
||||||
{
|
{
|
||||||
if(!_initialized)
|
if(!_initialized)
|
||||||
throw std::runtime_error("GlWindow error : cannot create label while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create label while not initialized");
|
||||||
|
|
||||||
glfwMakeContextCurrent(glfw_window);
|
glfwMakeContextCurrent(glfw_window);
|
||||||
std::shared_ptr<uui::GlLabel> label(
|
std::shared_ptr<uui::GlLabel> label(new uui::GlLabel(shared_from_this(), components.size(), params));
|
||||||
new uui::GlLabel(shared_from_this(), components.size(), x, y, text, text_color));
|
|
||||||
push_child(std::static_pointer_cast<uui::GlComponent>(label));
|
push_child(std::static_pointer_cast<uui::GlComponent>(label));
|
||||||
label->init();
|
label->init();
|
||||||
|
|
||||||
|
|
@ -301,14 +295,13 @@ void uui::GlWindow::create_label(
|
||||||
init(*label);
|
init(*label);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uui::GlWindow::create_flex(
|
void uui::GlWindow::create_flex(const StackParams& params, uui::InitFunction<Flex> init)
|
||||||
const uui::position_t x, const uui::position_t y, const uui::Direction direction, uui::InitFunction<Flex> init)
|
|
||||||
{
|
{
|
||||||
if(!_initialized)
|
if(!_initialized)
|
||||||
throw std::runtime_error("GlWindow error : cannot create flex while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create flex while not initialized");
|
||||||
|
|
||||||
glfwMakeContextCurrent(glfw_window);
|
glfwMakeContextCurrent(glfw_window);
|
||||||
std::shared_ptr<uui::GlFlex> flex(new uui::GlFlex(shared_from_this(), components.size(), x, y, direction));
|
std::shared_ptr<uui::GlFlex> flex(new uui::GlFlex(shared_from_this(), components.size(), params));
|
||||||
push_child(std::static_pointer_cast<uui::GlComponent>(flex));
|
push_child(std::static_pointer_cast<uui::GlComponent>(flex));
|
||||||
flex->init();
|
flex->init();
|
||||||
|
|
||||||
|
|
@ -316,14 +309,13 @@ void uui::GlWindow::create_flex(
|
||||||
init(*flex);
|
init(*flex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uui::GlWindow::create_stack(
|
void uui::GlWindow::create_stack(const StackParams& params, uui::InitFunction<Stack> init)
|
||||||
const uui::position_t x, const uui::position_t y, const uui::Direction direction, uui::InitFunction<Stack> init)
|
|
||||||
{
|
{
|
||||||
if(!_initialized)
|
if(!_initialized)
|
||||||
throw std::runtime_error("GlWindow error : cannot create stack while not initialized");
|
throw std::runtime_error("GlWindow error : cannot create stack while not initialized");
|
||||||
|
|
||||||
glfwMakeContextCurrent(glfw_window);
|
glfwMakeContextCurrent(glfw_window);
|
||||||
std::shared_ptr<uui::GlStack> stack(new uui::GlStack(shared_from_this(), components.size(), x, y, direction));
|
std::shared_ptr<uui::GlStack> stack(new uui::GlStack(shared_from_this(), components.size(), params));
|
||||||
push_child(std::static_pointer_cast<uui::GlComponent>(stack));
|
push_child(std::static_pointer_cast<uui::GlComponent>(stack));
|
||||||
stack->init();
|
stack->init();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue