U
    Pe"                     @   s6   d Z ddlmZ ddlmZ dZG dd deeZdS )a  
RecycleBoxLayout
================

.. versionadded:: 1.10.0

.. warning::
    This module is highly experimental, its API may change in the future and
    the documentation is not complete at this time.

The RecycleBoxLayout is designed to provide a
:class:`~kivy.uix.boxlayout.BoxLayout` type layout when used with the
:class:`~kivy.uix.recycleview.RecycleView` widget. Please refer to the
:mod:`~kivy.uix.recycleview` module documentation for more information.

    )RecycleLayout)	BoxLayout)RecycleBoxLayoutc                       sD   e Zd ZdZ fddZdd Z fddZdd	 Zd
d Z  Z	S )r   Nc                    s$   t t| jf | | d| j d S )Nchildren)superr   __init__ZfunbindZ_trigger_layout)selfkwargs	__class__ =/tmp/pip-unpacked-wheel-xzebddm3/kivy/uix/recycleboxlayout.pyr      s    zRecycleBoxLayout.__init__c           /      C   sp  | j dk}| j\}}}}|| }|| }| j}	| j}
td|	| }td|
| }| j| }| j| }| j}| j}|D ]\}}\}}\}}\}}\}}\}}\}}\}} \}!}"}#}$|r||ks||ks||ks||!ks|s||ks||ks||ks| |"kr dS ||| || }%|r|%d \}&}'|d k	rL|&|| g \}(}|%d< n|'}|%d \})}*|$	 D ]P\}+},|,| }-|+dkr|-| }*n*|+dkr|-| }*n|+dkrd|-|d	  }*qd|)|*g|%d< qt|%d \}&}'|d k	r|| |'g \}}(|%d< n|&}|%d \})}*|$	 D ]P\}+},|,| }.|+d
kr0|.| })n*|+dkrD|.| })n|+dkr|.|d	  })q|)|*g|%d< qtdS )N
horizontalr   TsizeposytopZcenter_y       @xrightZcenter_xF)
orientationpaddingwidthheightmaxr   r   	view_optsremove_viewitems)/r   changedr   Zpadding_leftZpadding_topZpadding_rightZpadding_bottomZ	padding_xZ	padding_yZselfwZselfhZlayout_wZlayout_hZcxcyr   r   indexZwidgetwhZwnZhnshwshhZshnwZshnhZshw_minZshh_minZshwn_minZshhn_minZshw_maxZshh_maxZshwn_maxZshhn_maxphZphnoptwoho_ZxoZyokeyvalueZposyZposxr   r   r   _update_sizes    s    


$    












zRecycleBoxLayout._update_sizesc                    s  t t| || | j}|d ks.|r2| |s2d S |   d | _|sh| j\}}}}|| || f| _d S | j	}t
|}	| dd t|D D ]f\}
}}}}||	|
 d  }|d \}}||f|d< |d \}}|d kr|n||d kr|n|g|d< q| j}d gt
|  }| _| jdkr| j|d< |d | jd  |d d d  |d	  }t|dd  dD ]&\}
}|||
< ||d d | 7 }qbn| j| j | jd  |d d d  |d	   }|d
< t
|}	t|dd  dD ].\}
}|||d d  8 }|||	d |
 < qd S )Nc                 S   s.   g | ]&}|d  |d |d |d |d fqS )r   	size_hintZpos_hintZsize_hint_minZsize_hint_maxr   ).0r&   r   r   r   
<listcomp>r   s
    z3RecycleBoxLayout.compute_layout.<locals>.<listcomp>   r-   r   r   r   r   r   )r   r   compute_layoutZ_changed_viewsr,   Zclear_layout_rv_positionsr   Zminimum_sizer   lenZ_iterate_layoutreversedspacingr   r   	enumerater   r   )r   dataflagsr   ltrbr   nir   r   r!   r"   r&   r#   r$   r'   r(   r6   r   lastvalr
   r   r   r2   `   s`    

 
zRecycleBoxLayout.compute_layoutc                 C   s   | j }|sdS |\}}| jdkrt||d ks8t|dkrDt|d S d}|dd  D ]}||k rh|  S |d7 }qTnV||d kst|dkrdS d}|dd  D ](}||k rt|| d   S |d7 }qdstd S )Nr   r   r1   r0   F)r3   r   r4   AssertionError)r   r   Zcalc_posr   r   ixrA   Ziyr   r   r   get_view_index_at   s(    

z"RecycleBoxLayout.get_view_index_atc           
      C   s~   | j d ks|sg S |\}}}}| j}| jdkrN|||f||| |f }}	n|||| f|||f }}	tt||	d S )Nr   r0   )r3   rD   r   listrange)
r   r8   Zviewportr   r   r!   r"   Zat_idxar=   r   r   r   compute_visible_views   s    
 z&RecycleBoxLayout.compute_visible_views)
__name__
__module____qualname__r3   r   r,   r2   rD   rH   __classcell__r   r   r
   r   r      s   @1r   N)__doc__Zkivy.uix.recyclelayoutr   Zkivy.uix.boxlayoutr   __all__r   r   r   r   r   <module>   s   