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; };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue