Stack component implemented (more flex than stack)
This commit is contained in:
parent
b530f65f38
commit
2ba59d8e37
17 changed files with 426 additions and 100 deletions
|
|
@ -3,16 +3,15 @@
|
|||
#include <array>
|
||||
#include <variant>
|
||||
|
||||
#include "uui/config.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class Component
|
||||
{
|
||||
public:
|
||||
Component(
|
||||
const std::variant<int, float> x, const std::variant<int, float> y, const std::variant<int, float> width,
|
||||
const std::variant<int, float> height):
|
||||
position_x(x),
|
||||
position_y(y), size_width(width), size_height(height)
|
||||
Component(const position_t x, const position_t y, const position_t width, const position_t height):
|
||||
position_x(x), position_y(y), size_width(width), size_height(height)
|
||||
{
|
||||
background_color = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
}
|
||||
|
|
@ -20,10 +19,10 @@ public:
|
|||
virtual void render() = 0;
|
||||
|
||||
protected:
|
||||
std::variant<int, float> position_x;
|
||||
std::variant<int, float> position_y;
|
||||
std::variant<int, float> size_width;
|
||||
std::variant<int, float> size_height;
|
||||
position_t position_x;
|
||||
position_t position_y;
|
||||
position_t size_width;
|
||||
position_t size_height;
|
||||
|
||||
std::array<float, 4> background_color;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include "graphic_context.hpp"
|
||||
|
||||
namespace Config
|
||||
{
|
||||
constexpr unsigned int FONT_TEXTURE_UNIT = GL_TEXTURE0;
|
||||
}
|
||||
|
||||
namespace uui
|
||||
{
|
||||
typedef std::variant<int, float> position_t;
|
||||
enum Direction
|
||||
{
|
||||
HORIZONTAL,
|
||||
VERTICAL
|
||||
};
|
||||
} // namespace uui
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#include <vector>
|
||||
|
||||
#include "graphic_context.hpp"
|
||||
#include "uui/config.hpp"
|
||||
#include "uui/opengl/container.hpp"
|
||||
#include "uui/opengl/font_manager.hpp"
|
||||
|
||||
namespace uui
|
||||
|
|
@ -34,49 +36,45 @@ private:
|
|||
static GlApplication* application_pointer;
|
||||
};
|
||||
|
||||
class GlLabel;
|
||||
class GlComponent;
|
||||
class GlWindow
|
||||
class GlStack;
|
||||
class GlLabel;
|
||||
class GlWindow: public GlContainer, public std::enable_shared_from_this<GlWindow>
|
||||
{
|
||||
friend class GlApplication;
|
||||
friend class GlComponent;
|
||||
friend class GlStack;
|
||||
friend class GlLabel;
|
||||
|
||||
public:
|
||||
std::string title;
|
||||
std::vector<std::shared_ptr<GlComponent>> components;
|
||||
|
||||
GlWindow(const GlWindow&) = delete;
|
||||
GlWindow(GlWindow&&) = delete;
|
||||
~GlWindow();
|
||||
|
||||
std::shared_ptr<GlComponent> create_component(
|
||||
const std::variant<int, float> x, const std::variant<int, float> y, const std::variant<int, float> width,
|
||||
const std::variant<int, float> height);
|
||||
std::shared_ptr<GlComponent> create_component(const position_t x, const position_t y, const position_t width, const position_t height);
|
||||
std::shared_ptr<GlLabel> create_label(
|
||||
const std::variant<int, float> x, const std::variant<int, float> y, const std::string& text,
|
||||
const std::tuple<float, float, float, float>& text_color);
|
||||
const position_t x, const position_t y, const std::string& text, const std::tuple<float, float, float, float>& text_color);
|
||||
std::shared_ptr<GlStack> create_stack(const position_t x, const position_t y, const Direction direction);
|
||||
|
||||
protected:
|
||||
GlApplication* app;
|
||||
|
||||
GlFontManager font_manager;
|
||||
bool initialized;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
bool render_needed;
|
||||
bool resize_needed;
|
||||
|
||||
bool iconified;
|
||||
|
||||
size_t index;
|
||||
bool initialized;
|
||||
GlFontManager font_manager;
|
||||
|
||||
GLFWwindow* glfw_window;
|
||||
|
||||
GLuint gl_program;
|
||||
|
||||
GlWindow(GlApplication* app, size_t index, int width, int height, const std::string& title);
|
||||
GlWindow(GlApplication* app, int width, int height, const std::string& title);
|
||||
std::shared_ptr<GlWindow> getptr() { return shared_from_this(); }
|
||||
|
||||
void init();
|
||||
void deinit();
|
||||
|
|
|
|||
|
|
@ -2,31 +2,35 @@
|
|||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
|
||||
#include "graphic_context.hpp"
|
||||
#include "uui/config.hpp"
|
||||
#include "uui/opengl/container.hpp"
|
||||
#include "window.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class GlComponent
|
||||
class GlStack;
|
||||
class GlComponent: public std::enable_shared_from_this<GlComponent>
|
||||
{
|
||||
friend class GlWindow;
|
||||
friend class GlStack;
|
||||
|
||||
public:
|
||||
GlComponent(const GlComponent&) = delete;
|
||||
GlComponent(GlComponent&&) = delete;
|
||||
~GlComponent();
|
||||
|
||||
void set_background_color(float r, float g, float b, float a = 1.0f);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<GlWindow> window;
|
||||
size_t window_index;
|
||||
std::shared_ptr<GlContainer> parent;
|
||||
size_t parent_index;
|
||||
|
||||
std::variant<int, float> position_x;
|
||||
std::variant<int, float> position_y;
|
||||
std::variant<int, float> size_width;
|
||||
std::variant<int, float> size_height;
|
||||
position_t position_x;
|
||||
position_t position_y;
|
||||
position_t size_width;
|
||||
position_t size_height;
|
||||
bool coord_all_relative;
|
||||
|
||||
std::array<float, 4> background_color;
|
||||
|
|
@ -38,8 +42,16 @@ protected:
|
|||
GLuint gl_ebo;
|
||||
|
||||
GlComponent(
|
||||
std::shared_ptr<GlWindow> window, const std::variant<int, float> x, const std::variant<int, float> y,
|
||||
const std::variant<int, float> width, const std::variant<int, float> height);
|
||||
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, window, window_index, x, y, width, height)
|
||||
{}
|
||||
GlComponent(const GlComponent&) = delete;
|
||||
GlComponent(GlComponent&&) = default;
|
||||
std::shared_ptr<GlComponent> getptr() { return shared_from_this(); }
|
||||
|
||||
virtual void init();
|
||||
virtual void set_vbo_data();
|
||||
|
|
|
|||
44
include/uui/opengl/container.hpp
Normal file
44
include/uui/opengl/container.hpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class GlComponent;
|
||||
class GlStack;
|
||||
class GlContainer
|
||||
{
|
||||
friend class GlComponent;
|
||||
friend class GlStack;
|
||||
|
||||
protected:
|
||||
GlContainer() = default;
|
||||
GlContainer(const GlContainer&) = default;
|
||||
GlContainer(GlContainer&&) = default;
|
||||
|
||||
virtual std::size_t push_child(std::shared_ptr<GlComponent> child)
|
||||
{
|
||||
components.push_back(child);
|
||||
return components.size() - 1;
|
||||
}
|
||||
virtual std::shared_ptr<GlComponent> get_child(std::size_t index) const { return components.at(index); }
|
||||
virtual void remove_child(std::size_t index) { components.at(index) = nullptr; };
|
||||
|
||||
virtual std::tuple<int, int> get_child_position(const std::size_t child_index) const { return {0, 0}; }
|
||||
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
WINDOW,
|
||||
STACK
|
||||
};
|
||||
std::vector<std::shared_ptr<GlComponent>> components;
|
||||
Type type;
|
||||
|
||||
~GlContainer() { components.clear(); }
|
||||
};
|
||||
|
||||
} // namespace uui
|
||||
|
|
@ -4,12 +4,15 @@
|
|||
#include <tuple>
|
||||
|
||||
#include "uui/opengl/component.hpp"
|
||||
#include "uui/opengl/container.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class GlStack;
|
||||
class GlLabel: public GlComponent
|
||||
{
|
||||
friend class GlWindow;
|
||||
friend class GlStack;
|
||||
|
||||
size_t font_index;
|
||||
|
||||
|
|
@ -24,8 +27,13 @@ protected:
|
|||
int text_height;
|
||||
|
||||
GlLabel(
|
||||
std::shared_ptr<GlWindow> window, const std::variant<int, float> x, const std::variant<int, float> y, const std::string& text,
|
||||
const std::tuple<float, float, float, float>& text_color);
|
||||
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)
|
||||
{}
|
||||
|
||||
void render();
|
||||
};
|
||||
|
|
|
|||
39
include/uui/opengl/stack.hpp
Normal file
39
include/uui/opengl/stack.hpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
#include "uui/opengl/component.hpp"
|
||||
#include "uui/opengl/container.hpp"
|
||||
#include "uui/opengl/label.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class GlStack: public GlComponent, public GlContainer
|
||||
{
|
||||
friend class GlWindow;
|
||||
|
||||
public:
|
||||
std::shared_ptr<GlComponent> create_component(const position_t width, const position_t height);
|
||||
std::shared_ptr<GlLabel> create_label(const std::string& text, const std::tuple<float, float, float, float>& text_color);
|
||||
|
||||
protected:
|
||||
Direction direction;
|
||||
int content_width;
|
||||
int content_height;
|
||||
|
||||
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)
|
||||
{}
|
||||
|
||||
float get_width() const;
|
||||
float get_height() const;
|
||||
|
||||
std::tuple<int, int> get_child_position(const std::size_t child_index) const override;
|
||||
};
|
||||
|
||||
} // namespace uui
|
||||
Loading…
Add table
Add a link
Reference in a new issue