Skip to content

Fix breakpoints #5785

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

Merged
merged 10 commits into from
May 11, 2025
Merged

Conversation

python-and-novella
Copy link
Contributor

Fix VERTICAL_BREAKPOINTS won't work.

Copy link
Contributor

@TomJGooding TomJGooding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to add a separate snapshot test for vertical breakpoints?

The updated snapshots don't really demonstrate the change in layout, but also don't match the description in the docstring:

def test_breakpoints(snap_compare, size):
"""Test HORIZONTAL_BREAKPOINTS
You should see four terminals of different sizes with a grid of placeholders.
The first should have a single column, then two columns, then 4, then 6.
"""

@python-and-novella python-and-novella deleted the fix-breakpoints branch May 7, 2025 16:08
@python-and-novella python-and-novella restored the fix-breakpoints branch May 7, 2025 16:15
Copy link
Contributor

@TomJGooding TomJGooding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for adding the snapshot test! But this still needs Will's approval (and an update to the CHANGELOG).

@willmcgugan
Copy link
Collaborator

Please add an entry to the CHANGELOG, and we should be good to go!

@python-and-novella
Copy link
Contributor Author

If someone is waiting for this pr, put following code in the head of source code, that will fix it:

# patch is here
from textual.app import App
from textual.screen import Screen
from textual import events

class Screen(Screen):
    async def _on_resize(self, event: events.Resize) -> None:
        event.stop()
        self._screen_resized(event.size)
        for screen in self.app._background_screens:
            screen._screen_resized(event.size)

        horizontal_breakpoints = (
            self.app.HORIZONTAL_BREAKPOINTS
            if self.HORIZONTAL_BREAKPOINTS is None
            else self.HORIZONTAL_BREAKPOINTS
        ) or []

        vertical_breakpoints = (
            self.app.VERTICAL_BREAKPOINTS
            if self.VERTICAL_BREAKPOINTS is None
            else self.VERTICAL_BREAKPOINTS
        ) or []

        width, height = event.size
        if horizontal_breakpoints:
            self._set_breakpoints(width, horizontal_breakpoints)
        if vertical_breakpoints:
            self._set_breakpoints(height, vertical_breakpoints)
            
class App(App):
    def get_default_screen(self) -> Screen:
        """Get the default screen.

        This is called when the App is first composed. The returned screen instance
        will be the first screen on the stack.

        Implement this method if you would like to use a custom Screen as the default screen.

        Returns:
            A screen instance.
        """
        return Screen(id="_default")
# patch is over

@willmcgugan willmcgugan merged commit 2f38af7 into Textualize:main May 11, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants