
    AHj                    j    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  G d de
      Zy)	    )annotations)TYPE_CHECKING)NULL_OFFSETRegionSize)ArrangeResultLayoutWidgetPlacement)Widgetc                  V    e Zd ZdZdZ	 d	 	 	 	 	 	 	 	 	 ddZd	dZ	 	 	 	 	 	 	 	 	 	 d
dZy)StreamLayouta  A cut down version of the vertical layout.

    The stream layout is faster, but has a few limitations compared to the vertical layout.

    - All widgets are the full width (as if their widget is `1fr`).
    - All widgets have an effective height of `auto`.
    - `max-height` is supported, but only if it is a units value, all other extrema rules are ignored.
    - No absolute positioning.
    - No overlay: screen.
    - Layers are ignored.
    - Non TCSS styles are ignored.

    The primary use of `layout: stream` is for a long list of widgets in a scrolling container, such as
    what you might expect from a LLM chat-bot. The speed improvement will only be significant with a lot of
    child widgets, so stick to vertical layouts unless you see any slowdown.

    streamc                   |j                  |        |sg S |j                  j                  }t        }t        }g }|j
                  }	|d   j                  }
d}|
j                  j                  }t        }|D ]  }|j                  j                  }|j                  }|j                  j                  \  }}|\  }}}}|||kD  r|n|z  }|}|j                  |||	|z
        |z   }|j                  x}*|j                  r|t!        |j"                        x}k  r|n|}|j$                  x}*|j                  r|t!        |j"                        x}kD  r|n|}|j'                   | ||||	||z   z
  |      |||dddd             ||z  } |S )Nr   F)
pre_layoutappviewport_sizer   r
   widthstylesmargintopr   _base_stylesguttertotalsget_content_height
max_heightis_cellsintvalue
min_heightappend)selfparentchildrensizegreedyviewport_Region_WidgetPlacement
placementsr   first_child_stylesyprevious_marginnull_offsetwidgetr   r   gutter_widthgutter_heightr   rightbottomleftheightr   max_height_valuer   min_height_values                               N/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/layouts/stream.pyarrangezStreamLayout.arrange!   s    	$I::++*,.


%a[//,3377! #	F]]//F]]F*0--*>*>'L-'-$Co-?BA$O))$%,:NO   %///
<ATAT S9I9I5J!J!1K ) 
 %///
<ATAT S9I9I5J!J!1K ) 
  D!UdUl%;VD	 KAG#	J     c                .    |j                   j                  S )zGet the optimal content width by arranging children.

        Args:
            widget: The container widget.
            container: The container size.
            viewport: The viewport size.

        Returns:
            Width of the content.
        )scrollable_content_regionr   )r!   r.   	containerr&   s       r7   get_content_widthzStreamLayout.get_content_widthZ   s     //555r9   c                    |j                   r3|j                  t        |d            }|j                  j                  }|S d}|S )a  Get the content height.

        Args:
            widget: The container widget.
            container: The container size.
            viewport: The viewport.
            width: The content width.

        Returns:
            Content height (in lines).
        r   )_nodesr8   r   total_regionr4   )r!   r.   r<   r&   r   arrangementr4   s          r7   r   zStreamLayout.get_content_heightg   sC     == ..eQ8K --44F  Fr9   N)T)
r"   r   r#   zlist[Widget]r$   r   r%   boolreturnr   )r.   r   r<   r   r&   r   rC   r   )
r.   r   r<   r   r&   r   r   r   rC   r   )__name__
__module____qualname____doc__namer8   r=   r    r9   r7   r   r      su    $ D RV77(47<@7JN7	7r6)-9=FI	r9   r   N)
__future__r   typingr   textual.geometryr   r   r   textual.layoutr   r	   r
   textual.widgetr   r   rI   r9   r7   <module>rO      s+    "   6 6 A A%n6 nr9   