mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Default clickable ranges correctly in underline bar
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user