Skip to content

Commit

Permalink
Loading indicator simplify (#2050)
Browse files Browse the repository at this point in the history
* nice simplify

* import

* changelog

* doc [skip ci]
  • Loading branch information
willmcgugan authored Mar 14, 2023
1 parent d80e38c commit c5f1cbd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Changed

- Dropped "loading-indicator--dot" component style from LoadingIndicator https://github.com/Textualize/textual/pull/2050

## [0.15.1] - 2023-03-14

Expand Down
12 changes: 10 additions & 2 deletions docs/widgets/loading_indicator.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ Displays pulsating dots to indicate when data is being loaded.
- [ ] Focusable
- [ ] Container

You can set the color of the loading indicator by setting its `color` style.

Here's how you would do that with CSS:

```sass
LoadingIndicator {
color: red;
}
```


=== "Output"

Expand All @@ -17,8 +27,6 @@ Displays pulsating dots to indicate when data is being loaded.
--8<-- "docs/examples/widgets/loading_indicator.py"
```



## See Also

* [LoadingIndicator](../api/loading_indicator.md) code reference
15 changes: 2 additions & 13 deletions src/textual/widgets/_loading_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,13 @@
class LoadingIndicator(Widget):
"""Display an animated loading indicator."""

COMPONENT_CLASSES = {"loading-indicator--dot"}

DEFAULT_CSS = """
LoadingIndicator {
width: 100%;
height: 100%;
content-align: center middle;
}
LoadingIndicator > .loading-indicator--dot {
color: $accent;
}
"""

def on_mount(self) -> None:
Expand All @@ -36,11 +30,7 @@ def render(self) -> RenderableType:
elapsed = time() - self._start_time
speed = 0.8
dot = "\u25CF"
dot_styles = self.get_component_styles("loading-indicator--dot")

base_style = self.rich_style
background = self.background_colors[-1]
color = dot_styles.color
_, _, background, color = self.colors

gradient = Gradient(
(0.0, background.blend(color, 0.1)),
Expand All @@ -53,8 +43,7 @@ def render(self) -> RenderableType:
dots = [
(
f"{dot} ",
base_style
+ Style.from_color(gradient.get_color((1 - blend) ** 2).rich_color),
Style.from_color(gradient.get_color((1 - blend) ** 2).rich_color),
)
for blend in blends
]
Expand Down

0 comments on commit c5f1cbd

Please sign in to comment.