
    AHj                    V    d dl mZ d dlmZ d dlmZmZ d dlmZ  G d de      Z	d	dZ
y)
    )annotations)Fraction)Sequencecast)Protocolc                  0    e Zd ZU dZded<   ded<   ded<   y)EdgeProtocolz1Any object that defines an edge (such as Layout).z
int | Nonesizeintfractionmin_sizeN)__name__
__module____qualname____doc____annotations__     O/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/_layout_resolve.pyr	   r	   	   s    ; MMr   r	   c                t   |D cg c]  }|j                   xs d }}d|vrt        d|      S t        t        ||            D cg c]  \  }\  }}|||f }}}}| t	        |D cg c]  }|xs d
 c}      z
  }|dk  r1t        ||      D cg c]  \  }}||j
                  xs dn| c}}S t	        |D cg c]  \  }}|j                  xs d c}}      }	|rt        ||	      }
t        |      D ]Z  \  }\  }}|
|j                  z  |j
                  k  s&|j
                  ||<   ||j
                  z  }|	|j                  xs dz  }	||=  n9 t        d      }|D ]'  \  }}t        |
|j                  z  |z   d      \  ||<   }) n|rt        d|      S c c}w c c}}}w c c}w c c}}w c c}}w )am  Divide total space to satisfy size, fraction, and min_size, constraints.

    The returned list of integers should add up to total in most cases, unless it is
    impossible to satisfy all the constraints. For instance, if there are two edges
    with a minimum size of 20 each and `total` is 30 then the returned list will be
    greater than total. In practice, this would mean that a Layout object would
    clip the rows that would overflow the screen height.

    Args:
        total: Total number of characters.
        edges: Edges within total space.

    Returns:
        Number of characters for each edge.
    N	list[int]r      )	r
   r   	enumeratezipsumr   r   r   divmod)totaledgesedgesizesindexr
   flexible_edges	remaining_total_flexibleportionflexible_index	remainders                r   layout_resolver)      s   " .33Tdii43E35K''
 $-S->#? E<D$< 
N  594TYQY9::IA~ "%/
d &*\dmm qt;
 	
 nM71d4==-A-MNN
9n5 .7~-F 	)NMUD&6  $}}eT]]*	$--"414">2	 !I- Yt*04==1H91TVW*X'eiY- 2 U##a 4 :
 Ns   FF"(F)
F.>F4
N)r   r   r   zSequence[EdgeProtocol]returnr   )
__future__r   	fractionsr   typingr   r   typing_extensionsr   r	   r)   r   r   r   <module>r/      s#    "  ! &8 A$r   