Skip to content

Commit

Permalink
add RESIZE event const
Browse files Browse the repository at this point in the history
  • Loading branch information
mmertama committed Oct 23, 2023
1 parent 600a7d6 commit 68a3988
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions gempyrelib/include/gempyre.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ namespace Gempyre {
int height;
};


public:
/// Copy constructor.
Element(const Element& other) = default;
Expand Down Expand Up @@ -144,7 +145,7 @@ namespace Gempyre {
/// @param value - attribute value
/// @return this element
Element& set_attribute(const std::string& attr, const std::string& value);
/// @brief Set HTML a attribute of this element
/// @brief Set HTML a attribute of this element
/// @param attr - attribute name
/// @return this element
Element& set_attribute(const std::string& attr);
Expand Down Expand Up @@ -180,7 +181,7 @@ namespace Gempyre {
/// @cond INTERNAL
const GempyreInternal& ref() const;
GempyreInternal& ref();
static const std::string generateId(const std::string& prefix);
static const std::string generateId(const std::string& prefix);
protected:
Ui* m_ui;
std::string m_id;
Expand Down Expand Up @@ -225,6 +226,8 @@ namespace Gempyre {
static constexpr auto FOCUS_OUT = "focusout";
/// Load
static constexpr auto LOAD = "load";
/// Resize - use ui.root().subscribe(Event::RESIZE, [... for window resize
static constexpr auto RESIZE = "resize";

/// @brief element that has emitted the event, the same that did subscription.
Element element;
Expand Down
28 changes: 27 additions & 1 deletion gempyrelib/src/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#include <chrono>
#include <charconv>

// helper type for the visitor #4
template<class... Ts>
struct overloaded : Ts... { using Ts::operator()...; };
// explicit deduction guide (not needed as of C++20)
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

using namespace Gempyre;

const std::string Element::generateId(const std::string& prefix) {
Expand Down Expand Up @@ -68,6 +75,25 @@ Element& Element::set_attribute(const std::string &attr) {
"value", "true");
return *this;
}
/*
using AttrValueType = std::variant<bool, int, unsigned, float, double>;
template <typename T>
void Element::send(Element& el, const std::string& attr, const T& value) {
el.ref().send(el, "set_attribute", "attribute", attr, "value", value);
}
Element& Element::set_attribute(const std::string& attr, const AttrValueType& value) {
std::visit(overloaded {
[&, this](const bool& v) {send(*this, attr, v);},
[&, this](const int& v) {send(*this, attr, v);},
[&, this](const double& v) {send(*this, attr, v);},
[&, this](const float& v) {send(*this, attr, v);},
[&, this](const unsigned& v) {send(*this, attr, v);},
}, value);
return *this;
}
*/

Element& Element::remove_attribute(const std::string &attr) {
ref().send(*this, "remove_attribute",
Expand Down Expand Up @@ -159,7 +185,7 @@ std::optional<Element> Element::parent() const {
return m_ui->root();
return Gempyre::Element(*m_ui, *pid);
}


Element::~Element() {}

Expand Down

0 comments on commit 68a3988

Please sign in to comment.