Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The reported width of a widget doesn't take the scrollbar into account. #1888

Closed
davep opened this issue Feb 26, 2023 · 4 comments
Closed

The reported width of a widget doesn't take the scrollbar into account. #1888

davep opened this issue Feb 26, 2023 · 4 comments
Labels
bug Something isn't working Task

Comments

@davep
Copy link
Contributor

davep commented Feb 26, 2023

Consider the following test code:

from textual.app         import App, ComposeResult, RenderResult
from textual.containers  import Vertical
from textual.widgets     import Header, Footer
from textual.scroll_view import ScrollView
from textual.geometry    import Size

class ScrollViewPlaceHolder( ScrollView ):

    def __init__( self, height: int ):
        super().__init__()
        self._height = height

    def on_mount( self ) -> None:
        self.virtual_size = Size( self.size.width, self._height )

    def render( self ) -> RenderResult:
        return "\n".join( (
            "".join( f"{n + 1:3}"[ 0 ] for n in range( self.size.width ) ),
            "".join( f"{n + 1:3}"[ 1 ] for n in range( self.size.width ) ),
            "".join( f"{n + 1:3}"[ 2 ] for n in range( self.size.width ) ),
            "", "",
            f"Size: {self.size!r}",
            f"Virtual size: {self.virtual_size!r}",
            f"Vertical scrollbar width: {self.scrollbar_size_vertical}",
            "",
            "Text to width:",
            "-" * self.size.width,
            "Text to width minus 2:",
            "-" * ( self.size.width - 2 ),
            "Text to width minus vertical scrollbar:",
            "-" * ( self.size.width - self.scrollbar_size_vertical ),
            "Text to width minus vertical scrollbar minus 2:",
            "-" * ( self.size.width - self.scrollbar_size_vertical - 2 ),
        ) )

class ScrollViewApp( App[ None ] ):

    CSS = """
    ScrollViewPlaceHolder {
        height: 1fr;
        border: round red;
    }
    """

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Vertical( ScrollViewPlaceHolder( 1 ), ScrollViewPlaceHolder( 1000 ) )
        yield Footer()

if __name__ == "__main__":
    ScrollViewApp().run()

and the output from it:

Screenshot 2023-02-26 at 22 16 27

Checked with Will and the expectation is that the width should take the scrollbar width into account; but given the above it seems not.

@davep
Copy link
Contributor Author

davep commented Feb 27, 2023

See #1891 work taking place towards a possible fix (not linking this as "a thing that will be fixed by that thing" just yet, but I suspect it will).

@willmcgugan
Copy link
Collaborator

This is as expected. You can get the size without the scrollbars with self.scrollable_content_region.size, which is possibly a verbose. We could add a scrollable_size property to expose that.

@willmcgugan
Copy link
Collaborator

#2175

@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

No branches or pull requests

2 participants