mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
added sandbox
This commit is contained in:
39
sandbox/will/layer_order.py
Normal file
39
sandbox/will/layer_order.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Static
|
||||
|
||||
|
||||
class OrderApp(App):
|
||||
|
||||
CSS = """
|
||||
Screen {
|
||||
layout: center;
|
||||
}
|
||||
Static {
|
||||
border: heavy white;
|
||||
}
|
||||
#one {
|
||||
background: red;
|
||||
width:20;
|
||||
height: 30;
|
||||
}
|
||||
#two {
|
||||
background: blue;
|
||||
width:30;
|
||||
height: 20;
|
||||
}
|
||||
#three {
|
||||
background: green;
|
||||
width:40;
|
||||
height:10
|
||||
}
|
||||
"""
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("One", id="one")
|
||||
yield Static("Two", id="two")
|
||||
yield Static("Three", id="three")
|
||||
|
||||
|
||||
app = OrderApp()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
@@ -462,9 +462,12 @@ class Compositor:
|
||||
@property
|
||||
def layers(self) -> list[tuple[Widget, MapGeometry]]:
|
||||
"""Get widgets and geometry in layer order."""
|
||||
index_one = itemgetter(1)
|
||||
if self._layers is None:
|
||||
self._layers = sorted(
|
||||
self.map.items(), key=lambda item: item[1].order, reverse=True
|
||||
self.map.items(),
|
||||
key=lambda item: index_one(index_one(item)),
|
||||
reverse=True,
|
||||
)
|
||||
return self._layers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user