Default clickable ranges correctly in underline bar

This commit is contained in:
Darren Burns
2022-02-17 13:29:07 +00:00
parent d1687374b0
commit 2a634f7293
2 changed files with 13 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ from dataclasses import dataclass
from rich.console import RenderableType
from rich.padding import Padding
from rich.text import Text
from rich.rule import Rule
from textual import events
from textual.app import App
@@ -11,8 +11,13 @@ from textual.widget import Widget
from textual.widgets.tabs import Tabs
class Hr(Widget):
def render(self) -> RenderableType:
return Rule()
class Info(Widget):
DEFAULT_STYLES = "height: 1;"
DEFAULT_STYLES = "height: 2;"
def __init__(self, text: str) -> None:
super().__init__()
@@ -129,12 +134,13 @@ class BasicApp(App):
self.mount(
info=Info(
"\n"
"• The examples below show customisation options for the [#1493FF]Tabs[/] widget.\n"
"• The examples below show customisation options for the [bold #1493FF]Tabs[/] widget.\n"
"• Press keys 1-6 on your keyboard to switch tabs, or click on a tab.",
)
)
for example in self.examples:
info = Info(example.description)
self.mount(Hr())
self.mount(info)
self.mount(example.widget)

View File

@@ -1,8 +1,7 @@
from __future__ import annotations
from rich.console import ConsoleOptions, Console, RenderResult
from rich.segment import Segment
from rich.style import StyleType, Style
from rich.style import StyleType
from rich.text import Text
@@ -27,7 +26,7 @@ class UnderlineBar:
self.highlight_range = highlight_range
self.highlight_style = highlight_style
self.background_style = background_style
self.clickable_ranges = clickable_ranges
self.clickable_ranges = clickable_ranges or {}
self.width = width
def __rich_console__(
@@ -50,7 +49,8 @@ class UnderlineBar:
if start == end == 0 or end < 0 or start > end:
output_bar.append(Text(bar * width, style=background_style, end=""))
return output_bar
yield output_bar
return
# Round start and end to nearest half
start = round(start * 2) / 2