Skip to content

Commit 1bef675

Browse files
authored
Merge pull request #5347 from Textualize/fix-wacky-align
Fix broken alignment applied to docked widgets
2 parents 85765f5 + 46f60cf commit 1bef675

File tree

7 files changed

+236
-6
lines changed

7 files changed

+236
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [0.89.1] - 2024-11-05
9+
10+
### Fixed
11+
12+
- Fixed alignment of docked widgets https://github.com/Textualize/textual/pull/5347
13+
814
## [0.89.0] - 2024-11-05
915

1016
## Added
@@ -2627,6 +2633,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
26272633
- New handler system for messages that doesn't require inheritance
26282634
- Improved traceback handling
26292635

2636+
[0.89.1]: https://github.com/Textualize/textual/compare/v0.89.0...v0.89.1
26302637
[0.89.0]: https://github.com/Textualize/textual/compare/v0.88.1...v0.89.0
26312638
[0.88.1]: https://github.com/Textualize/textual/compare/v0.88.0...v0.88.1
26322639
[0.88.0]: https://github.com/Textualize/textual/compare/v0.87.1...v0.88.0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "textual"
3-
version = "0.89.0"
3+
version = "0.89.1"
44
homepage = "https://github.com/Textualize/textual"
55
repository = "https://github.com/Textualize/textual"
66
documentation = "https://textual.textualize.io/"

src/textual/_arrange.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,7 @@ def _arrange_dock_widgets(
167167
# Should not occur, mainly to keep Mypy happy
168168
raise AssertionError("invalid value for dock edge") # pragma: no-cover
169169

170-
align_offset = dock_widget.styles._align_size(
171-
(widget_width, widget_height), size
172-
)
173-
dock_region = dock_region.shrink(margin).translate(align_offset)
170+
dock_region = dock_region.shrink(margin)
174171
styles = dock_widget.styles
175172
offset = (
176173
styles.offset.resolve(

src/textual/css/styles.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ def _align_width(self, width: int, parent_width: int) -> int:
735735
offset_x = (parent_width - width) // 2
736736
else:
737737
offset_x = parent_width - width
738+
738739
return offset_x
739740

740741
def _align_height(self, height: int, parent_height: int) -> int:

src/textual/widgets/_toast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class ToastRack(Container, inherit_css=False):
150150
layer: _toastrack;
151151
width: 1fr;
152152
height: auto;
153-
dock: top;
153+
dock: bottom;
154154
align: right bottom;
155155
visibility: hidden;
156156
layout: vertical;
Lines changed: 154 additions & 0 deletions
Loading

tests/snapshot_tests/test_snapshots.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,3 +2913,74 @@ def compose(self) -> ComposeResult:
29132913
yield label
29142914

29152915
snap_compare(TabApp())
2916+
2917+
2918+
def test_dock_align(snap_compare):
2919+
"""Regression test for https://github.com/Textualize/textual/issues/5345
2920+
You should see a blue panel aligned to the top right of the screen, with a centered button."""
2921+
2922+
class MainContainer(Static):
2923+
def compose(self):
2924+
yield Sidebar()
2925+
2926+
# ~~~~ Sidebar widget ~~~~
2927+
class Sidebar(Static):
2928+
def compose(self):
2929+
yield StartButtons()
2930+
2931+
# ~~~~ the two buttons inside the sidebar ~~~~
2932+
class StartButtons(Static):
2933+
def compose(self):
2934+
yield Button("Start", variant="primary", id="start")
2935+
yield Button("Stop", variant="error", id="stop")
2936+
2937+
# ~~~~ main ~~~~
2938+
class Test1(App):
2939+
CSS = """
2940+
2941+
Screen {
2942+
layout: horizontal;
2943+
}
2944+
2945+
MainContainer {
2946+
width: 100%;
2947+
height: 100%;
2948+
background: red;
2949+
layout: horizontal;
2950+
}
2951+
2952+
2953+
Sidebar {
2954+
width: 40;
2955+
background: blue;
2956+
border: double green;
2957+
layout: vertical;
2958+
2959+
/* seems to be a weird interaction between these two */
2960+
/* V V V V */
2961+
dock: right;
2962+
align-horizontal: center;
2963+
2964+
}
2965+
2966+
StartButtons {
2967+
max-width: 18.5;
2968+
height: 5;
2969+
background: $boost;
2970+
padding: 1;
2971+
layout: horizontal;
2972+
}
2973+
#start {
2974+
dock: left;
2975+
}
2976+
#stop {
2977+
dock: left;
2978+
}
2979+
2980+
2981+
"""
2982+
2983+
def compose(self):
2984+
yield MainContainer()
2985+
2986+
snap_compare(Test1())

0 commit comments

Comments
 (0)