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

add get_content_width #4507

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed

- Fixed auto width not working for option lists https://github.com/Textualize/textual/pull/4507

## [0.59.0] - 2024-05-11

### Fixed
Expand Down
10 changes: 10 additions & 0 deletions src/textual/widgets/_option_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import ClassVar, Iterable, NamedTuple

from rich.console import RenderableType
from rich.measure import Measurement
from rich.padding import Padding
from rich.repr import Result
from rich.rule import Rule
Expand Down Expand Up @@ -360,6 +361,15 @@ def __init__(
# the state of the option list in regard to its available options.
self.action_first()

def get_content_width(self, container: Size, viewport: Size) -> int:
"""Get maximum width of options."""
console = self.app.console
options = console.options
return max(
Measurement.get(console, options, option.prompt).maximum
for option in self._options
)

def _request_content_tracking_refresh(
self, rescroll_to_highlight: bool = False
) -> None:
Expand Down
Loading