fix: use content_size and fixed width for sidebar layout

width: auto on Static expands to content width before clamping,
so self.size.width matched content and truncation never fired.
Switch to fixed width with dynamic resize, use content_size to
exclude padding/border from width calculations.
This commit is contained in:
Username
2026-02-24 12:38:24 +01:00
parent 590e5e8f0f
commit e7698fd181

View File

@@ -56,7 +56,7 @@ class StatusBar(Static):
server_info = reactive("") server_info = reactive("")
def render(self) -> str: def render(self) -> str:
w = self.size.width if self.size.width > 0 else 80 w = self.content_size.width if self.content_size.width > 0 else 80
if self.connected: if self.connected:
conn_sym = "[#9ece6a]\u25cf[/]" conn_sym = "[#9ece6a]\u25cf[/]"
@@ -106,8 +106,10 @@ class ChannelTree(Static):
@property @property
def _available_width(self) -> int: def _available_width(self) -> int:
"""Usable character width, accounting for padding.""" """Usable character width (content area, excludes padding/border)."""
w = self.size.width if self.size.width > 0 else self.DEFAULT_WIDTH w = self.content_size.width
if w <= 0:
w = self.DEFAULT_WIDTH
return max(w, 12) return max(w, 12)
@staticmethod @staticmethod
@@ -203,12 +205,10 @@ class TuimbleApp(App):
height: 1fr; height: 1fr;
} }
#sidebar { #sidebar {
width: auto; width: 24;
min-width: 16;
max-width: 32;
border-right: solid #292e42; border-right: solid #292e42;
padding: 0 1; padding: 0 1;
overflow: hidden; overflow-x: hidden;
} }
#chat-area { #chat-area {
width: 1fr; width: 1fr;
@@ -429,9 +429,10 @@ class TuimbleApp(App):
# -- resize -------------------------------------------------------------- # -- resize --------------------------------------------------------------
def on_resize(self, _event: events.Resize) -> None: def on_resize(self, event: events.Resize) -> None:
"""Refresh width-aware widgets when terminal resizes.""" """Adapt layout to new terminal dimensions."""
self.query_one("#sidebar", ChannelTree).refresh() sidebar = self.query_one("#sidebar", ChannelTree)
sidebar.styles.width = max(16, min(32, event.size.width // 4))
self.query_one("#status", StatusBar).refresh() self.query_one("#status", StatusBar).refresh()
# -- lifecycle ----------------------------------------------------------- # -- lifecycle -----------------------------------------------------------