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