From 8baf5e927c50fc27fc0e1941597928d8734ac4b2 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 25 Oct 2009 15:41:57 +0000 Subject: [PATCH] Remove the silly properties interface --- include/gui2/ILayout.hpp | 16 ---------------- include/gui2/Label.hpp | 2 -- include/gui2/Widget.hpp | 28 ++++------------------------ layouts/demo.xml | 4 ++-- src/ft/Font.cpp | 11 +++++++++++ src/ft/IFont.hpp | 1 + src/gui2/Button.cpp | 5 +++-- src/gui2/Label.cpp | 6 +++--- src/gui2/Widget.cpp | 28 +++++++--------------------- src/gui2/Window.cpp | 5 +++-- 10 files changed, 34 insertions(+), 72 deletions(-) diff --git a/include/gui2/ILayout.hpp b/include/gui2/ILayout.hpp index f539ee2..cbd4cdc 100644 --- a/include/gui2/ILayout.hpp +++ b/include/gui2/ILayout.hpp @@ -29,25 +29,9 @@ namespace gui { // A generic UI element struct IWidget { virtual ~IWidget() {} - - virtual boost::any get_property(const string& key) const = 0; - virtual void set_property(const string& key, boost::any value) = 0; }; typedef shared_ptr IWidgetPtr; - - template - inline T get_property(IWidgetPtr elem, const string& key) - { - return boost::any_cast(elem->get_property(key)); - } - - template - inline void set_property(IWidgetPtr elem, const string& key, - const T& value) - { - elem->set_property(key, value); - } // A complete set of UI elements struct ILayout { diff --git a/include/gui2/Label.hpp b/include/gui2/Label.hpp index 5c5f1de..1b77cab 100644 --- a/include/gui2/Label.hpp +++ b/include/gui2/Label.hpp @@ -18,8 +18,6 @@ #ifndef INC_GUI_LABEL_HPP #define INC_GUI_LABEL_HPP -// Internal header: do not include this file directly - #include "Platform.hpp" #include "gui2/Widget.hpp" diff --git a/include/gui2/Widget.hpp b/include/gui2/Widget.hpp index cce1161..1f7501d 100644 --- a/include/gui2/Widget.hpp +++ b/include/gui2/Widget.hpp @@ -28,8 +28,6 @@ #include #include -#include - namespace gui { class Widget : public IWidget { @@ -41,39 +39,21 @@ namespace gui { int y() const { return y_; } int width() const { return width_; } int height() const { return height_; } + + void width(int w) { width_ = w; } + void height(int h) { height_ = h; } boost::any get_property(const string& key) const; void set_property(const string& key, boost::any value); virtual void render(RenderContext& rc) const = 0; - protected: - template - void const_property(const string& key, T& value, - const T& def = T()) - { - value = tmp_attrs.get(key, def); - read_properties[key] = value; - } - - template - void property(const string& key, T& value, const T& def = T()) - { - const_property(key, value); // Readable as well - write_properties[key] = ref(value); - } - private: static string unique_name(); string name_; int x_, y_, width_, height_; - - const AttributeSet& tmp_attrs; // Do not use after initialisation - - typedef map PropertyMap; - PropertyMap read_properties, write_properties; - + static int unique_id; }; diff --git a/layouts/demo.xml b/layouts/demo.xml index a91e49d..c937243 100644 --- a/layouts/demo.xml +++ b/layouts/demo.xml @@ -5,7 +5,7 @@