/*************************************************************************** * Copyright (C) 2004 by Christoph Freundl * * Christoph.Freundl@informatik.uni-erlangen.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef SDLWIDGETS_LAYOUT_H #define SDLWIDGETS_LAYOUT_H #include #include #include namespace SDLwidgets { class Widget; class WidgetComposite; enum WidgetStretch { RIGID, FILL }; class LayoutManager { protected: WidgetComposite* _managed_widget; public: LayoutManager( WidgetComposite* widget ) : _managed_widget( widget ) { } virtual ~LayoutManager() { } virtual void add( Widget* widget ) = 0; virtual void remove( Widget* widget ) = 0; virtual int getWidth() const = 0; virtual int getHeight() const = 0; virtual void arrangeAll() = 0; virtual void arrangeToWidth( const Uint16 width ) { arrangeAll(); } }; class FreeLayout : public LayoutManager { private: std::vector _contained_widgets; Uint16 _width, _height; public: FreeLayout( WidgetComposite* widget ) : LayoutManager( widget ), _width( 0 ), _height( 0 ) { } virtual ~FreeLayout() { } virtual void add( Widget* widget ); virtual void remove( Widget* widget ); virtual int getWidth() const { return _width; } virtual int getHeight() const { return _height; } virtual void arrangeAll() { } private: void computeExtent(); }; class VerticalLayout : public LayoutManager { private: std::vector _contained_widgets; Uint16 _width, _height; Uint16 _border_spacing; Uint16 _spacing; std::map _widget_stretch; public: VerticalLayout( WidgetComposite* widget ) : LayoutManager( widget ), _border_spacing( 0 ), _spacing( 1 ) { } virtual void add( Widget* widget ); virtual void remove( Widget* widget ); void setBorderSpacing( Uint16 spacing ) { _border_spacing = spacing; arrangeAll(); } void setSpacing( Uint16 spacing ) { _spacing = spacing; arrangeAll(); } void setStretch( Widget* widget, WidgetStretch stretch ) { // if ( _contained_widgets.find( widget ) != _contained_widgets.end() ) _widget_stretch[widget] = stretch; } virtual int getWidth() const { return _width; } virtual int getHeight() const { return _height; } virtual void arrangeAll(); }; class HorizontalLayout : public LayoutManager { private: std::vector _contained_widgets; Uint16 _width, _height; Uint16 _spacing; std::map _widget_stretch; public: HorizontalLayout( WidgetComposite* widget ) : LayoutManager( widget ), _spacing( 1 ) { } virtual void add( Widget* widget ); virtual void remove( Widget* widget ); void setSpacing( Uint16 spacing ) { _spacing = spacing; arrangeAll(); } void setStretch( Widget* widget, WidgetStretch stretch ) { // if ( _contained_widgets.find( widget ) != _contained_widgets.end() ) _widget_stretch[widget] = stretch; } virtual int getWidth() const { return _width; } virtual int getHeight() const { return _height; } virtual void arrangeAll(); virtual void arrangeToWidth( const Uint16 width ); }; class TableLayout : public LayoutManager { private: std::vector _contained_widgets; std::vector _column_widths; std::vector _row_heights; std::vector _column_stretch; Uint16 _width, _height; Uint16 _number_columns; Uint16 _horizontal_spacing, _vertical_spacing; public: TableLayout( WidgetComposite* widget, Uint16 number_columns ) : LayoutManager( widget ), _column_widths( number_columns ), _column_stretch( number_columns, RIGID ), _number_columns( number_columns ), _horizontal_spacing( 1 ), _vertical_spacing( 1 ) { } virtual void add( Widget* widget ); virtual void remove( Widget* widget ); void setHorizontalSpacing( Uint16 spacing ) { _horizontal_spacing = spacing; arrangeAll(); } void setVerticalSpacing( Uint16 spacing ) { _vertical_spacing = spacing; arrangeAll(); } void setColumnStretch( int column, WidgetStretch stretch ) { _column_stretch[column] = stretch; } virtual int getWidth() const { return _width; } virtual int getHeight() const { return _height; } virtual void arrangeAll(); }; } #endif // SDLWIDGETS_LAYOUT_H