From 73934d0e34b263ab17afc9e49af47f09dac2df0a Mon Sep 17 00:00:00 2001 From: Corentin Date: Thu, 6 Oct 2022 22:29:56 +0900 Subject: [PATCH] Code cleaning, update roadmap and manifest --- ROADMAP.md | 10 +++---- include/uui/application.hpp | 7 ++++- include/uui/component.hpp | 8 +----- include/uui/container.hpp | 8 ++---- include/uui/opengl/application.hpp | 7 +---- include/uui/opengl/component.hpp | 7 +++-- include/uui/opengl/container.hpp | 3 +- include/uui/opengl/window.hpp | 2 +- include/uui/style.hpp | 2 +- include/uui/{config.hpp => types.hpp} | 0 include/uui/uui.hpp | 2 +- include/uui/window.hpp | 8 +----- manifest.md | 6 +++- src/test/benchmark_text.cpp | 3 +- src/test/example_gl.cpp | 40 +++++++++++---------------- src/uui/opengl/component.cpp | 2 +- src/uui/opengl/container.cpp | 2 +- src/uui/opengl/font_manager.cpp | 2 +- src/uui/opengl/label.cpp | 2 +- src/uui/opengl/window.cpp | 11 ++++---- 20 files changed, 56 insertions(+), 76 deletions(-) rename include/uui/{config.hpp => types.hpp} (100%) diff --git a/ROADMAP.md b/ROADMAP.md index 6125280..b85818b 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,16 +1,16 @@ -* layout - * button -* lambda constructor - * scroll * Text wrap +* Style + +* Text Edition + * projected vertex/raw vertex mode (projection on GPU) -* negative absolution position (from right/bottom) +* negative absolute position (from right/bottom) * VAO/VBO in windows (batched) diff --git a/include/uui/application.hpp b/include/uui/application.hpp index 17c7d2f..7d813a0 100644 --- a/include/uui/application.hpp +++ b/include/uui/application.hpp @@ -3,7 +3,7 @@ #include #include -#include "uui/config.hpp" +#include "uui/types.hpp" namespace uui { @@ -11,6 +11,11 @@ class Window; class Application { public: +#ifdef DEBUG + constexpr static bool debug_mode = true; +#else + constexpr static bool debug_mode = false; +#endif enum Implementaion { OPENGL diff --git a/include/uui/component.hpp b/include/uui/component.hpp index 208720a..7bd2c39 100644 --- a/include/uui/component.hpp +++ b/include/uui/component.hpp @@ -3,7 +3,7 @@ #include #include -#include "uui/config.hpp" +#include "uui/types.hpp" #include "uui/window.hpp" namespace uui @@ -15,12 +15,6 @@ public: virtual void set_background_color(float r, float g, float b, float a = 1.0f) = 0; protected: - #ifdef DEBUG - constexpr static bool debug_mode = true; - #else - constexpr static bool debug_mode = false; - #endif - std::shared_ptr window; std::size_t window_index; std::shared_ptr parent; diff --git a/include/uui/container.hpp b/include/uui/container.hpp index f5a3d84..43d1b24 100644 --- a/include/uui/container.hpp +++ b/include/uui/container.hpp @@ -6,7 +6,7 @@ #include #include -#include "uui/config.hpp" +#include "uui/types.hpp" namespace uui { @@ -15,6 +15,7 @@ class GlComponent; class Container { friend class GlComponent; + public: enum Type { @@ -26,11 +27,6 @@ public: Type type; protected: -#ifdef DEBUG - constexpr static bool debug_mode = true; -#else - constexpr static bool debug_mode = false; -#endif virtual std::size_t push_child(std::shared_ptr child) = 0; virtual std::shared_ptr get_child(std::size_t index) const = 0; virtual void remove_child(std::size_t index) = 0; diff --git a/include/uui/opengl/application.hpp b/include/uui/opengl/application.hpp index 4860c89..4d2d4e6 100644 --- a/include/uui/opengl/application.hpp +++ b/include/uui/opengl/application.hpp @@ -6,7 +6,7 @@ #include "graphic_context.hpp" #include "uui/application.hpp" -#include "uui/config.hpp" +#include "uui/types.hpp" namespace uui { @@ -16,11 +16,6 @@ class GlApplication final: virtual public Application friend class GlWindow; public: -#ifdef DEBUG - constexpr static bool debug_mode = true; -#else - constexpr static bool debug_mode = false; -#endif std::vector> windows; GlApplication(); diff --git a/include/uui/opengl/component.hpp b/include/uui/opengl/component.hpp index 223d154..24230df 100644 --- a/include/uui/opengl/component.hpp +++ b/include/uui/opengl/component.hpp @@ -4,10 +4,10 @@ #include #include "graphic_context.hpp" -#include "uui/opengl/component.hpp" #include "uui/container.hpp" -#include "uui/config.hpp" +#include "uui/opengl/component.hpp" #include "uui/opengl/window.hpp" +#include "uui/types.hpp" namespace uui { @@ -39,7 +39,8 @@ protected: GlComponent( std::shared_ptr 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(window), window_index, x, y, width, height) + GlComponent( + window, window_index, std::static_pointer_cast(window), window_index, x, y, width, height) {} GlComponent(const GlComponent&) = delete; GlComponent(GlComponent&&) = default; diff --git a/include/uui/opengl/container.hpp b/include/uui/opengl/container.hpp index 973059e..ace8ae1 100644 --- a/include/uui/opengl/container.hpp +++ b/include/uui/opengl/container.hpp @@ -6,14 +6,13 @@ #include #include -#include "uui/container.hpp" #include "uui/component.hpp" +#include "uui/container.hpp" namespace uui { class GlContainer: virtual public Container { - protected: GlContainer() = default; GlContainer(const GlContainer&) = default; diff --git a/include/uui/opengl/window.hpp b/include/uui/opengl/window.hpp index 0e04afd..5c064e0 100644 --- a/include/uui/opengl/window.hpp +++ b/include/uui/opengl/window.hpp @@ -1,9 +1,9 @@ #pragma once -#include "uui/config.hpp" #include "uui/opengl/application.hpp" #include "uui/opengl/container.hpp" #include "uui/opengl/font_manager.hpp" +#include "uui/types.hpp" #include "uui/window.hpp" namespace uui diff --git a/include/uui/style.hpp b/include/uui/style.hpp index 22d7401..c3d4781 100644 --- a/include/uui/style.hpp +++ b/include/uui/style.hpp @@ -4,7 +4,7 @@ #include #include -#include "config.hpp" +#include "types.hpp" namespace uui { diff --git a/include/uui/config.hpp b/include/uui/types.hpp similarity index 100% rename from include/uui/config.hpp rename to include/uui/types.hpp diff --git a/include/uui/uui.hpp b/include/uui/uui.hpp index 0c04834..6718260 100644 --- a/include/uui/uui.hpp +++ b/include/uui/uui.hpp @@ -1,9 +1,9 @@ #pragma once #include "uui/application.hpp" -#include "uui/config.hpp" #include "uui/component.hpp" #include "uui/flex.hpp" #include "uui/label.hpp" #include "uui/stack.hpp" +#include "uui/types.hpp" #include "uui/window.hpp" diff --git a/include/uui/window.hpp b/include/uui/window.hpp index 7cc52d5..ca58191 100644 --- a/include/uui/window.hpp +++ b/include/uui/window.hpp @@ -5,9 +5,9 @@ #include #include "uui/application.hpp" -#include "uui/config.hpp" #include "uui/container.hpp" #include "uui/font_manager.hpp" +#include "uui/types.hpp" namespace uui { @@ -39,12 +39,6 @@ public: int height() { return _height; }; protected: -#ifdef DEBUG - constexpr static bool debug_mode = true; -#else - constexpr static bool debug_mode = false; -#endif - std::shared_ptr _app; bool _initialized; diff --git a/manifest.md b/manifest.md index 1c88ca7..d817af0 100644 --- a/manifest.md +++ b/manifest.md @@ -8,6 +8,10 @@ * Let custom rendering +* Canvas for easy drawing + +* Style/Config watch option : real-time update on file change + ## Technical @@ -26,4 +30,4 @@ ## Layout / Style -* Constraint based? padding/margin? +* CSS subset diff --git a/src/test/benchmark_text.cpp b/src/test/benchmark_text.cpp index 24eeffa..693bc82 100644 --- a/src/test/benchmark_text.cpp +++ b/src/test/benchmark_text.cpp @@ -11,7 +11,8 @@ 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) { - 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}, {}); + 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}, {}); }); app->run(); } diff --git a/src/test/example_gl.cpp b/src/test/example_gl.cpp index 65650cf..59706f8 100644 --- a/src/test/example_gl.cpp +++ b/src/test/example_gl.cpp @@ -31,45 +31,37 @@ int main() 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_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); - }); + 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_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); - }); + 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_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); - }); + stack.create_component( + 100, 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_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); - }); + stack.create_component( + 100, 20, [](uui::Component& component) { component.set_background_color(0.2f, 0.25f, 0.75f); }); }); }); diff --git a/src/uui/opengl/component.cpp b/src/uui/opengl/component.cpp index 280fd12..d4c72cf 100644 --- a/src/uui/opengl/component.cpp +++ b/src/uui/opengl/component.cpp @@ -10,7 +10,7 @@ uui::GlComponent::GlComponent( std::shared_ptr window, std::size_t window_index, std::shared_ptr parent, std::size_t parent_index, const position_t x, const position_t y, const position_t width, const position_t height) { - if constexpr(debug_mode) + if constexpr(uui::Application::debug_mode) std::cout << "Creating a GlComponent " << parent_index << std::endl; gl_window = window; diff --git a/src/uui/opengl/container.cpp b/src/uui/opengl/container.cpp index c9d0242..4d45bf0 100644 --- a/src/uui/opengl/container.cpp +++ b/src/uui/opengl/container.cpp @@ -31,7 +31,7 @@ std::tuple uui::GlContainer::get_child_position(const std::size_t chil uui::GlContainer::~GlContainer() { - if constexpr(debug_mode) + if constexpr(uui::Application::debug_mode) std::cout << "Destroying GlContainer" << std::endl; components.clear(); } diff --git a/src/uui/opengl/font_manager.cpp b/src/uui/opengl/font_manager.cpp index 6e66b2a..59c7ebf 100644 --- a/src/uui/opengl/font_manager.cpp +++ b/src/uui/opengl/font_manager.cpp @@ -6,7 +6,7 @@ #include #include -#include "uui/config.hpp" +#include "uui/types.hpp" #include "uui/opengl/application.hpp" #include "uui/opengl/gl_utils.hpp" #include "uui/shader.hpp" diff --git a/src/uui/opengl/label.cpp b/src/uui/opengl/label.cpp index 88fc169..981d0a9 100644 --- a/src/uui/opengl/label.cpp +++ b/src/uui/opengl/label.cpp @@ -12,7 +12,7 @@ uui::GlLabel::GlLabel( GlComponent(window, window_index, parent, parent_index, x, y, 0.0f, 0.0f), text(text), text_color(text_color) { - if constexpr(debug_mode) + if constexpr(uui::Application::debug_mode) std::cout << "Creating GlLabel " << parent_index << std::endl; font_index = 0; diff --git a/src/uui/opengl/window.cpp b/src/uui/opengl/window.cpp index 096a226..19f0dea 100644 --- a/src/uui/opengl/window.cpp +++ b/src/uui/opengl/window.cpp @@ -6,7 +6,6 @@ #include "uui/opengl/flex.hpp" #include "uui/opengl/gl_utils.hpp" #include "uui/opengl/label.hpp" -#include "uui/opengl/flex.hpp" #include "uui/opengl/stack.hpp" #include "uui/shader.hpp" @@ -80,7 +79,8 @@ void uui::GlWindow::glfw_iconify_callback(GLFWwindow* window, int iconified) gl_window->_iconified = iconified; } -void uui::GlWindow::glfw_key_callback(GLFWwindow* window, int key, int scancode [[maybe_unused]], int action, int mods [[maybe_unused]]) +void uui::GlWindow::glfw_key_callback( + GLFWwindow* window, int key, int scancode [[maybe_unused]], int action, int mods [[maybe_unused]]) { if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, true); @@ -96,7 +96,7 @@ uui::GlWindow::GlWindow(std::shared_ptr app, int width, int he _resize_needed = false; _iconified = false; - if constexpr(debug_mode) + if constexpr(uui::Application::debug_mode) std::cout << "Creating GlWindow : " << title << std::endl; this->title = title; type = Type::WINDOW; @@ -104,11 +104,11 @@ uui::GlWindow::GlWindow(std::shared_ptr app, int width, int he uui::GlWindow::~GlWindow() { - if constexpr(debug_mode) + if constexpr(uui::Application::debug_mode) std::cout << "Destructor GlWindow : " << title << std::endl; if(_initialized) { - if constexpr(debug_mode) + if constexpr(uui::Application::debug_mode) std::cout << "Destructor-deinit GlWindow : " << title << std::endl; deinit(); } @@ -330,4 +330,3 @@ void uui::GlWindow::create_stack( if(stack != nullptr && init != nullptr) init(*stack); } -