title: How do I force a FloatLayout to keep the same dimensions as the image inside it when window size changes using Kivy?
body: <p>I have an image of a chessboard added to a FloatLayout. The chessboard resizes just fine, but the layout always shows beyond the borders of the chessboard image. The background of the FloatLayout is green so I can see it.</p>
  <p>The app opens with window maximized &amp; no matter how I adjust the layout with size_hint when I restore the window to default size (not maximized) some part of the layout is showing.</p>
  <p>Is there a way to make the layout always be the same size as the image inside it when it auto-resizes when the window is resized manually with the mouse or by the maximize button?</p>
  <p>Here is my code:</p>
  <pre><code>from kivy.config import Config
  
  Config.set('graphics', 'resizable', True)
  Config.set('graphics', 'window_state', 'maximized')
  Config.write()
  
  import kivy
  from kivy.app import App
  from kivy.uix.image import Image
  from kivy.uix.behaviors import DragBehavior
  from kivy.uix.floatlayout import FloatLayout
  from kivy.graphics import Color, Rectangle
  
  kivy.require('2.0.0')
  
  class DraggableArea(FloatLayout):  # FloatLayout
      def __init__(self, **kwargs):
          super(DraggableArea, self).__init__(**kwargs)
          self.size_hint = (.547, .89)
          self.layout_size_not_retrieved = True
          self.initial_updated_layout_size = None
  
          with self.canvas.before:
              Color(0, 1, 0, 1) 
              self.rect = Rectangle(size=(200, 200),
                                    pos=(300, 200))
          def update_rect(instance, value):
              instance.rect.pos = instance.pos
              instance.rect.size = instance.size
              if self.layout_size_not_retrieved:
                  if self.rect.size[0] &gt; 100:
                      self.initial_updated_layout_size = self.rect.size
                      self.add_widget(
                          Image(source=&quot;./data/images/chess-pieces/DarkerGreenGreyChessBoard.png&quot;, pos=self.rect.pos,
                                size_hint=(1, 1), keep_ratio=True, allow_stretch=True))
                      self.add_widget(
                          MoveableImage(source=&quot;./data/images/chess-pieces/WhiteQueen57.png&quot;,
                                        pos=self.rect.pos))
                      self.layout_size_not_retrieved = False
  
          self.bind(pos=update_rect, size=update_rect)
  
  
  class MoveableImage(DragBehavior, Image):
  
      def __init__(self, **kwargs):
          super(MoveableImage, self).__init__(**kwargs)
          self.drag_timeout = 10000000
          self.drag_distance = 0
          self.drag_rectangle = [self.x, self.y, self.width, self.height]
          self.size_hint = (.1, .1) 
          self.keep_ratio = True
          self.allow_stretch = True  
  
      def on_pos(self, *args):
          self.drag_rectangle = [self.x, self.y, self.width, self.height]
  
      def on_size(self, *args):
          self.drag_rectangle = [self.x, self.y, self.width, self.height]
  
  
  class egGameApp(App):
      def build(self):
          c = DraggableArea()
          c.pos = (40, 40)
  
          return c
  
  
  if __name__ == '__main__':
      egGameApp().run()       
  </code></pre>