Add Layout, FixedLayout.
authorRadek Brich <radek.brich@devl.cz>
Thu, 27 Mar 2014 08:03:51 +0100
changeset 93 c1e79acb9fcb
parent 92 b97c4e25ed6d
child 94 e50dae408fe9
Add Layout, FixedLayout.
tuikit/core/container.py
tuikit/core/widget.py
tuikit/core/window.py
tuikit/layouts/__init__.py
tuikit/layouts/fixed.py
tuikit/layouts/layout.py
--- a/tuikit/core/container.py	Wed Mar 26 21:26:39 2014 +0100
+++ b/tuikit/core/container.py	Thu Mar 27 08:03:51 2014 +0100
@@ -1,4 +1,5 @@
 from tuikit.core.widget import Widget
+from tuikit.layouts.fixed import FixedLayout
 
 
 class Container(Widget):
@@ -9,10 +10,11 @@
 
     """
 
-    def __init__(self):
+    def __init__(self, layout_class=FixedLayout):
         Widget.__init__(self)
         #: List of child widgets.
         self.children = []
+        self.layout = layout_class()
 
     def add(self, widget):
         """Add widget into container."""
@@ -20,6 +22,11 @@
         widget.parent = self
         widget.window = self.window
         widget.set_theme(self.theme)
+        self.layout.add(widget)
+
+    def resize(self, w, h):
+        Widget.resize(self, w, h)
+        self.layout.resize()
 
     def draw(self, buffer, x=0, y=0):
         """Draw child widgets."""
--- a/tuikit/core/widget.py	Wed Mar 26 21:26:39 2014 +0100
+++ b/tuikit/core/widget.py	Thu Mar 27 08:03:51 2014 +0100
@@ -25,7 +25,7 @@
         #: Position inside parent widget. Modified by layout manager.
         self.pos = Point()
         #: Actual size. Modified by layout manager.
-        self.size = Size(10, 10)
+        self._size = Size(10, 10)
 
         #: Requested size. Layout manager will use this when placing the widget.
         self.sizereq = Size(1, 1)
@@ -53,6 +53,13 @@
     def height(self):
         return self.size.h
 
+    @property
+    def size(self):
+        return self._size.readonly()
+
+    def resize(self, w, h):
+        self._size.update(w, h)
+
     ## appearance ##
 
     def draw(self, buffer, x, y):
--- a/tuikit/core/window.py	Wed Mar 26 21:26:39 2014 +0100
+++ b/tuikit/core/window.py	Thu Mar 27 08:03:51 2014 +0100
@@ -26,10 +26,14 @@
     def buffer(self, buffer):
         # replace the buffer
         self._buffer = buffer
-        self.size = buffer.size
+
+    @property
+    def size(self):
+        return self.buffer.size
 
     def resize(self, w, h):
         """Resize buffer when window gets resized."""
+        Container.resize(self, w, h)
         self.buffer.resize(w, h)
         self.redraw()
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tuikit/layouts/fixed.py	Thu Mar 27 08:03:51 2014 +0100
@@ -0,0 +1,8 @@
+from .layout import Layout
+
+
+class FixedLayout(Layout):
+
+    def resize(self):
+        for widget in self._managed_widgets:
+            widget.resize(*widget.sizereq)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tuikit/layouts/layout.py	Thu Mar 27 08:03:51 2014 +0100
@@ -0,0 +1,12 @@
+class Layout:
+
+    def __init__(self):
+        self._managed_widgets = []
+
+    def add(self, widget):
+        self._managed_widgets.append(widget)
+
+    def resize(self):
+        pass
+
+