Main Content

isInScrollView

Determine if component is visible in scrollable container

    Description

    example

    tf = isInScrollView(container,comp) returns whether components are visible in a scrollable container.

    • If comp is a single UI component, then isInScrollView(container,comp) returns logical 1 (true) if any part of the component is visible given the current size and scroll location of container. Otherwise, it returns logical 0 (false).

    • If comp is a vector of UI components, then isInScrollView(container,comp) returns an array of logical values indicating whether each component in comp is at least partially visible given the current size and scroll location of container.

    Examples

    collapse all

    Create a scrollable figure window, and then create a button and a spinner in it.

    fig = uifigure(Position=[680 558 300 300],Scrollable="on");
    b = uibutton(fig,Position=[100 150 100 22]);
    s = uispinner(fig,Position=[400 150 100 22]);

    UI figure window with a button and a horizontal scroll bar. The scroll bar is scrolled all the way to the left.

    Check if the spinner is visible in the scrollable figure.

    isInScrollView(fig,s)
    ans =
    
      logical
    
       0

    Scroll the figure all the way to the right.

    scroll(fig,"right")

    UI figure window with a spinner and a horizontal scroll bar. The scroll bar is scrolled all the way to the right.

    Check if the spinner is visible after scrolling.

    isInScrollView(fig,s)
    ans =
    
      logical
    
       1

    Create a scrollable grid layout manager with five columns in a figure window. Then, add a button to each column of the grid.

    fig = uifigure(Position=[680 558 300 300]);
    gl = uigridlayout(fig,Scrollable="on");
    gl.RowHeight = 30;
    gl.ColumnWidth = {100,100,100,100,100};
    for k = 1:5
        uibutton(gl);
    end

    UI figure window with a row of buttons and a horizontal scroll bar. The first two buttons are fully visible and the third is partially visible.

    Determine which components in the scrollable grid are at least partially visible.

    isInScrollView(gl,gl.Children)
    ans =
    
      5×1 logical array
    
       1
       1
       1
       0
       0

    Input Arguments

    collapse all

    Scrollable container or button group, specified as a Figure object created using the uifigure function, or as a Panel object, GridLayout object, Tab object, or ButtonGroup object in a figure created using the uifigure function.

    UI components, specified as a single object or a vector of objects. The objects must be descendents of the scrollable container specified by container.

    Version History

    Introduced in R2022a

    expand all