U
    Pe+                     @   s@   d Z dZddlmZ ddlmZmZmZmZ G dd deZ	dS )a  
Box Layout
==========

.. only:: html

    .. image:: images/boxlayout.gif
        :align: right

.. only:: latex

    .. image:: images/boxlayout.png
        :align: right

:class:`BoxLayout` arranges children in a vertical or horizontal box.

To position widgets above/below each other, use a vertical BoxLayout::

    layout = BoxLayout(orientation='vertical')
    btn1 = Button(text='Hello')
    btn2 = Button(text='World')
    layout.add_widget(btn1)
    layout.add_widget(btn2)

To position widgets next to each other, use a horizontal BoxLayout. In this
example, we use 10 pixel spacing between children; the first button covers
70% of the horizontal space, the second covers 30%::

    layout = BoxLayout(spacing=10)
    btn1 = Button(text='Hello', size_hint=(.7, 1))
    btn2 = Button(text='World', size_hint=(.3, 1))
    layout.add_widget(btn1)
    layout.add_widget(btn2)

Position hints are partially working, depending on the orientation:

* If the orientation is `vertical`: `x`, `right` and `center_x` will be used.
* If the orientation is `horizontal`: `y`, `top` and `center_y` will be used.

Kv Example::

    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'this on top'
        Label:
            text: 'this right aligned'
            size_hint_x: None
            size: self.texture_size
            pos_hint: {'right': 1}
        Label:
            text: 'this on bottom'

You can check the `examples/widgets/boxlayout_poshint.py` for a live example.

.. note::

    The `size_hint` uses the available space after subtracting all the
    fixed-size widgets. For example, if you have a layout that is 800px
    wide, and add three buttons like this::

        btn1 = Button(text='Hello', size=(200, 100), size_hint=(None, None))
        btn2 = Button(text='Kivy', size_hint=(.5, 1))
        btn3 = Button(text='World', size_hint=(.5, 1))

    The first button will be 200px wide as specified, the second and third
    will be 300px each, e.g. (800-200) * 0.5


.. versionchanged:: 1.4.1
    Added support for `pos_hint`.

)	BoxLayout    )Layout)NumericPropertyOptionPropertyVariableListPropertyReferenceListPropertyc                       s   e Zd ZdZedZeddddgZedddZ	edZ
edZee
eZ fddZdd	 Zd
d Z fddZ fddZ  ZS )r   zEBox layout class. See module documentation for more information.
    r   
horizontal)r   Zvertical)optionsc                    sh   t t| jf | | j}| j}|d| |d| |d| |d| |d| |d| |d| d S )Nspacingpaddingchildrenorientationparentsizepos)superr   __init___trigger_layoutfbind)selfkwargsupdater   	__class__ 6/tmp/pip-unpacked-wheel-xzebddm3/kivy/uix/boxlayout.pyr      s    





zBoxLayout.__init__c           -   	   #   s  t |}| j\}}}}| j}| j}|| }	|| }
d}d}d g| }d}|dkrd}|	||d   }t|D ]\}\\}}\}}}\}}\}}|d kr||7 }n.|||< |rd}||7 }n|d k	rd}||7 }|d krt||}qn|rnt||}qn|| }||
7 }nd}|
||d   }t|D ]\}\\}}\}}}\}}\}}|d krX||7 }n2|||< |rtd}||7 }n|d k	rd}||7 }|d krt||}n|r"t||}q"|| }||	7 }||f| _| j}| j}|dkrtd| j	| }d ntd| j
| }d |r|dk r~d }}t|D ]L\}}|d   } | d krPq.|d	   }!|!d k	rp|!||< nd||< q.n0| ||| fd
d|D  fdd|D | |dkr|| }"| j
|
 }#ttt|t|D ]\}\} \\}}\}}}$}}|| }%| rtd||  | }|r2td||# }|$ D ]X\}&}'|'|# }(|&dkr^|%|(7 }%n2|&dkrv|%|(| 7 }%n|&dkr:|%|(|d  7 }%q:|| d |"|%||fV  |"|| 7 }"qn|| })| j	|	 }*tt||D ]\}\} \\}}\}}}$}}|| }+| rtd||  | }|r0td||* }|$ D ]X\}&}'|'|* },|&dkr\|+|,7 }+n2|&dkrt|+|,| 7 }+n|&dkr8|+|,|d  7 }+q8||+|)||fV  |)|| 7 })qd S )Ng        Fr   r      Tg&.>g      ?   c                 3   s   | ]}|d    V  qdS )r   Nr   ).0valZdimr   r   	<genexpr>   s     z,BoxLayout._iterate_layout.<locals>.<genexpr>c                 3   s   | ]}|d    V  qdS )   Nr   )r   elemr    r   r   r!      s     ytopZcenter_yg       @xrightZcenter_x)lenr   r
   r   	enumeratemaxminimum_sizer&   r$   widthheightZlayout_hint_with_boundszipreverseditems)-r   ZsizesZlen_childrenZpadding_leftZpadding_topZpadding_rightZpadding_bottomr
   r   Z	padding_xZ	padding_yZstretch_sumZ	has_boundhintZminimum_size_boundedZminimum_size_yZminimum_size_noneiwhshwshh_Zshw_minZshh_minZshw_maxZminimum_size_xZshh_maxZselfxZselfyZstretch_spacer   shZsh_minr&   Zsize_ypos_hintcykeyvalueZposyr$   Zsize_xZcxZposxr   r    r   _iterate_layout   s    















   

"




"



zBoxLayout._iterate_layoutc                 G   s   | j }|s.| j\}}}}|| || f| _d S | dd |D D ]\\}}}	}
}|| }||	f|_|j\}}|d kr|d k	r||_qB|d kr|
|_qB|
|f|_qBd S )Nc                 S   s$   g | ]}|j |j|j|j|jfqS r   )r   	size_hintr9   Zsize_hint_minZsize_hint_max)r   cr   r   r   
<listcomp>7  s   z'BoxLayout.do_layout.<locals>.<listcomp>)	r   r   r+   r=   r   r>   r-   r,   r   )r   largsr   ltrbr2   r&   r$   r3   r4   r?   r5   r6   r   r   r   	do_layout/  s&    

zBoxLayout.do_layoutc                    s&   | d| j tt| j|f||S Nr9   )r   r   r   r   
add_widgetr   Zwidgetargsr   r   r   r   rH   E  s    zBoxLayout.add_widgetc                    s&   | d| j tt| j|f||S rG   )Zfunbindr   r   r   remove_widgetrI   r   r   r   rK   I  s    zBoxLayout.remove_widget)__name__
__module____qualname____doc__r   r
   r   r   r   r   Zminimum_widthZminimum_heightr   r+   r   r=   rF   rH   rK   __classcell__r   r   r   r   r   R   s   		
 r   N)
rO   __all__Zkivy.uix.layoutr   Zkivy.propertiesr   r   r   r   r   r   r   r   r   <module>   s   J