From 1bb9e74a50d83489b24d144480ca1abf9a3f566c Mon Sep 17 00:00:00 2001 From: Bill Robinson Date: Sun, 18 Jan 2015 20:36:13 +0000 Subject: [PATCH] Support more integer types --- GtkAbstractInspector.cpp | 78 --------------------------------------- GtkAbstractInspector.h | 16 +++++++- GtkAbstractInspector.hpp | 79 ++++++++++++++++++++++++++++++++++++++++ Inspector.h | 6 +++ 4 files changed, 99 insertions(+), 80 deletions(-) diff --git a/GtkAbstractInspector.cpp b/GtkAbstractInspector.cpp index 46de5c7..2a5fcd0 100644 --- a/GtkAbstractInspector.cpp +++ b/GtkAbstractInspector.cpp @@ -9,65 +9,6 @@ #include namespace MagnumInspector { - -template -inline void ensure_range(WidgetType& w, ValueType min, ValueType max) { - ValueType currentMin,currentMax; - w.get_range(currentMin, currentMax); - if (currentMin != min || currentMax != max) { -// std::cout << "set_range\n"; - w.set_range(min, max); - } -} -template -inline void ensure_increments(WidgetType& w, ValueType a, ValueType b) { - ValueType ca,cb; - w.get_increments(ca, cb); - if (ca != a || cb != b) { -// std::cout << "set_incrementse\n"; - w.set_increments(a, b); - } -} - -template -inline void ensure_digits(WidgetType& w, ValueType v) { - if (w.get_digits() != v) { -// std::cout << "set_digits\n"; - w.set_digits(v); - } -} - -template -inline void ensure_width_chars(WidgetType& w, ValueType v) { - if (w.get_width_chars() != v) { -// std::cout << "set_width_chars\n"; - w.set_width_chars(v); - } -} - -template -inline void ensure_value(WidgetType& w, ValueType v) { - if (ValueType(w.get_value()) != v) { -// std::cout << "set_value " << w.get_value() << "!=" << v << "\n"; - w.set_value(v); - } -} - -template -inline void ensure_text(WidgetType& w, ValueType v) { - if (w.get_text() != v) { -// std::cout << "set_text “" << w.get_text() << "” != “" << v << "”\n"; - w.set_text(v); - } -} - -template -inline void ensure_active(WidgetType& w, ValueType v) { - if (w.get_active() != v) { -// std::cout << "set_active\n"; - w.set_active(v); - } -} void GtkAbstractInspector::readonly(const char* name, const float* f, uint n, uint m) { @@ -91,25 +32,6 @@ void GtkAbstractInspector::editable(const char* name, float* f, uint n, uint m) }); } - -void GtkAbstractInspector::readonly(const char* name, const int& i) -{ - auto& field = addField(name); - ensure_text(field, std::to_string(i)); -} - -void GtkAbstractInspector::editable(const char* name, int& i) -{ - auto& field = addField(name); - ensure_range(field, double(std::numeric_limits().lowest()), double(std::numeric_limits().max())); - ensure_digits(field, 0u); - ensure_increments(field, 1.0, 10.0); - if (!field.has_focus()) ensure_value(field, double(i)); - field.signal_value_changed().connect([&] { - i = field.get_value_as_int(); - }); -} - void GtkAbstractInspector::readonly(const char* name, const std::string& s) { auto& field = addField(name); diff --git a/GtkAbstractInspector.h b/GtkAbstractInspector.h index a198bb9..0376676 100644 --- a/GtkAbstractInspector.h +++ b/GtkAbstractInspector.h @@ -19,8 +19,14 @@ class GtkAbstractInspector : public Inspector virtual void editable(const char* name, bool& i); virtual void readonly(const char* name, bool i); - virtual void editable(const char* name, int& i); - virtual void readonly(const char* name, const int& i); + virtual void editable(const char* name, int& i) { editableInteger(name, i); } + virtual void readonly(const char* name, const int& i) { readonlyInteger(name, i); } + + virtual void editable(const char* name, long& i) { editableInteger(name, i); } + virtual void readonly(const char* name, const long& i) { readonlyInteger(name, i); } + + virtual void editable(const char* name, unsigned long& i) { editableInteger(name, i); } + virtual void readonly(const char* name, const unsigned long& i) { readonlyInteger(name, i); } virtual void editable(const char* name, float& f); virtual void readonly(const char* name, const float& f); @@ -63,6 +69,12 @@ class GtkAbstractInspector : public Inspector template void readonlyFeature(Magnum::SceneGraph::AbstractFeature& feature); + + + template + void editableInteger(const char* name, ValueType& i); + template + void readonlyInteger(const char* name, const ValueType& i); }; } \ No newline at end of file diff --git a/GtkAbstractInspector.hpp b/GtkAbstractInspector.hpp index e912ceb..dc00de4 100644 --- a/GtkAbstractInspector.hpp +++ b/GtkAbstractInspector.hpp @@ -9,6 +9,65 @@ namespace MagnumInspector { + +template +inline void ensure_range(WidgetType& w, ValueType min, ValueType max) { + ValueType currentMin,currentMax; + w.get_range(currentMin, currentMax); + if (currentMin != min || currentMax != max) { +// std::cout << "set_range\n"; + w.set_range(min, max); + } +} +template +inline void ensure_increments(WidgetType& w, ValueType a, ValueType b) { + ValueType ca,cb; + w.get_increments(ca, cb); + if (ca != a || cb != b) { +// std::cout << "set_incrementse\n"; + w.set_increments(a, b); + } +} + +template +inline void ensure_digits(WidgetType& w, ValueType v) { + if (w.get_digits() != v) { +// std::cout << "set_digits\n"; + w.set_digits(v); + } +} + +template +inline void ensure_width_chars(WidgetType& w, ValueType v) { + if (w.get_width_chars() != v) { +// std::cout << "set_width_chars\n"; + w.set_width_chars(v); + } +} + +template +inline void ensure_value(WidgetType& w, ValueType v) { + if (ValueType(w.get_value()) != v) { +// std::cout << "set_value " << w.get_value() << "!=" << v << "\n"; + w.set_value(v); + } +} + +template +inline void ensure_text(WidgetType& w, ValueType v) { + if (w.get_text() != v) { +// std::cout << "set_text “" << w.get_text() << "” != “" << v << "”\n"; + w.set_text(v); + } +} + +template +inline void ensure_active(WidgetType& w, ValueType v) { + if (w.get_active() != v) { +// std::cout << "set_active\n"; + w.set_active(v); + } +} template inline std::string getNameAndType(T& object) { @@ -112,4 +171,24 @@ inline void GtkAbstractInspector::readonly(Inspectable* i) { frame.childPopulator.pruneRemaining(); } +template +inline void GtkAbstractInspector::readonlyInteger(const char* name, const ValueType& i) +{ + auto& field = addField(name); + ensure_text(field, std::to_string(i)); +} + +template +inline void GtkAbstractInspector::editableInteger(const char* name, ValueType& i) +{ + auto& field = addField(name); + ensure_range(field, double(std::numeric_limits().lowest()), double(std::numeric_limits().max())); + ensure_digits(field, 0u); + ensure_increments(field, 1.0, 10.0); + if (!field.has_focus()) ensure_value(field, i); + field.signal_value_changed().connect([&] { + i = ValueType(field.get_value()); + }); +} + } \ No newline at end of file diff --git a/Inspector.h b/Inspector.h index 0aab01b..47ae592 100644 --- a/Inspector.h +++ b/Inspector.h @@ -41,6 +41,12 @@ class Inspector virtual void editable(const char* name, int& i) = 0; virtual void readonly(const char* name, const int& i) = 0; + virtual void editable(const char* name, long& i) = 0; + virtual void readonly(const char* name, const long& i) = 0; + + virtual void editable(const char* name, unsigned long& i) = 0; + virtual void readonly(const char* name, const unsigned long& i) = 0; + virtual void editable(const char* name, Magnum::Vector2& i) { editable(name, i.data(), 2u, 1u); } virtual void readonly(const char* name, const Magnum::Vector2& i) { readonly(name, i.data(), 2u, 1u); }