diff --git a/.clangd b/.clangd index 32169b9..122ab09 100644 --- a/.clangd +++ b/.clangd @@ -1,3 +1,2 @@ CompileFlags: - CompilationDatabase: bin - Add: ["--target=x86_64-w64-mingw32"] \ No newline at end of file + CompilationDatabase: bin \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ef766c..ac8ecb2 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,6 @@ list(APPEND OSTD_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/src/ostd/io/Stylesheet.cpp # math - ${CMAKE_CURRENT_LIST_DIR}/src/ostd/math/Geometry.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ostd/math/ShuntingYard.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ostd/math/Random.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ostd/math/SineWave.cpp diff --git a/src/ogfx/gui/Widgets.cpp b/src/ogfx/gui/Widgets.cpp index eb34147..878c71b 100644 --- a/src/ogfx/gui/Widgets.cpp +++ b/src/ogfx/gui/Widgets.cpp @@ -305,12 +305,8 @@ namespace ogfx return ostd::Rectangle(getGlobalPosition(), getSize()).contains(p, includeBounds); } - void Widget::addThemeOverride(const ostd::String& key, ostd::Stylesheet::TypeVariant value, const ostd::String& themeID, const ostd::String& qualifier, bool propagate) + void Widget::addThemeOverride(const ostd::String& fullKey, ostd::Stylesheet::TypeVariant value, bool propagate) { - ostd::String fullKey = "@" + themeID; - if (qualifier.new_trim() != "") - fullKey += ":" + qualifier; - fullKey += "." + key; m_themeOverrides.push_back({ fullKey, value, propagate }); } diff --git a/src/ogfx/gui/Widgets.hpp b/src/ogfx/gui/Widgets.hpp index 0015e6b..d4926ae 100644 --- a/src/ogfx/gui/Widgets.hpp +++ b/src/ogfx/gui/Widgets.hpp @@ -87,7 +87,7 @@ namespace ogfx using ostd::Rectangle::contains; bool contains(ostd::Vec2 p, bool includeBounds = false) const override; virtual void applyTheme(const ostd::Stylesheet& theme) = 0; - void addThemeOverride(const ostd::String& key, ostd::Stylesheet::TypeVariant value, const ostd::String& themeID = "", const ostd::String& qualifier = "", bool propagate = true); + void addThemeOverride(const ostd::String& fullKey, ostd::Stylesheet::TypeVariant value, bool propagate = true); void reloadTheme(void); void setThemeQualifier(const ostd::String& qualifier, bool value = true); bool getThemeQualifier(const ostd::String& qualifier); diff --git a/src/ostd/data/BaseObject.cpp b/src/ostd/data/BaseObject.cpp index 470612b..8a8cf76 100755 --- a/src/ostd/data/BaseObject.cpp +++ b/src/ostd/data/BaseObject.cpp @@ -25,12 +25,6 @@ namespace ostd return *this; } - std::ostream& operator<<(std::ostream& out, const BaseObject& val) - { - out << val.toString(); - return out; - } - void BaseObject::print(bool newLine, OutputHandlerBase* __destination) const { if (__destination == nullptr) diff --git a/src/ostd/data/BaseObject.hpp b/src/ostd/data/BaseObject.hpp index bdc4237..c58f095 100755 --- a/src/ostd/data/BaseObject.hpp +++ b/src/ostd/data/BaseObject.hpp @@ -21,14 +21,13 @@ #pragma once #include -#include #include namespace ostd { class OutputHandlerBase; struct Signal; - class BaseObject + class BaseObject : public __i_stringeable { public: BaseObject(const BaseObject& copy); @@ -56,7 +55,7 @@ namespace ostd inline bool signalsEnabled(void) { return m_signalsEnabled; } inline void enableSignals(bool e = true) { m_signalsEnabled = e; } - virtual inline String toString(void) const { return getObjectHeaderString(); }; + virtual inline String toString(void) const override { return getObjectHeaderString(); }; virtual void print(bool newLine = true, OutputHandlerBase* __destination = nullptr) const; virtual inline void handleSignal(Signal& signal) { } @@ -64,8 +63,6 @@ namespace ostd void __handle_signal(Signal& signal); - friend std::ostream& operator<<(std::ostream& os, const BaseObject& obj); - protected: inline BaseObject(void) { m_uid = -1; m_valid = false; m_oid = BaseObject::s_next_oid++; } private: diff --git a/src/ostd/io/Stylesheet.cpp b/src/ostd/io/Stylesheet.cpp index e91f02c..3b00585 100644 --- a/src/ostd/io/Stylesheet.cpp +++ b/src/ostd/io/Stylesheet.cpp @@ -303,7 +303,27 @@ namespace ostd { for (const auto&[key, value] : m_values) { - std::cout << key << "\n"; + std::cout << key << " = " << typeVariantToString(value) << "\n"; } } + + ostd::String Stylesheet::typeVariantToString(const TypeVariant& v) + { + ostd::String str = ""; + // if (auto p = std::get_if(&v)) + // str.add(*p); + // else if (auto p = std::get_if(&v)) + // str.add(*p); + // else if (auto p = std::get_if(&v)) + // str.add(STR_BOOL(*p)); + // else if (auto p = std::get_if(&v)) + // str.add(*p); + // else if (auto p = std::get_if(&v)) + // str.add(*p); + // else if (auto p = std::get_if(&v)) + // std::cout << std::format("{{ {}, {}, {}, {} }}", (*p).x, (*p).y, (*p).w, (*p).h); + // else if (auto p = std::get_if(&v)) + // std::cout << *p; + return str; + } } diff --git a/src/ostd/io/Stylesheet.hpp b/src/ostd/io/Stylesheet.hpp index bd84d6e..266f7f4 100644 --- a/src/ostd/io/Stylesheet.hpp +++ b/src/ostd/io/Stylesheet.hpp @@ -53,6 +53,7 @@ namespace ostd } void debugPrint(void); + ostd::String typeVariantToString(const TypeVariant& v); private: bool parseThemeFileLine(const ostd::String& line); diff --git a/src/ostd/math/Geometry.cpp b/src/ostd/math/Geometry.cpp deleted file mode 100755 index c4ce1a8..0000000 --- a/src/ostd/math/Geometry.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "Geometry.hpp" -#include "../string/String.hpp" - -namespace ostd -{ - String Vec2::toString(void) const - { - return String("{ ").add(x).add(", ").add(y).add(" }"); - } - String Vec3::toString(void) const - { - return String("{ ").add(x).add(", ").add(y).add(", ").add(z).add(" }"); - } -} diff --git a/src/ostd/math/Geometry.hpp b/src/ostd/math/Geometry.hpp index 13d1073..8519cf2 100755 --- a/src/ostd/math/Geometry.hpp +++ b/src/ostd/math/Geometry.hpp @@ -45,9 +45,8 @@ namespace ostd { - class OutputHandlerBase; template - class Point + class Point : public __i_stringeable { public: T x; @@ -65,6 +64,8 @@ namespace ostd x = (T2)(copy.x); y = (T2)(copy.y); } + + inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(" }"); } }; typedef Point FPoint; @@ -78,7 +79,7 @@ namespace ostd typedef Point I16Point; typedef Point I8Point; - struct Vec2 + struct Vec2 : public __i_stringeable { //======================== Data ======================== float x; @@ -103,7 +104,7 @@ namespace ostd //===================== Conversion ===================== inline Vec2 toIsometric(void) const { return Vec2(x - y, (x + y) / 2.0f); } inline Vec2 toCartesian(void) const { return Vec2((2 * y + x) / 2.0f, (2 * y - x) / 2.0f); } - String toString(void) const; + inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(" }"); } //====================================================== @@ -159,8 +160,6 @@ namespace ostd inline Vec2& operator-=(const float& op2) { return subm(op2, op2); } inline Vec2& operator*=(const float& op2) { return mulm(op2); } inline Vec2& operator/=(const float& op2) { return divm(op2); } - - friend std::ostream& operator<<(std::ostream& out, const Vec2& val); //====================================================== private: @@ -168,13 +167,7 @@ namespace ostd }; - inline std::ostream& operator<<(std::ostream& out, const Vec2& val) - { - out << val.toString(); - return out; - } - - struct Vec3 + struct Vec3 : public __i_stringeable { inline Vec3(float xx = 0, float yy = 0, float zz = 0) { @@ -186,25 +179,17 @@ namespace ostd inline Vec2 xy(void) const { return Vec2(x, y); } inline Vec2 yz(void) const { return Vec2(y, z); } inline Vec2 zx(void) const { return Vec2(z, x); } - String toString(void) const; + inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(", ").add(z).add(" }"); } inline bool operator==(const Vec3& op2 ) const { return (x == op2.x && y == op2.y && op2.z == z); } inline bool operator!=(const Vec3& op2 ) const { return (x != op2.x || y != op2.y || op2.z != z); } inline Vec3& operator+=(const Vec3& op2 ) { x += op2.x; y += op2.y; z += op2.z; return *this; } - friend std::ostream& operator<<(std::ostream& out, const Vec2& val); - float x; float y; float z; }; - inline std::ostream& operator<<(std::ostream& out, const Vec3& val) - { - out << val.toString(); - return out; - } - - struct Vec4 + struct Vec4 : public __i_stringeable { inline Vec4(float xx = 0, float yy = 0, float zz = 0, float ww = 0) { @@ -220,7 +205,7 @@ namespace ostd inline Vec2 yz(void) const { return Vec2(y, z); } inline Vec2 zw(void) const { return Vec2(z, w); } inline Vec2 wx(void) const { return Vec2(w, x); } - + inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(", ").add(z).add(", ").add(w).add(" }"); } float x; float y; @@ -228,7 +213,7 @@ namespace ostd float w; }; - struct Triangle + struct Triangle : public __i_stringeable { Vec2 vA; Vec2 vB; @@ -249,7 +234,7 @@ namespace ostd vC.x = cx; vC.y = cy; } - bool contains(Vec2 p) + inline bool contains(Vec2 p) { float d1, d2, d3; bool has_neg, has_pos; @@ -263,6 +248,7 @@ namespace ostd return !(has_neg && has_pos); } + inline String toString(void) const override { return String("{ A: ").add(vA.toString()).add(", B: ").add(vB.toString()).add(", C: ").add(vC.toString()).add(" }"); } private: inline float __sign(Vec2 p1, Vec2 p2, Vec2 p3) @@ -271,7 +257,7 @@ namespace ostd } }; - class Rectangle + class Rectangle : public __i_stringeable { public: inline Rectangle(void) : x(0), y(0), w(0), h(0) {} @@ -350,6 +336,8 @@ namespace ostd inline virtual float top(void) const { return gety(); } inline virtual float bottom(void) const { return geth(); } + inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(", ").add(w).add(", ").add(h).add(" }"); } + inline virtual bool intersects(Rectangle rect, bool includeBounds = true) const { if (includeBounds) @@ -397,13 +385,14 @@ namespace ostd }; template - class Rect + class Rect : public __i_stringeable { public: Rect(void) = default; inline Rect(T pos_x, T pos_y, T size_x, T size_y) : position(pos_x, pos_y), size(size_x, size_y) { } inline Rect(Point pos, Point _size) : position(pos), size(_size) { } template inline Rect(Rect copy) { position = { (T2)(copy.position.x), (T2)(copy.position.y) }; size = { (T2)(copy.size.x), (T2)(copy.size.y) }; } + inline String toString(void) const override { return String("{ ").add(position.x).add(", ").add(position.y).add(", ").add(size.x).add(", ").add(size.y).add(" }"); } public: Point position; @@ -422,13 +411,14 @@ namespace ostd typedef Rect I8Rect; template - class Line + class Line : public __i_stringeable { public: Line(void) = default; inline Line(T x1, T y1, T x2, T y2) : p1(x1, y1), p2(x2, y2) { } inline Line(Point _p1, Point _p2) : p1(_p1), p2(_p2) { } template inline Line(Line copy) { p1 = { (T2)(copy.p1.x), (T2)(copy.p1.y) }; p2 = { (T2)(copy.p2.x), (T2)(copy.p2.y) }; } + inline String toString(void) const override { return String("{ P1: ").add(p1.toString()).add(", P2").add(p2.toString()).add(" }"); } public: Point p1; diff --git a/src/ostd/string/String.hpp b/src/ostd/string/String.hpp index fd58cd9..4739e9d 100644 --- a/src/ostd/string/String.hpp +++ b/src/ostd/string/String.hpp @@ -22,6 +22,7 @@ #include #include +#include #include #define STR_BOOL(b) (b ? "true" : "false") @@ -179,6 +180,20 @@ namespace ostd private: ostd::cpp_string m_data; }; + + struct __i_stringeable + { + virtual String toString(void) const = 0; + friend std::ostream& operator<<(std::ostream& out, const __i_stringeable& val); + inline operator String() const { return toString(); } + inline operator std::string() const { return toString(); } + }; + + inline std::ostream& operator<<(std::ostream& out, const __i_stringeable& val) + { + out << val.toString(); + return out; + } } diff --git a/src/test/GuiTest.cpp b/src/test/GuiTest.cpp index 3ae5964..78493cc 100644 --- a/src/test/GuiTest.cpp +++ b/src/test/GuiTest.cpp @@ -62,7 +62,7 @@ class Window : public ogfx::gui::Window // m_label1.setMouseDraggedCallback([&](const ogfx::gui::Event& event) -> void { // m_label1.applyThemeValue(m_theme, "label.backgroundColor", ostd::Colors::DarkGreen, false); // }); - // addWidget(m_label1); + addWidget(m_label1); // m_label1.setThemeQualifier("disabled"); m_label2.setPosition(100, 400); @@ -73,6 +73,10 @@ class Window : public ogfx::gui::Window m_theme.loadFromFile("./testTheme.txt"); setTheme(m_theme); + + m_label2.addThemeOverride("@:hover.label.fontSize", 10); + m_label2.reloadTheme(); + m_theme.debugPrint(); }