Index: /trunk/nv/gui/gui_element.hh
===================================================================
--- /trunk/nv/gui/gui_element.hh	(revision 267)
+++ /trunk/nv/gui/gui_element.hh	(revision 268)
@@ -14,5 +14,5 @@
 #define NV_GUI_ELEMENT_HH
 
-#include <nv/object.hh>
+#include <nv/common.hh>
 #include <nv/position.hh>
 #include <nv/io_event.hh>
@@ -23,122 +23,35 @@
 	namespace gui
 	{
-		class element : public object
+		class element
 		{
 		protected:
+			/// List type
+			typedef std::list<element*> list;
 
-			/**
-			 * Creates a new GUI element with the give root node and positioning data.
-			 *
-			 * @param r The rectangle representing the position and size of this element.
-			 */
+
 			explicit element( const rectangle& r )
-					: object( "" ), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true ), m_render_data( nullptr ) {}
-
-		public:
-
-			/**
-			 * Checks if this element contains the given point.
-			 *
-			 * @param p The point to check.
-			 * @returns True if the point is within the region of the element, false otherwise.
-			 */
-			virtual bool contains( const position& p ) const
-			{
-				return m_absolute.contains( p );
-			}
-
-			/**
-			 * Gets the position and size of the element relative to its parent.
-			 *
-			 * @returns The element's position and size relative to its parent.
-			 */
-			virtual const rectangle& get_relative() const { return m_relative; }
-
-			/**
-			 * Gets the position and size of the element relative to the root (window).
-			 *
-			 * @returns The element's position and size relative to the root (window).
-			 */
-			virtual const rectangle& get_absolute() const { return m_absolute; }
-
-			/**
-			 * Gets whether this element is currently accepting events.
-			 *
-			 * @returns True if the element is receiving events, false otherwise.
-			 */
-			virtual bool is_enabled() const { return m_enabled; }
-
-			/**
-			 * Gets whether this element is currently visible.
-			 *
-			 * @returns True if the element is visible, false otherwise.
-			 */
-			virtual bool is_visible() const { return m_visible; }
-
-			/**
-			 * Gets whether this element needs to be redrawn.
-			 *
-			 * @returns True if the element needs to be redrawn, false if not.
-			 */
-			virtual bool is_dirty()   const { return m_dirty; }
-
-			/**
-			 * Sets whether this element is currently accepting events.
-			 *
-			 * @param value True to allow the element and its children to receive events, false to disable.
-			 */
-			virtual void set_enabled( bool value ) { m_enabled = value; }
-
-			/**
-			 * Sets whether this element is visible on the screen.
-			 *
-			 * @param value True to display the element and its children, false to hide it and its children.
-			 */
-			virtual void set_visible( bool value ) { m_visible = value; }
-
-			/**
-			 * Sets whether this element needs to be redrawn.
-			 *
-			 * @param value True to request that the element and its children be redrawn, false if not.
-			 */
-			virtual void set_dirty( bool value )   { m_dirty   = value; }
-
-			/**
-			 * Gets the text associated with this element.
-			 *
-			 * @returns A string containing the associated text.
-			 */
-			virtual const string& get_text() const { return m_text; }
-
-			/**
-			 * Sets the text associated with this element.
-			 *
-			 * @param text The new text to associate with this element.
-			 */
-			virtual void set_text( const string& text ) { m_text = text; m_dirty = true; }
-
-			/**
-			 * Gets the class name associated with this element.
-			 *
-			 * @returns A string containing the class name of this element.
-			 */
-			virtual const string& get_class() const { return m_class; }
-
-			/**
-			 * sets the class name associated with this element.
-			 *
-			 * @param class_ The new class name.
-			 */
-			virtual void set_class( const string& class_ ) { m_class = class_; m_dirty = true; }
+				: m_id( "" )
+				, m_parent( nullptr )
+				, m_children()
+				, m_child_count(0)
+				, m_class("")
+				, m_relative( r )
+				, m_absolute( r )
+				, m_enabled( true )
+				, m_visible( true )
+				, m_dirty( true )
+				, m_render_data( nullptr ) {}
 
 		protected:
-			/**
-			 * Destroys the element.
-			 */
 			virtual ~element() { delete m_render_data; }
 		protected:
 			friend class environment;
 			friend class renderer;
+			friend class style;
 
+			string    m_id;              ///< id type of the object
+			element*  m_parent;          ///< pointer to parent
+			list      m_children;        ///< children objects
+			size_t    m_child_count;     ///< number of children
 			string    m_class; ///< Class name.
 			string    m_text; ///< Displayed label or text.
Index: /trunk/nv/gui/gui_environment.hh
===================================================================
--- /trunk/nv/gui/gui_environment.hh	(revision 267)
+++ /trunk/nv/gui/gui_environment.hh	(revision 268)
@@ -26,4 +26,8 @@
 	namespace gui
 	{
+		class handle
+		{
+
+		};
 
 		class environment
@@ -34,4 +38,6 @@
 			void load_style( const std::string& filename );
 			element* create_element( element* parent, const rectangle& r );
+			void set_text( element* e, const string& text );
+			void set_class( element* e, const string& text );
 			void update();
 			void draw();
@@ -42,4 +48,6 @@
 			element* get_element( const position& p );
 			void add_child( element* child );
+			void add_child( element* parent, element* child );
+			void remove_child( element* parent, element* child );
 			void destroy_children( element* e );
 			void update( element* e, uint32 elapsed );
Index: /trunk/src/gui/gui_environment.cc
===================================================================
--- /trunk/src/gui/gui_environment.cc	(revision 267)
+++ /trunk/src/gui/gui_environment.cc	(revision 268)
@@ -42,5 +42,5 @@
 	element* result = new element( r );
 	if ( parent == nullptr ) parent = m_screen;
-	parent->add_child( result );
+	add_child( parent, result );
 	return result;
 }
@@ -49,5 +49,8 @@
 {
 	destroy_children( e );
-	e->detach();
+	if ( e->m_parent ) 
+	{
+		remove_child( e->m_parent, e );
+	}
 	delete e;
 }
@@ -56,15 +59,15 @@
 {
 //	e->on_update( elapsed );
-	if ( e->is_visible() )
-	{
-		for ( object* i : *e )
-		{
-			update( ((element*)i), elapsed );
-		}
-	}
-	if ( e->is_dirty() || e->m_render_data == nullptr )
+	if ( e->m_visible )
+	{
+		for ( element* i : e->m_children )
+		{
+			update( i, elapsed );
+		}
+	}
+	if ( e->m_dirty || e->m_render_data == nullptr )
 	{
 		m_renderer->redraw( e, elapsed );
-		e->set_dirty( false );
+		e->m_dirty = false;
 	}
 }
@@ -72,11 +75,11 @@
 void nv::gui::environment::draw( element* e )
 {
-	if ( e->is_visible() )
+	if ( e->m_visible )
 	{
 //		e->on_draw();
 		m_renderer->draw( e );
-		for ( object* i : *e )
-		{
-			draw((element*)i);
+		for ( element* i : e->m_children )
+		{
+			draw(i);
 		}
 	}
@@ -96,5 +99,19 @@
 void nv::gui::environment::add_child( element* child )
 {
-	m_screen->add_child( child );
+	add_child( m_screen, child );
+}
+
+void nv::gui::environment::add_child( element* parent, element* child )
+{
+	if ( child )
+	{
+		if ( child->m_parent )
+		{
+			remove_child( child->m_parent, child );
+		}
+		child->m_parent = parent;
+		parent->m_children.push_back( child );
+		parent->m_child_count++;
+	}
 }
 
@@ -103,5 +120,5 @@
 	while ( !e->m_children.empty() )
 	{
-		destroy_element( (element*)e->m_children.front() );
+		destroy_element( e->m_children.front() );
 	}
 }
@@ -121,5 +138,5 @@
 bool nv::gui::environment::process_io_event( element* e, const io_event& ev )
 {
-	return e->m_parent ? process_io_event( (element*)e->m_parent, ev ) : false;
+	return e->m_parent ? process_io_event( e->m_parent, ev ) : false;
 }
 
@@ -131,5 +148,5 @@
 nv::gui::element* nv::gui::environment::get_deepest_child( element* e, const position& p )
 {
-	if ( !e->is_visible() ) return nullptr;
+	if ( !e->m_visible ) return nullptr;
 
 	element* result = nullptr;
@@ -138,10 +155,10 @@
 	while ( it != e->m_children.rend() )
 	{
-		result = get_deepest_child( (element*)(*it), p );
+		result = get_deepest_child( *it, p );
 		if ( result ) return result;
 		++it;
 	}
 
-	if ( e->contains( p ) ) return e;
+	if ( e->m_absolute.contains(p) ) return e;
 	return nullptr;
 }
@@ -149,8 +166,8 @@
 void nv::gui::environment::move_to_top( element* child )
 {
-	element* parent = (element*)child->m_parent;
+	element* parent = child->m_parent;
 	if ( parent )
 	{
-		auto it = std::find( parent->m_children.begin(), parent->m_children.end(), (object*)child );
+		auto it = std::find( parent->m_children.begin(), parent->m_children.end(), child );
 		if ( it != parent->m_children.end() )
 		{
@@ -164,8 +181,8 @@
 void nv::gui::environment::move_to_bottom( element* child )
 {
-	element* parent = (element*)child->m_parent;
+	element* parent = child->m_parent;
 	if ( parent )
 	{
-		auto it = std::find( parent->m_children.begin(), parent->m_children.end(), (object*)child );
+		auto it = std::find( parent->m_children.begin(), parent->m_children.end(), child );
 		if ( it != parent->m_children.end() )
 		{
@@ -195,13 +212,40 @@
 	if ( e->m_parent )
 	{
-		pabsolute = ((element*)(e->m_parent))->m_absolute;
+		pabsolute = e->m_parent->m_absolute;
 	}
 
 	e->m_absolute = e->m_relative + pabsolute.ul;
 
-	for ( object* o : e->m_children )
-	{
-		recalculate_absolute( ((element*)o) );
-	}
-}
-
+	for ( element* o : e->m_children )
+	{
+		recalculate_absolute( o );
+	}
+}
+
+void nv::gui::environment::set_class( element* e, const string& text )
+{
+	e->m_class = text;
+	e->m_dirty = true;
+}
+
+void nv::gui::environment::set_text( element* e, const string& text )
+{
+	e->m_text = text;
+	e->m_dirty = true;
+}
+
+void nv::gui::environment::remove_child( element* parent, element* child )
+{
+	if ( child->m_parent != parent )
+	{
+		return; // signal error?
+	}
+	auto it = std::find( parent->m_children.begin(), parent->m_children.end(), child );
+	if ( it != parent->m_children.end() )
+	{
+		(*it)->m_parent = nullptr;
+		parent->m_children.erase(it);
+	}	
+
+}
+
Index: /trunk/src/gui/gui_renderer.cc
===================================================================
--- /trunk/src/gui/gui_renderer.cc	(revision 267)
+++ /trunk/src/gui/gui_renderer.cc	(revision 268)
@@ -198,6 +198,6 @@
 
 	qvec.clear();
-	rectangle abs = e->get_absolute();
-	if ( e->get_absolute() != m_area )
+	rectangle abs = e->m_absolute;
+	if ( e->m_absolute != m_area )
 	{
 		int border;
@@ -220,5 +220,5 @@
 		}
 
-		text = e->get_text();
+		text = e->m_text;
 		if ( !text.empty() )
 		{
Index: /trunk/src/gui/gui_style.cc
===================================================================
--- /trunk/src/gui/gui_style.cc	(revision 267)
+++ /trunk/src/gui/gui_style.cc	(revision 268)
@@ -67,6 +67,6 @@
 {
 	const char* centry = entry.c_str();
-	const char* cid    = e->get_id().c_str();
-	const char* cclass = e->get_class().c_str();
+	const char* cid    = e->m_id.c_str();
+	const char* cclass = e->m_class.c_str();
 	lua_getglobal( m_lua, "default" );
 	int global = lua_gettop( m_lua );
Index: /trunk/tests/gui_test/nv_gui_test.cc
===================================================================
--- /trunk/tests/gui_test/nv_gui_test.cc	(revision 267)
+++ /trunk/tests/gui_test/nv_gui_test.cc	(revision 268)
@@ -87,6 +87,6 @@
 	glm::ivec2 b( std::rand() % 200 + 40, std::rand() % 200 + 40 );
 	nv::gui::element* e = m_guienv->create_element( nullptr, nv::rectangle(a).dim(b) );
-	e->set_class( "window" );
-	e->set_text("Window "+nv::to_string(m_windows.size()+1) );
+	m_guienv->set_class( e, "window" );
+	m_guienv->set_text( e, "Window "+nv::to_string(m_windows.size()+1) );
 	NV_LOG( nv::LOG_INFO, "Spawn (" << a.x << "," << a.y << "x" << b.x << "," << b.y << ")" );
 	m_windows.push_back( e );
