Unable to tell a child widget to be 100% the height of the parent widget
See original GitHub issueGiven this code:
from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import Static
class HeightApp( App[ None ] ):
CSS = """
Horizontal {
border: solid red;
height: auto;
}
Static {
border: solid green;
width: auto;
}
#fill_parent {
height: auto;
}
#static {
height: 23;
}
"""
def compose( self ) -> ComposeResult:
yield Horizontal(
Static( "How to make this as tall as container?", id="fill_parent" ),
Static( "This has default\nheight\nbut a\nfew lines" ),
Static( "I have a static height", id="static" ),
)
if __name__ == "__main__":
HeightApp().run()
this is the output:
Now imagine you want to make the first widget exactly as tall as the containing widget. Given all other things seen in CSS, it feels like you should be able to set the height
of fill_parent
to 100%
and it will vertically fill the parent – in effect matching the height of the tallest non-relative-sized widget. But if I do that the widget does this instead:
It’s as if it is taking the height from the container’s container, or simply the Screen
.
Note the same happens if height
is set to 1fr
.
Raising this issue to first check if this is the expected behaviour.
Issue Analytics
- State:
- Created 10 months ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How can I layout widgets based on the size of the parent?
You will want to use the LayoutBuilder widget which will build at layout time and provides the parent widget's constraints.
Read more >Child Widget is always clipped by Parent Size #54551 - GitHub
When a Child Widget attempts to exceed the size of the Parent, it is clipped. ... 100), child: Container( width: 100, height: 100, ......
Read more >How to Set Child Widget Width Equal to Parent in Flutter
This error occurs when the parent widget has an infinite container and the child widget has infinite width or height.
Read more >Can anyone explain widget Constraints? I am not able to wrap ...
If you want to set a widget to 25% of the width and/or height of the parent widget, there's a FractionallySizedBox and an...
Read more >Flutter: The Advanced Layout Rule Even Beginners Must Know
A widget gets its own constraints from its parent. A “constraint” is just a set of 4 doubles: a minimum and maximum width,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should be fixed in main. Making that column expand is now as simple as:
If I’m understanding you correctly… that’s fine, the enclosing
Horizontal
avoids those:I’ve not dived into the code yet (this issue is for future investigation for me as much as anything), but I feel like there could be a tweak to be had here regarding deciding which child height wins when trying to decide the best height.