mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add a Label widget
For the moment this does nothing more than inherit from a Static; but what it does do is make it easier for someone to add text to their application and to style it by styling all the Labels. Before now it would be common to use a Static but if you try and style (or query) all Statics, you'd also get things like Buttons, which inherit from Static. See #1190
This commit is contained in:
@@ -13,7 +13,7 @@ from textual.containers import Horizontal
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.screen import Screen
|
||||
from textual.widget import Widget
|
||||
from textual.widgets import Footer, Button, Static
|
||||
from textual.widgets import Footer, Button, Label
|
||||
from textual.css.query import DOMQuery
|
||||
from textual.reactive import reactive
|
||||
from textual.binding import Binding
|
||||
@@ -33,10 +33,10 @@ class Help(Screen):
|
||||
Returns:
|
||||
ComposeResult: The result of composing the help screen.
|
||||
"""
|
||||
yield Static(Markdown(Path(__file__).with_suffix(".md").read_text()))
|
||||
yield Label(Markdown(Path(__file__).with_suffix(".md").read_text()))
|
||||
|
||||
|
||||
class WinnerMessage(Static):
|
||||
class WinnerMessage(Label):
|
||||
"""Widget to tell the user they have won."""
|
||||
|
||||
MIN_MOVES: Final = 14
|
||||
@@ -91,9 +91,9 @@ class GameHeader(Widget):
|
||||
ComposeResult: The result of composing the game header.
|
||||
"""
|
||||
yield Horizontal(
|
||||
Static(self.app.title, id="app-title"),
|
||||
Static(id="moves"),
|
||||
Static(id="progress"),
|
||||
Label(self.app.title, id="app-title"),
|
||||
Label(id="moves"),
|
||||
Label(id="progress"),
|
||||
)
|
||||
|
||||
def watch_moves(self, moves: int):
|
||||
@@ -102,7 +102,7 @@ class GameHeader(Widget):
|
||||
Args:
|
||||
moves (int): The number of moves made.
|
||||
"""
|
||||
self.query_one("#moves", Static).update(f"Moves: {moves}")
|
||||
self.query_one("#moves", Label).update(f"Moves: {moves}")
|
||||
|
||||
def watch_filled(self, filled: int):
|
||||
"""Watch the on-count reactive and update when it changes.
|
||||
@@ -110,7 +110,7 @@ class GameHeader(Widget):
|
||||
Args:
|
||||
filled (int): The number of cells that are currently on.
|
||||
"""
|
||||
self.query_one("#progress", Static).update(f"Filled: {filled}")
|
||||
self.query_one("#progress", Label).update(f"Filled: {filled}")
|
||||
|
||||
|
||||
class GameCell(Button):
|
||||
|
||||
Reference in New Issue
Block a user