
    AHj                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZmZmZ erd dlmZ d dlmZ  G d	 d
e      Zy)    )annotations)Fraction)TYPE_CHECKING)resolve_box_models)NULL_OFFSETRegionSize)ArrangeResultLayoutWidgetPlacement)Spacing)Widgetc                  2    e Zd ZdZdZ	 d	 	 	 	 	 	 	 	 	 ddZy)HorizontalLayoutzUsed to layout Widgets horizontally on screen, from left to right. Since Widgets naturally
    fill the space of their parent container, all widgets used in a horizontal layout should have a specified.
    
horizontalc                v   |j                  |        g }|j                  }|j                  j                  }|D cg c]  }|j                   }	}|	D 
cg c]  }
|
j
                  dk7  s|
j                    }}
|rt        t        t        ||dd        D cg c]  \  }}t        |d   |d          c}}      |d   j                  |d   j                  z   z   t        |D cg c]  \  }}}}||z    c}}}            }nt        dd      }t        |	D 
cg c]  }
|
j                   c}
||||d|      }t        ||dd        D cg c]:  \  }}t        |j                  j                  |j                  j                  f      < }}}|r(|j                  |d   j                  j                         t        d t        ||      D        t!        d            }t"        }t$        }t        }t        |||      D ]  \  }\  }}}}|j                  }
|
j
                  dk(  }|
j'                  d	      r?|
j(                  j+                   ||j-                         |j-                               |      nt.        } |j0                  }!||z   }" ||j-                         |!|"|j-                         z
  j-                         |j-                               }#|
j'                  d
      xr |
j2                  dk(  }$ | ||#| ||dd||$             |r|$r|"|z   } |S c c}w c c}
w c c}}w c c}}}w c c}
w c c}}w )Nscreen      r   width)resolve_dimensiongreedyc              3     K   | ]?  \  }}|j                   j                  d k7  r!t        |j                  j                         A yw)r   N)stylesoverlayr   marginleft).0	box_modelchilds      R/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/layouts/horizontal.py	<genexpr>z+HorizontalLayout.arrange.<locals>.<genexpr>G   s?      $Iu<<''83 ))../s   AAoffsetpositionabsoluteF)
pre_layoutappendappviewport_sizer   r   r   r	   sumzipmaxr   rightr   r   nextr   r   r   has_ruler$   resolve	__floor__r   topr%   )%selfparentchildrensizer   
placementsadd_placementviewportr!   child_stylesr   box_marginsmargin1margin2
margin_top_margin_bottomresolve_margin
box_modelsbox1box2marginsx_Region_WidgetPlacement_Sizewidgetcontent_widthcontent_height
box_marginr   r   r$   offset_ynext_xregionr&   s%                                        r"   arrangezHorizontalLayout.arrange   sX    	$,.
"))::++2:;;;(4&
$(8RFMM&
 &
 ! 14KQR0Q,GW GAJ
3 q>&&R)>)>>@  @K ;J=! #]2N  "!QZN'(45fV\\5%

 "*jn=
d ""DKK$4$456
 
 NN:b>00667(+J(A
 QK
 *KNj'L
 $	$GF?]NJ ]]Fnn0G ??8,	 %%-113^5M5M5OP
 !  "~~H&F!++-'224((*	F z2Tv*7TH 	 8VOI$	$L u <&
 6
s)   LL(LL#$L)L0?L5N)T)
r5   r   r6   zlist[Widget]r7   r	   r   boolreturnr
   )__name__
__module____qualname____doc__namerR        r"   r   r      sH     D RVbb(4b<@bJNb	br[   r   N)
__future__r   	fractionsr   typingr   textual._resolver   textual.geometryr   r   r	   textual.layoutr
   r   r   r   textual.widgetr   r   rZ   r[   r"   <module>rc      s4    "    / 6 6 A A(%iv ir[   