mail[Wesnoth-commits] r33673 - in /trunk/src/gui/widgets: control.cpp control.hpp label.hpp widget.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by koraq on March 15, 2009 - 13:52:
Author: mordante
Date: Sun Mar 15 13:52:08 2009
New Revision: 33673

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33673&view=rev
Log:
Add the initial code for shrinking widgets.

Modified:
    trunk/src/gui/widgets/control.cpp
    trunk/src/gui/widgets/control.hpp
    trunk/src/gui/widgets/label.hpp
    trunk/src/gui/widgets/widget.hpp

Modified: trunk/src/gui/widgets/control.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.cpp?rev=33673&r1=33672&r2=33673&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.cpp (original)
+++ trunk/src/gui/widgets/control.cpp Sun Mar 15 13:52:08 2009
@@ -163,6 +163,23 @@
                                << ".\n";
 
        }
+}
+
+void tcontrol::layout_shrink_width(const unsigned maximum_width)
+{
+       DBG_G_L << "tcontrol(" + get_control_type() + ") " + __func__ + ":"
+                       << " maximum_width " << maximum_width
+                       << ".\n";
+
+       /** @todo handle the tooltip properly. */
+
+       std::cerr << "Shrink from : " << get_best_size().x 
+               << " to " << maximum_width << ".\n";
+
+       shrunken_ = true;
+       set_layout_size(tpoint(maximum_width, get_best_size().y));
+
+       assert(static_cast<unsigned>(get_best_size().x) == maximum_width);
 }
 
 tpoint tcontrol::calculate_best_size() const

Modified: trunk/src/gui/widgets/control.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.hpp?rev=33673&r1=33672&r2=33673&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.hpp (original)
+++ trunk/src/gui/widgets/control.hpp Sun Mar 15 13:52:08 2009
@@ -156,6 +156,9 @@
        /** Inherited from twidget. */
        void layout_wrap(const unsigned maximum_width);
 
+       /** Inherited from twidget. */
+       void layout_shrink_width(const unsigned maximum_width);
+
 protected:
        /** Inherited from twidget. */
        tpoint calculate_best_size() const;

Modified: trunk/src/gui/widgets/label.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/label.hpp?rev=33673&r1=33672&r2=33673&view=diff
==============================================================================
--- trunk/src/gui/widgets/label.hpp (original)
+++ trunk/src/gui/widgets/label.hpp Sun Mar 15 13:52:08 2009
@@ -33,6 +33,9 @@
 
        /** Inherited from twidget. */
        bool can_wrap() const { return can_wrap_; }
+
+       /** Inherited from twidget. */
+       bool can_shrink_width() const { return true; }
 
        /** Inherited from tcontrol. */
        void set_active(const bool active)

Modified: trunk/src/gui/widgets/widget.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/widget.hpp?rev=33673&r1=33672&r2=33673&view=diff
==============================================================================
--- trunk/src/gui/widgets/widget.hpp (original)
+++ trunk/src/gui/widgets/widget.hpp Sun Mar 15 13:52:08 2009
@@ -225,14 +225,22 @@
        virtual void layout_use_horizontal_scrollbar(const unsigned 
/*maximum_width*/)
                { assert(has_horizontal_scrollbar()); }
 
-       /**
-        * Tries to shrink a widget so it fits in the wanted width.
-        *
-        * @todo implement this function properly.
+       /** Can the widget reduce its width. */
+       virtual bool can_shrink_width() const { return false; }
+
+       /**
+        * Shrinks the contents of the widget so it can fit the wanted width
+        *
+        * @todo implement this function properly at the moment it kind of 
works
+        * for a label but should also work for a button and maybe some other
+        * classes.
         *
         * @param maximum_width       The wanted maximum width of the widget.
-        */
-       virtual void layout_shrink_width(const unsigned /*maximum_width*/) { }
+        *
+        * @pre                       can_shrink_width() == true.
+        */
+       virtual void layout_shrink_width(const unsigned /*maximum_width*/)
+               { assert(can_shrink_width()); }
 
        /**
         * Does the widget have a vertical scrollbar.




Related Messages


Powered by MHonArc, Updated Sun Mar 15 14:00:18 2009