Skip to content

Commit

Permalink
Support more integer types
Browse files Browse the repository at this point in the history
  • Loading branch information
wivlaro committed Jan 18, 2015
1 parent 2e2d06d commit 1bb9e74
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 80 deletions.
78 changes: 0 additions & 78 deletions GtkAbstractInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,6 @@
#include <numeric>

namespace MagnumInspector {

template<typename WidgetType, typename ValueType>
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<typename WidgetType, typename ValueType>
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<typename WidgetType, typename ValueType>
inline void ensure_digits(WidgetType& w, ValueType v) {
if (w.get_digits() != v) {
// std::cout << "set_digits\n";
w.set_digits(v);
}
}

template<typename WidgetType, typename ValueType>
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<typename WidgetType, typename ValueType>
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<typename WidgetType, typename ValueType>
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<typename WidgetType, typename ValueType>
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)
{
Expand All @@ -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<Gtk::Label>(name);
ensure_text(field, std::to_string(i));
}

void GtkAbstractInspector::editable(const char* name, int& i)
{
auto& field = addField<Gtk::SpinButton>(name);
ensure_range(field, double(std::numeric_limits<int>().lowest()), double(std::numeric_limits<int>().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<Gtk::Label>(name);
Expand Down
16 changes: 14 additions & 2 deletions GtkAbstractInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -63,6 +69,12 @@ class GtkAbstractInspector : public Inspector

template<uint Dimensions, typename ValueType>
void readonlyFeature(Magnum::SceneGraph::AbstractFeature<Dimensions, ValueType>& feature);


template<typename ValueType>
void editableInteger(const char* name, ValueType& i);
template<typename ValueType>
void readonlyInteger(const char* name, const ValueType& i);
};

}
79 changes: 79 additions & 0 deletions GtkAbstractInspector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,65 @@

namespace MagnumInspector {


template<typename WidgetType, typename ValueType>
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<typename WidgetType, typename ValueType>
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<typename WidgetType, typename ValueType>
inline void ensure_digits(WidgetType& w, ValueType v) {
if (w.get_digits() != v) {
// std::cout << "set_digits\n";
w.set_digits(v);
}
}

template<typename WidgetType, typename ValueType>
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<typename WidgetType, typename ValueType>
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<typename WidgetType, typename ValueType>
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<typename WidgetType, typename ValueType>
inline void ensure_active(WidgetType& w, ValueType v) {
if (w.get_active() != v) {
// std::cout << "set_active\n";
w.set_active(v);
}
}

template<typename T>
inline std::string getNameAndType(T& object) {
Expand Down Expand Up @@ -112,4 +171,24 @@ inline void GtkAbstractInspector::readonly(Inspectable* i) {
frame.childPopulator.pruneRemaining();
}

template<typename ValueType>
inline void GtkAbstractInspector::readonlyInteger(const char* name, const ValueType& i)
{
auto& field = addField<Gtk::Label>(name);
ensure_text(field, std::to_string(i));
}

template<typename ValueType>
inline void GtkAbstractInspector::editableInteger(const char* name, ValueType& i)
{
auto& field = addField<Gtk::SpinButton>(name);
ensure_range(field, double(std::numeric_limits<ValueType>().lowest()), double(std::numeric_limits<ValueType>().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());
});
}

}
6 changes: 6 additions & 0 deletions Inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down

0 comments on commit 1bb9e74

Please sign in to comment.