
    AHjD                    n    d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZ  G d d	e      Zy
)zO
`ScrollView` is a base class for [Line API](/guide/widgets#line-api) widgets.
    )annotations)RenderableType)EasingFunction)AnimationLevelCallbackType)ScrollableContainer)RegionSizec            
          e Zd ZdZdZdZedd       ZddZddZ	d Z
ddZdd	Z	 d	 	 	 	 	 	 	 	 	 dd
ZddZ	 	 dddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZdddZy)
ScrollViewz
    A base class for a Widget that handles its own scrolling (i.e. doesn't rely
    on the compositor to render children).
    TzP
    ScrollView {
        overflow-y: auto;
        overflow-x: auto;
    }
    c                     y)zAlways scrollable.T selfs    K/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/scroll_view.pyis_scrollablezScrollView.is_scrollable   s         c                    | j                   r|| j                  _        t        |      t        |      k7  r&| j	                  | j
                  j                         y y N)show_horizontal_scrollbarhorizontal_scrollbarpositionroundrefreshsizeregionr   	old_value	new_values      r   watch_scroll_xzScrollView.watch_scroll_x#   sF    ))1:D%%.uY//LL))* 0r   c                    | j                   r|| j                  _        t        |      t        |      k7  r&| j	                  | j
                  j                         y y r   )show_vertical_scrollbarvertical_scrollbarr   r   r   r   r   r   s      r   watch_scroll_yzScrollView.watch_scroll_y)   sF    ''/8D##,uY//LL))* 0r   c                $    | j                          y r   )_refresh_scrollbarsr   s    r   on_mountzScrollView.on_mount/   s      "r   c                .    | j                   j                  S )zGets the width of the content area.

        Args:
            container: Size of the container (immediate parent) widget.
            viewport: Size of the viewport.

        Returns:
            The optimal width of the content.
        )virtual_sizewidth)r   	containerviewports      r   get_content_widthzScrollView.get_content_width2   s       &&&r   c                .    | j                   j                  S )a#  Gets the height (number of lines) in the content area.

        Args:
            container: Size of the container (immediate parent) widget.
            viewport: Size of the viewport.
            width: Width of renderable.

        Returns:
            The height of the content.
        )r)   height)r   r+   r,   r*   s       r   get_content_heightzScrollView.get_content_height>   s       '''r   c                v   | j                   |k7  x}r| j                          |s|| j                  k7  s|| j                  k7  rf| j                  j                          || _         | j                  }|| j                  j                  j                  z
  | _	        | j                  |       |xs | j                  |k7  S )a2  Called when size is updated.

        Args:
            size: New size.
            virtual_size: New virtual size.
            container_size: New container size.
            layout: Perform layout if required.

        Returns:
            True if a resize event should be sent, otherwise False.
        )_size
_set_dirtyr)   container_size_scrollbar_changesclearstylesguttertotals_container_size_scroll_update)r   r   r)   r4   layoutsize_changeds         r   _size_updatedzScrollView._size_updatedK   s      ::--<-OOt000!4!44##))+DJ,,L#'$++*<*<*C*C#CD -Et33~EEr   c                P    ddl m}  || j                   d| j                         S )z~Render the scrollable region (if `render_lines` is not implemented).

        Returns:
            Renderable object.
        r   )Panel )
rich.panelr@   scroll_offsetr"   )r   r@   s     r   renderzScrollView.renderh   s+     	%**+1T-I-I,JKLLr   NFbasic)animatespeeddurationeasingforceon_completelevel	immediatec               8    | j                  |||||||||		       y)a  Scroll to a given (absolute) coordinate, optionally animating.

        Args:
            x: X coordinate (column) to scroll to, or `None` for no change.
            y: Y coordinate (row) to scroll to, or `None` for no change.
            animate: Animate to new scroll position.
            speed: Speed of scroll if `animate` is `True`; or `None` to use `duration`.
            duration: Duration of animation, if `animate` is `True` and `speed` is `None`.
            easing: An easing method for the scrolling animation.
            force: Force scrolling even when prohibited by overflow styling.
            on_complete: A callable to invoke when the animation is finished.
            level: Minimum level required for the animation to take place (inclusive).
            immediate: If `False` the scroll will be deferred until after a screen refresh,
                set to `True` to scroll immediately.
        )rF   rG   rH   rI   rJ   rK   rL   N)
_scroll_to)r   xyrF   rG   rH   rI   rJ   rK   rL   rM   s              r   	scroll_tozScrollView.scroll_tos   s0    < 	# 	 
	
r   c           
         | j                  t        d|| j                  j                  z
  t	        | j
                  j                  | j                  j                        d             y)zQRefresh a single line.

        Args:
            y: Coordinate of line.
        r      N)r   r	   rC   rQ   maxr)   r*   r   )r   rQ   s     r   refresh_linezScrollView.refresh_line   sP     	D&&(((D%%++TYY__=		
r   c                    t        d|| j                  j                  z
  t        | j                  j
                  | j                  j
                        |      }| j                  |       y)zRefresh one or more lines.

        Args:
            y_start: First line to refresh.
            line_count: Total number of lines to refresh.
        r   N)r	   rC   rQ   rU   r)   r*   r   r   )r   y_start
line_countrefresh_regions       r   refresh_lineszScrollView.refresh_lines   sT      d((***!!''9	
 	^$r   )returnbool)r   floatr   r^   r\   None)r+   r
   r,   r
   r\   int)r+   r
   r,   r
   r*   r`   r\   r`   )T)
r   r
   r)   r
   r4   r
   r<   r]   r\   r]   )r\   r   )NN)rP   float | NonerQ   ra   rF   r]   rG   ra   rH   ra   rI   zEasingFunction | str | NonerJ   r]   rK   zCallbackType | NonerL   r   rM   r]   r\   r_   )rQ   r`   r\   r_   )rT   )rX   r`   rY   r`   r\   r_   )__name__
__module____qualname____doc__ALLOW_MAXIMIZEDEFAULT_CSSpropertyr   r    r$   r'   r-   r0   r>   rD   rR   rV   r[   r   r   r   r   r      s%   
 NK  ++#
'( TXFF(,F>BFLPF	F:M (

 "!%.2+/ '(
(
 (

 (
 (
 (
 ,(
 (
 )(
 (
 (
 
(
T
%r   r   N)re   
__future__r   rich.consoler   textual._animatorr   textual._typesr   r   textual.containersr   textual.geometryr	   r
   r   r   r   r   <module>ro      s-    # ' , 7 2 )j%$ j%r   