Improve class structure
This commit is contained in:
parent
6427c7aeb7
commit
3ad40381e5
25 changed files with 271 additions and 216 deletions
|
|
@ -14,22 +14,30 @@ class Component
|
|||
public:
|
||||
virtual void set_background_color(float r, float g, float b, float a = 1.0f) = 0;
|
||||
|
||||
ComponentType type() { return _type; }
|
||||
uui::position_t x() { return _position_x; }
|
||||
uui::position_t y() { return _position_y; }
|
||||
uui::size_t width() { return _width; }
|
||||
uui::size_t height() { return _height; }
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Window> window;
|
||||
std::size_t window_index;
|
||||
std::shared_ptr<Container> parent;
|
||||
std::size_t parent_index;
|
||||
ComponentType _type = ComponentType::UNASSIGNED;
|
||||
|
||||
uui::position_t position_x;
|
||||
uui::position_t position_y;
|
||||
uui::size_t size_width;
|
||||
uui::size_t size_height;
|
||||
std::shared_ptr<Window> _window;
|
||||
std::size_t _window_index;
|
||||
std::shared_ptr<Container> _parent;
|
||||
std::size_t _parent_index;
|
||||
|
||||
bool coord_all_relative;
|
||||
uui::position_t _position_x;
|
||||
uui::position_t _position_y;
|
||||
uui::size_t _width;
|
||||
uui::size_t _height;
|
||||
|
||||
std::array<float, 4> background_color;
|
||||
bool _coord_all_relative;
|
||||
|
||||
bool initialized;
|
||||
std::array<float, 4> _background_color;
|
||||
|
||||
bool _initialized = false;
|
||||
|
||||
virtual void render() = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,36 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "uui/component.hpp"
|
||||
#include "uui/container_interface.hpp"
|
||||
#include "uui/types.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class Component;
|
||||
class GlComponent;
|
||||
class Container
|
||||
{
|
||||
friend class GlComponent;
|
||||
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
WINDOW,
|
||||
FLEX,
|
||||
STACK
|
||||
};
|
||||
|
||||
Type type;
|
||||
|
||||
protected:
|
||||
virtual std::size_t push_child(std::shared_ptr<Component> child) = 0;
|
||||
virtual std::shared_ptr<Component> get_child(std::size_t index) const = 0;
|
||||
virtual void remove_child(std::size_t index) = 0;
|
||||
virtual std::tuple<int, int> get_child_position(const std::size_t child_index [[maybe_unused]]) const = 0;
|
||||
};
|
||||
class Container: virtual public Component, virtual public ContainerInterface
|
||||
{};
|
||||
|
||||
} // namespace uui
|
||||
|
|
|
|||
21
include/uui/container_interface.hpp
Normal file
21
include/uui/container_interface.hpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
#include "uui/types.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class Component;
|
||||
class ContainerInterface
|
||||
{
|
||||
public:
|
||||
virtual std::tuple<int, int> get_child_position(const std::size_t child_index [[maybe_unused]]) const = 0;
|
||||
protected:
|
||||
virtual std::size_t push_child(std::shared_ptr<Component> child) = 0;
|
||||
virtual std::shared_ptr<Component> get_child(std::size_t index) const = 0;
|
||||
virtual void remove_child(std::size_t index) = 0;
|
||||
};
|
||||
|
||||
} // namespace uui
|
||||
|
|
@ -51,6 +51,6 @@ protected:
|
|||
bool initialized;
|
||||
|
||||
FT_Library ft;
|
||||
virtual const Font& init_font(const std::string& font_path, std::size_t font_size) = 0;
|
||||
virtual const Font& init_font(const std::string& font_path, unsigned int font_size) = 0;
|
||||
};
|
||||
} // namespace uui
|
||||
|
|
|
|||
|
|
@ -20,3 +20,4 @@ protected:
|
|||
};
|
||||
|
||||
} // namespace uui
|
||||
|
||||
|
|
|
|||
|
|
@ -3,19 +3,18 @@
|
|||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
#include "graphic_context.hpp"
|
||||
#include "uui/container.hpp"
|
||||
#include "uui/opengl/component.hpp"
|
||||
#include "uui/component.hpp"
|
||||
#include "uui/opengl/graphic_context.hpp"
|
||||
#include "uui/opengl/window.hpp"
|
||||
#include "uui/types.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class GlContainer;
|
||||
class GlFlex;
|
||||
class GlStack;
|
||||
class GlComponent: public std::enable_shared_from_this<GlComponent>, virtual public Component
|
||||
{
|
||||
friend class Container;
|
||||
friend class GlContainer;
|
||||
friend class GlWindow;
|
||||
friend class GlFlex;
|
||||
|
|
@ -36,7 +35,7 @@ protected:
|
|||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||
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(window, window_index, nullptr, 0, params)
|
||||
{}
|
||||
GlComponent(const GlComponent&) = delete;
|
||||
GlComponent(GlComponent&&) = default;
|
||||
|
|
|
|||
|
|
@ -6,28 +6,13 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "uui/component.hpp"
|
||||
#include "uui/container.hpp"
|
||||
#include "uui/opengl/component.hpp"
|
||||
#include "uui/opengl/container_interface.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class GlContainer: virtual public Container
|
||||
{
|
||||
protected:
|
||||
GlContainer() = default;
|
||||
GlContainer(const GlContainer&) = default;
|
||||
GlContainer(GlContainer&&) = default;
|
||||
|
||||
virtual std::size_t push_child(std::shared_ptr<Component> child [[maybe_unused]]) final;
|
||||
std::size_t push_child(std::shared_ptr<GlComponent> child);
|
||||
std::shared_ptr<Component> get_child(std::size_t index) const final;
|
||||
virtual void remove_child(std::size_t index) final;
|
||||
virtual std::tuple<int, int> get_child_position(const std::size_t child_index [[maybe_unused]]) const override;
|
||||
|
||||
std::vector<std::shared_ptr<GlComponent>> components;
|
||||
|
||||
public:
|
||||
~GlContainer();
|
||||
};
|
||||
class GlContainer: virtual public Container, virtual public GlContainerInterface
|
||||
{};
|
||||
|
||||
} // namespace uui
|
||||
|
|
|
|||
28
include/uui/opengl/container_interface.hpp
Normal file
28
include/uui/opengl/container_interface.hpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
#include "uui/component.hpp"
|
||||
#include "uui/container_interface.hpp"
|
||||
#include "uui/types.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class GlComponent;
|
||||
class GlContainerInterface: virtual public ContainerInterface
|
||||
{
|
||||
public:
|
||||
virtual std::tuple<int, int> get_child_position(const std::size_t child_index [[maybe_unused]]) const override;
|
||||
|
||||
protected:
|
||||
virtual std::size_t push_child(std::shared_ptr<Component> child) final;
|
||||
std::size_t push_child(std::shared_ptr<GlComponent> child);
|
||||
virtual std::shared_ptr<Component> get_child(std::size_t index) const final;
|
||||
virtual void remove_child(std::size_t index) final;
|
||||
|
||||
virtual ~GlContainerInterface();
|
||||
|
||||
std::vector<std::shared_ptr<GlComponent>> components;
|
||||
};
|
||||
} // namespace uui
|
||||
|
|
@ -20,7 +20,7 @@ protected:
|
|||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||
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)
|
||||
GlFlex(window, window_index, nullptr, 0, params)
|
||||
{}
|
||||
|
||||
std::tuple<int, int> get_child_position(const std::size_t child_index) const override;
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@
|
|||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
#include "uui/font_manager.hpp"
|
||||
#include "uui/opengl/graphic_context.hpp"
|
||||
|
||||
|
|
@ -34,6 +31,6 @@ private:
|
|||
|
||||
void init();
|
||||
void deinit();
|
||||
const Font& init_font(const std::string& font_path, std::size_t font_size);
|
||||
const Font& init_font(const std::string& font_path, unsigned int font_size);
|
||||
};
|
||||
} // namespace uui
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#include <glm/gtc/type_ptr.hpp>
|
||||
// clang-format off
|
||||
|
||||
namespace Config
|
||||
namespace GlConfig
|
||||
{
|
||||
constexpr unsigned int FONT_TEXTURE_UNIT = GL_TEXTURE0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "uui/label.hpp"
|
||||
#include "uui/opengl/component.hpp"
|
||||
#include "uui/opengl/container.hpp"
|
||||
#include "uui/opengl/window.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
|
|
@ -28,7 +29,7 @@ protected:
|
|||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||
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)
|
||||
GlLabel(window, window_index, nullptr, 0, params)
|
||||
{}
|
||||
|
||||
void render() final;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ protected:
|
|||
std::shared_ptr<GlWindow> window, std::size_t window_index, std::shared_ptr<GlContainer> parent,
|
||||
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)
|
||||
GlStack(window, window_index, nullptr, 0, params)
|
||||
{}
|
||||
|
||||
std::tuple<int, int> get_child_position(const std::size_t child_index) const override;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "uui/opengl/application.hpp"
|
||||
#include "uui/opengl/container.hpp"
|
||||
#include "uui/opengl/container_interface.hpp"
|
||||
#include "uui/opengl/font_manager.hpp"
|
||||
#include "uui/types.hpp"
|
||||
#include "uui/window.hpp"
|
||||
|
|
@ -13,7 +13,10 @@ class GlContainer;
|
|||
class GlFlex;
|
||||
class GlLabel;
|
||||
class GlStack;
|
||||
class GlWindow final: public std::enable_shared_from_this<GlWindow>, virtual public Window, virtual public GlContainer
|
||||
class GlWindow:
|
||||
public std::enable_shared_from_this<GlWindow>,
|
||||
virtual public Window,
|
||||
virtual public GlContainerInterface
|
||||
{
|
||||
friend class GlApplication;
|
||||
friend class GlComponent;
|
||||
|
|
@ -48,5 +51,6 @@ protected:
|
|||
static void glfw_resize_callback(GLFWwindow* window, int width, int height);
|
||||
static void glfw_iconify_callback(GLFWwindow* window, int iconified);
|
||||
static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
// static void glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
|
||||
};
|
||||
} // namespace uui
|
||||
|
|
|
|||
|
|
@ -6,12 +6,28 @@
|
|||
|
||||
namespace uui
|
||||
{
|
||||
namespace Config
|
||||
{
|
||||
constexpr int MOUSE_GRID_WIDTH = 20;
|
||||
constexpr int MOUSE_GRID_HEIGHT = 20;
|
||||
}; // namespace Config
|
||||
|
||||
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
|
||||
enum class ComponentType
|
||||
{
|
||||
UNASSIGNED,
|
||||
COMPONENT,
|
||||
LABEL,
|
||||
FLEX,
|
||||
STACK,
|
||||
WINDOW
|
||||
};
|
||||
|
||||
enum class Direction
|
||||
{
|
||||
HORIZONTAL,
|
||||
VERTICAL
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "uui/application.hpp"
|
||||
#include "uui/container.hpp"
|
||||
#include "uui/container_interface.hpp"
|
||||
#include "uui/font_manager.hpp"
|
||||
#include "uui/types.hpp"
|
||||
|
||||
|
|
@ -14,13 +15,11 @@ class Component;
|
|||
class Label;
|
||||
class Flex;
|
||||
class Stack;
|
||||
class Window: virtual public Container
|
||||
class Window: virtual public ContainerInterface
|
||||
{
|
||||
friend class Component;
|
||||
|
||||
public:
|
||||
std::string title;
|
||||
|
||||
std::shared_ptr<FontManager> font_manager;
|
||||
|
||||
virtual void create_component(const ComponentParams& params, InitFunction<Component> init) = 0;
|
||||
|
|
@ -28,19 +27,26 @@ public:
|
|||
virtual void create_flex(const StackParams& params, InitFunction<Flex> init) = 0;
|
||||
virtual void create_stack(const StackParams& params, InitFunction<Stack> init) = 0;
|
||||
|
||||
const std::string& title() { return _title; }
|
||||
int width() { return _width; };
|
||||
int height() { return _height; };
|
||||
|
||||
protected:
|
||||
ComponentType _type = ComponentType::UNASSIGNED;
|
||||
|
||||
std::shared_ptr<Application> _app;
|
||||
bool _initialized;
|
||||
|
||||
std::string _title;
|
||||
int _width;
|
||||
int _height;
|
||||
bool _render_needed;
|
||||
bool _resize_needed;
|
||||
bool _iconified;
|
||||
|
||||
std::array<std::array<std::vector<std::shared_ptr<Component>>, Config::MOUSE_GRID_HEIGHT>, Config::MOUSE_GRID_WIDTH>
|
||||
_grid_click;
|
||||
|
||||
virtual void render() = 0;
|
||||
};
|
||||
} // namespace uui
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue