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_y;
|
||||
uui::position_t size_width;
|
||||
uui::position_t size_height;
|
||||
uui::size_t size_width;
|
||||
uui::size_t size_height;
|
||||
|
||||
bool coord_all_relative;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,13 +34,9 @@ protected:
|
|||
|
||||
GlComponent(
|
||||
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,
|
||||
const position_t height);
|
||||
GlComponent(
|
||||
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)
|
||||
std::size_t parent_index, const ComponentParams& params);
|
||||
GlComponent(std::shared_ptr<GlWindow> window, std::size_t window_index, const ComponentParams& params):
|
||||
GlComponent(window, window_index, std::static_pointer_cast<GlContainer>(window), window_index, params)
|
||||
{}
|
||||
GlComponent(const GlComponent&) = delete;
|
||||
GlComponent(GlComponent&&) = default;
|
||||
|
|
|
|||
|
|
@ -18,11 +18,9 @@ class GlFlex: virtual public GlStack, virtual public Flex
|
|||
protected:
|
||||
GlFlex(
|
||||
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);
|
||||
GlFlex(
|
||||
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
||||
const Direction direction):
|
||||
GlFlex(window, window_index, window, window_index, x, y, direction)
|
||||
std::size_t parent_index, const StackParams& params);
|
||||
GlFlex(std::shared_ptr<GlWindow> window, std::size_t window_index, const StackParams& params):
|
||||
GlFlex(window, window_index, window, window_index, params)
|
||||
{}
|
||||
|
||||
std::tuple<int, int> get_child_position(const std::size_t child_index) const override;
|
||||
|
|
|
|||
|
|
@ -26,12 +26,9 @@ protected:
|
|||
|
||||
GlLabel(
|
||||
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,
|
||||
const std::tuple<float, float, float, float>& text_color);
|
||||
GlLabel(
|
||||
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)
|
||||
std::size_t parent_index, const LabelParams& params);
|
||||
GlLabel(std::shared_ptr<GlWindow> window, std::size_t window_index, const LabelParams& params):
|
||||
GlLabel(window, window_index, window, window_index, params)
|
||||
{}
|
||||
|
||||
void render() final;
|
||||
|
|
|
|||
|
|
@ -15,19 +15,15 @@ class GlStack: virtual public GlComponent, virtual public GlContainer, virtual p
|
|||
friend class GlWindow;
|
||||
|
||||
public:
|
||||
void create_component(const position_t width, const position_t height, InitFunction<Component> init) override;
|
||||
void create_label(
|
||||
const std::string& text, const std::tuple<float, float, float, float>& text_color,
|
||||
InitFunction<Label> init) override;
|
||||
void create_component(const StackComponentParams& params, InitFunction<Component> init) override;
|
||||
void create_label(const StackLabelParams& params, InitFunction<Label> init) override;
|
||||
|
||||
protected:
|
||||
GlStack(
|
||||
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);
|
||||
GlStack(
|
||||
std::shared_ptr<GlWindow> window, std::size_t window_index, const position_t x, const position_t y,
|
||||
const Direction direction):
|
||||
GlStack(window, window_index, window, window_index, x, y, direction)
|
||||
std::size_t parent_index, const StackParams& params);
|
||||
GlStack(std::shared_ptr<GlWindow> window, std::size_t window_index, const StackParams& params):
|
||||
GlStack(window, window_index, window, window_index, params)
|
||||
{}
|
||||
|
||||
std::tuple<int, int> get_child_position(const std::size_t child_index) const override;
|
||||
|
|
|
|||
|
|
@ -26,15 +26,10 @@ public:
|
|||
GlWindow(GlWindow&&) = delete;
|
||||
~GlWindow();
|
||||
|
||||
void create_component(
|
||||
const position_t x, const position_t y, const position_t width, const position_t height,
|
||||
InitFunction<Component> init) final;
|
||||
void create_label(
|
||||
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;
|
||||
void create_component(const ComponentParams& params, InitFunction<Component> init) final;
|
||||
void create_label(const LabelParams& params, InitFunction<Label> init) final;
|
||||
void create_flex(const StackParams& params, InitFunction<Flex> init) final;
|
||||
void create_stack(const StackParams& params, InitFunction<Stack> init) final;
|
||||
|
||||
protected:
|
||||
void render() final;
|
||||
|
|
|
|||
|
|
@ -11,10 +11,8 @@ namespace uui
|
|||
class Stack: virtual public Component
|
||||
{
|
||||
public:
|
||||
virtual void create_component(const position_t width, const position_t height, InitFunction<Component> init) = 0;
|
||||
virtual void create_label(
|
||||
const std::string& text, const std::tuple<float, float, float, float>& text_color,
|
||||
InitFunction<Label> init) = 0;
|
||||
virtual void create_component(const StackComponentParams& params, InitFunction<Component> init) = 0;
|
||||
virtual void create_label(const StackLabelParams& params, InitFunction<Label> init) = 0;
|
||||
|
||||
protected:
|
||||
Direction direction;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
#include <variant>
|
||||
|
||||
namespace uui
|
||||
|
|
@ -8,9 +9,43 @@ namespace uui
|
|||
template<typename T> using InitFunction = const std::function<void(T&)>&;
|
||||
typedef std::variant<int, float> position_t;
|
||||
typedef std::variant<int, float> size_t;
|
||||
typedef std::tuple<float, float, float, float> color_t;
|
||||
|
||||
enum Direction
|
||||
{
|
||||
HORIZONTAL,
|
||||
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
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "uui/application.hpp"
|
||||
#include "uui/container.hpp"
|
||||
|
|
@ -24,16 +23,10 @@ public:
|
|||
|
||||
std::shared_ptr<FontManager> font_manager;
|
||||
|
||||
virtual void create_component(
|
||||
const position_t x, const position_t y, const position_t width, const position_t height,
|
||||
InitFunction<Component> init) = 0;
|
||||
virtual void create_label(
|
||||
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;
|
||||
virtual void create_component(const ComponentParams& params, InitFunction<Component> init) = 0;
|
||||
virtual void create_label(const LabelParams& params, InitFunction<Label> init) = 0;
|
||||
virtual void create_flex(const StackParams& params, InitFunction<Flex> init) = 0;
|
||||
virtual void create_stack(const StackParams& params, InitFunction<Stack> init) = 0;
|
||||
|
||||
int width() { return _width; };
|
||||
int height() { return _height; };
|
||||
|
|
|
|||
2
make.py
2
make.py
|
|
@ -18,7 +18,7 @@ class Config:
|
|||
OBJECT_DIR = Path('obj')
|
||||
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_RELEASE_FLAGS = '-O2 -flto=auto'
|
||||
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
|
||||
{
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,55 +13,64 @@ int main()
|
|||
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) {
|
||||
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);
|
||||
});
|
||||
|
||||
window.create_component(0.25f, 50, 0.4f, 150, [](uui::Component& component) {
|
||||
component.set_background_color(0.3f, 0.8f, 0.4f, 0.5f);
|
||||
});
|
||||
window.create_component(
|
||||
{.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) {
|
||||
label.set_background_color(0.1f, 0.2f, 0.5f, 0.8f);
|
||||
});
|
||||
window.create_label(
|
||||
{.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);
|
||||
});
|
||||
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) {
|
||||
flex.create_component(
|
||||
100, 50, [](uui::Component& 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::Component& component) { component.set_background_color(0.2f, 0.25f, 0.75f); });
|
||||
window.create_flex({200, 0.6f, uui::Direction::HORIZONTAL}, [](uui::Flex& flex) {
|
||||
flex.create_component({.width = 100, .height = 50}, [](uui::Component& component) {
|
||||
component.set_background_color(0.2f, 0.75f, 0.25f);
|
||||
});
|
||||
flex.create_label({.text = "test", .text_color = {0.8f, 0.2f, 0.2f, 1.0f}}, {});
|
||||
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) {
|
||||
flex.create_component(
|
||||
50, 100, [](uui::Component& 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::Component& component) { component.set_background_color(0.2f, 0.25f, 0.75f); });
|
||||
window.create_flex({50, 400, uui::Direction::VERTICAL}, [](uui::Flex& flex) {
|
||||
flex.create_component({50, 100}, [](uui::Component& 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::Component& component) {
|
||||
component.set_background_color(0.2f, 0.25f, 0.75f);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app->create_window(800, 600, "OpenGl 2", [](uui::Window& window) {
|
||||
window.create_stack(200, 0.6f, uui::Direction::HORIZONTAL, [](uui::Stack& stack) {
|
||||
stack.create_component(
|
||||
100, 50, [](uui::Component& 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::Component& component) { component.set_background_color(0.2f, 0.25f, 0.75f); });
|
||||
window.create_stack(
|
||||
{.x = 200, .y = 0.6f, .direction = uui::Direction::HORIZONTAL}, [](uui::Stack& stack) {
|
||||
stack.create_component({.width = 100, .height = 50}, [](uui::Component& component) {
|
||||
component.set_background_color(0.2f, 0.75f, 0.25f);
|
||||
});
|
||||
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) {
|
||||
stack.create_component(
|
||||
100, 50, [](uui::Component& 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::Component& component) { component.set_background_color(0.2f, 0.25f, 0.75f); });
|
||||
window.create_stack({.x = 50, .y = 400, .direction = uui::Direction::VERTICAL}, [](uui::Stack& stack) {
|
||||
stack.create_component({.width = 100, .height = 50}, [](uui::Component& component) {
|
||||
component.set_background_color(0.2f, 0.75f, 0.25f);
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -71,19 +80,19 @@ int main()
|
|||
{
|
||||
auto app = uui::create_application(uui::Application::OPENGL);
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,23 +4,12 @@ int main()
|
|||
{
|
||||
auto app = uui::create_application(uui::Application::OPENGL);
|
||||
app->create_window(800, 600, "UUI sample", [](uui::Window& window) {
|
||||
window.create_component(
|
||||
0, 0, 200, 100, [](uui::Component& component) { 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_component({.x = 0, .y = 0, .width = 200, .height = 100}, [](uui::Component& component) {
|
||||
component.set_background_color(1.0f, 0.f, 0.f, 0.5f);
|
||||
});
|
||||
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 = 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
uui::GlComponent::GlComponent(
|
||||
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)
|
||||
std::cout << "Creating a GlComponent " << parent_index << std::endl;
|
||||
|
|
@ -23,10 +23,10 @@ uui::GlComponent::GlComponent(
|
|||
|
||||
initialized = false;
|
||||
|
||||
position_x = x;
|
||||
position_y = y;
|
||||
size_width = width;
|
||||
size_height = height;
|
||||
position_x = params.x;
|
||||
position_y = params.y;
|
||||
size_width = params.width;
|
||||
size_height = params.height;
|
||||
|
||||
coord_all_relative = true;
|
||||
auto parse_coords = [&](position_t& value) {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
uui::GlFlex::GlFlex(
|
||||
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):
|
||||
GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f),
|
||||
GlStack(window, window_index, parent, parent_index, x, y, direction)
|
||||
std::size_t parent_index, const StackParams& params):
|
||||
GlComponent(window, window_index, parent, parent_index, {params.x, params.y, 0.0f, 0.0f}),
|
||||
GlStack(window, window_index, parent, parent_index, params)
|
||||
{
|
||||
if constexpr(uui::GlApplication::debug_mode)
|
||||
std::cout << "Creating a GlFlex " << parent_index << std::endl;
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@
|
|||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include "uui/types.hpp"
|
||||
#include "uui/opengl/application.hpp"
|
||||
#include "uui/opengl/gl_utils.hpp"
|
||||
#include "uui/shader.hpp"
|
||||
#include "uui/types.hpp"
|
||||
|
||||
uui::GlFontManager::GlFontManager()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,10 +7,9 @@
|
|||
|
||||
uui::GlLabel::GlLabel(
|
||||
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,
|
||||
const std::tuple<float, float, float, float>& text_color):
|
||||
GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f),
|
||||
text(text), text_color(text_color)
|
||||
std::size_t parent_index, const LabelParams& params):
|
||||
GlComponent(window, window_index, parent, parent_index, {params.x, params.y, 0.0f, 0.0f}),
|
||||
text(params.text), text_color(params.text_color)
|
||||
{
|
||||
if constexpr(uui::Application::debug_mode)
|
||||
std::cout << "Creating GlLabel " << parent_index << std::endl;
|
||||
|
|
|
|||
|
|
@ -7,20 +7,19 @@
|
|||
|
||||
uui::GlStack::GlStack(
|
||||
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):
|
||||
GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f)
|
||||
std::size_t parent_index, const StackParams& params):
|
||||
GlComponent(window, window_index, parent, parent_index, {params.x, params.y, 0.0f, 0.0f})
|
||||
{
|
||||
if constexpr(uui::GlApplication::debug_mode)
|
||||
std::cout << "Creating GlStack " << parent_index << std::endl;
|
||||
|
||||
this->direction = direction;
|
||||
direction = params.direction;
|
||||
|
||||
type = Type::STACK;
|
||||
coord_all_relative = false;
|
||||
}
|
||||
|
||||
void uui::GlStack::create_component(
|
||||
const uui::position_t width, const uui::position_t height, uui::InitFunction<uui::Component> init)
|
||||
void uui::GlStack::create_component(const StackComponentParams& params, uui::InitFunction<uui::Component> init)
|
||||
{
|
||||
if(!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);
|
||||
std::shared_ptr<uui::GlComponent> component(new uui::GlComponent(
|
||||
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);
|
||||
component->init();
|
||||
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);
|
||||
}
|
||||
|
||||
void uui::GlStack::create_label(
|
||||
const std::string& text, const std::tuple<float, float, float, float>& text_color,
|
||||
uui::InitFunction<uui::Label> init)
|
||||
void uui::GlStack::create_label(const StackLabelParams& params, uui::InitFunction<uui::Label> init)
|
||||
{
|
||||
if(!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);
|
||||
std::shared_ptr<uui::GlLabel> label(new uui::GlLabel(
|
||||
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));
|
||||
label->init();
|
||||
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;
|
||||
}
|
||||
|
||||
void uui::GlWindow::create_component(
|
||||
const uui::position_t x, const uui::position_t y, const uui::position_t width, const uui::position_t height,
|
||||
uui::InitFunction<Component> init)
|
||||
void uui::GlWindow::create_component(const uui::ComponentParams& params, uui::InitFunction<Component> init)
|
||||
{
|
||||
if(!_initialized)
|
||||
throw std::runtime_error("GlWindow error : cannot create component while not initialized");
|
||||
|
||||
glfwMakeContextCurrent(glfw_window);
|
||||
std::shared_ptr<uui::GlComponent> component(
|
||||
new uui::GlComponent(shared_from_this(), components.size(), x, y, width, height));
|
||||
std::shared_ptr<uui::GlComponent> component(new uui::GlComponent(shared_from_this(), components.size(), params));
|
||||
push_child(component);
|
||||
component->init();
|
||||
|
||||
|
|
@ -284,16 +281,13 @@ void uui::GlWindow::create_component(
|
|||
init(*component);
|
||||
}
|
||||
|
||||
void uui::GlWindow::create_label(
|
||||
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)
|
||||
void uui::GlWindow::create_label(const LabelParams& params, uui::InitFunction<Label> init)
|
||||
{
|
||||
if(!_initialized)
|
||||
throw std::runtime_error("GlWindow error : cannot create label while not initialized");
|
||||
|
||||
glfwMakeContextCurrent(glfw_window);
|
||||
std::shared_ptr<uui::GlLabel> label(
|
||||
new uui::GlLabel(shared_from_this(), components.size(), x, y, text, text_color));
|
||||
std::shared_ptr<uui::GlLabel> label(new uui::GlLabel(shared_from_this(), components.size(), params));
|
||||
push_child(std::static_pointer_cast<uui::GlComponent>(label));
|
||||
label->init();
|
||||
|
||||
|
|
@ -301,14 +295,13 @@ void uui::GlWindow::create_label(
|
|||
init(*label);
|
||||
}
|
||||
|
||||
void uui::GlWindow::create_flex(
|
||||
const uui::position_t x, const uui::position_t y, const uui::Direction direction, uui::InitFunction<Flex> init)
|
||||
void uui::GlWindow::create_flex(const StackParams& params, uui::InitFunction<Flex> init)
|
||||
{
|
||||
if(!_initialized)
|
||||
throw std::runtime_error("GlWindow error : cannot create flex while not initialized");
|
||||
|
||||
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));
|
||||
flex->init();
|
||||
|
||||
|
|
@ -316,14 +309,13 @@ void uui::GlWindow::create_flex(
|
|||
init(*flex);
|
||||
}
|
||||
|
||||
void uui::GlWindow::create_stack(
|
||||
const uui::position_t x, const uui::position_t y, const uui::Direction direction, uui::InitFunction<Stack> init)
|
||||
void uui::GlWindow::create_stack(const StackParams& params, uui::InitFunction<Stack> init)
|
||||
{
|
||||
if(!_initialized)
|
||||
throw std::runtime_error("GlWindow error : cannot create stack while not initialized");
|
||||
|
||||
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));
|
||||
stack->init();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue