o
    �õ±j”  ã                   @  sš   d Z ddlmZ ddlmZ ddlmZ g d¢Zer ddlmZ G dd„ dƒZ	ddd„Z
ddd„ZdeB e	B eg df B Zddd„Zddd„Ze	Ze	ZdS )zo
Layout dimensions are used to give the minimum, maximum and preferred
dimensions for containers and controls.
é    )Úannotations)ÚCallable)ÚTYPE_CHECKING)Ú	DimensionÚDÚsum_layout_dimensionsÚmax_layout_dimensionsÚAnyDimensionÚto_dimensionÚis_dimension)Ú	TypeGuardc                   @  sJ   e Zd ZdZ				ddd
d„Zeddd„ƒZeddd„ƒZddd„ZdS )r   aÞ  
    Specified dimension (width/height) of a user control or window.

    The layout engine tries to honor the preferred size. If that is not
    possible, because the terminal is larger or smaller, it tries to keep in
    between min and max.

    :param min: Minimum size.
    :param max: Maximum size.
    :param weight: For a VSplit/HSplit, the actual size will be determined
                   by taking the proportion of weights from all the children.
                   E.g. When there are two children, one with a weight of 1,
                   and the other with a weight of 2, the second will always be
                   twice as big as the first, if the min/max values allow it.
    :param preferred: Preferred size.
    NÚminú
int | NoneÚmaxÚweightÚ	preferredÚreturnÚNonec                 C  s   |d ur
|dks
J ‚|d u s|dksJ ‚|d u s|dksJ ‚|d u s(|dks(J ‚|d u| _ |d u| _|d u| _|d u| _|d u rBd}|d u rHd}|d u rN|}|d u rTd}|| _|| _|| _|| _||k rhtdƒ‚| j| jk rr| j| _| j| jkr~| j| _d S d S )Nr   l       ©7§3M“e'é   zInvalid Dimension: max < min.)	Úmin_specifiedÚmax_specifiedÚpreferred_specifiedÚweight_specifiedr   r   r   r   Ú
ValueError)Úselfr   r   r   r   © r   ú’/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/prompt_toolkit/layout/dimension.pyÚ__init__+   s8   



ÿzDimension.__init__ÚamountÚintc                 C  s   | |||d�S )zv
        Return a :class:`.Dimension` with an exact size. (min, max and
        preferred set to ``amount``).
        ©r   r   r   r   )Úclsr   r   r   r   ÚexactW   s   zDimension.exactc                 C  s   | j dd�S )zj
        Create a dimension that represents a zero size. (Used for 'invisible'
        controls.)
        r   )r   )r"   )r!   r   r   r   Úzero_   s   zDimension.zeroÚstrc                 C  st   g }| j r| d| j›�¡ | jr| d| j›�¡ | jr&| d| j›�¡ | jr2| d| j›�¡ d 	d 
|¡¡S )Nzmin=zmax=z
preferred=zweight=zDimension({})z, )r   Úappendr   r   r   r   r   r   r   ÚformatÚjoin)r   Úfieldsr   r   r   Ú__repr__g   s   zDimension.__repr__)NNNN)
r   r   r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   )r   r$   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr"   r#   r)   r   r   r   r   r      s    û,r   Ú
dimensionsúlist[Dimension]r   c                 C  sD   t dd„ | D ƒƒ}t dd„ | D ƒƒ}t dd„ | D ƒƒ}t|||d�S )z6
    Sum a list of :class:`.Dimension` instances.
    c                 s  ó   � | ]}|j V  qd S ©N©r   ©Ú.0Údr   r   r   Ú	<genexpr>y   ó   € z(sum_layout_dimensions.<locals>.<genexpr>c                 s  r1   r2   ©r   r4   r   r   r   r7   z   r8   c                 s  r1   r2   ©r   r4   r   r   r   r7   {   r8   r    )Úsumr   )r/   r   r   r   r   r   r   r   u   s   r   c                 C  sª   t | ƒst ¡ S tdd„ | D ƒƒrt ¡ S dd„ | D ƒ} | rRtdd„ | D ƒƒ}tdd„ | D ƒƒ}t|tdd„ | D ƒƒƒ}||krB|}tdd„ | D ƒƒ}t|||d	�S tƒ S )
z˜
    Take the maximum of a list of :class:`.Dimension` instances.
    Used when we have a HSplit/VSplit, and we want to get the best width/height.)
    c                 s  s$   � | ]}|j d ko|jd kV  qdS )r   N©r   r   r4   r   r   r   r7   ‹   s   €" z(max_layout_dimensions.<locals>.<genexpr>c                 S  s$   g | ]}|j d kr|jd kr|‘qS )r   r<   r4   r   r   r   Ú
<listcomp>�   s   $ z)max_layout_dimensions.<locals>.<listcomp>c                 s  r1   r2   r3   r4   r   r   r   r7   “   r8   c                 s  r1   r2   r9   r4   r   r   r   r7   œ   r8   c                 s  r1   r2   r:   r4   r   r   r   r7   �   r8   c                 s  r1   r2   r:   r4   r   r   r   r7   ¦   r8   r    )Úlenr   r#   Úallr   r   )r/   Úmin_Úmax_r   r   r   r   r   €   s   	r   Nr	   Úvaluec                 C  sJ   | du rt ƒ S t| tƒrt  | ¡S t| t ƒr| S t| ƒr!t| ƒ ƒS tdƒ‚)z:
    Turn the given object into a `Dimension` object.
    Nz#Not an integer or Dimension object.)r   Ú
isinstancer   r"   Úcallabler
   r   ©rB   r   r   r   r
   ±   s   



r
   ÚobjectúTypeGuard[AnyDimension]c                 C  s.   | du rdS t | ƒrdS t| ttfƒrdS dS )zŽ
    Test whether the given value could be a valid dimension.
    (For usage in an assertion. It's not guaranteed in case of a callable.)
    NTF)rD   rC   r   r   rE   r   r   r   r   Á   s   r   )r/   r0   r   r   )rB   r	   r   r   )rB   rF   r   rG   )r-   Ú
__future__r   Úcollections.abcr   Útypingr   Ú__all__r   r   r   r   r   r	   r
   r   r   ÚLayoutDimensionr   r   r   r   Ú<module>   s    

\
.

