Skip to content

Commit

Permalink
Tabs styled with block cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Oct 30, 2024
1 parent ace924f commit cd5aeeb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
19 changes: 1 addition & 18 deletions src/textual/widgets/_list_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ class ListItem(Widget, can_focus=False):
documentation for more details on use.
"""

DEFAULT_CSS = """
ListItem {
height: auto;
overflow: hidden hidden;
background: $surface;
& > :disabled {
background: $background;
}
& > Widget {
height: auto;
& :hover {
background: $block-hover-background;
}
}
}
"""

highlighted = reactive(False)
"""Is this item highlighted?"""

Expand All @@ -48,4 +30,5 @@ async def _on_click(self, _: events.Click) -> None:
self.post_message(self._ChildClicked(self))

def watch_highlighted(self, value: bool) -> None:
print("highlighted", value)
self.set_class(value, "--highlight")
18 changes: 13 additions & 5 deletions src/textual/widgets/_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ class ListView(VerticalScroll, can_focus=True, can_focus_children=False):
DEFAULT_CSS = """
ListView {
background: transparent;
& > ListItem.--highlight {
color: $block-cursor-foreground;
background: $block-cursor-blurred-background;
}
&:focus-within {
background-tint: $foreground 5%;
}
&:focus .--highlight {
& > ListItem {
color: $foreground;
height: auto;
overflow: hidden hidden;
&.--highlight {
color: $block-cursor-foreground;
background: $block-cursor-blurred-background;
}
}
&:focus > ListItem.--highlight {
color: $block-cursor-foreground;
background: $block-cursor-background;
text-style: $block-cursor-text-style;
Expand Down
14 changes: 7 additions & 7 deletions src/textual/widgets/_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Underline(Widget):
width: 1fr;
height: 1;
& > .underline--bar {
color: $block-cursor-background;
background: $foreground 10%;
color: $block-cursor-blurred-background;
}
}
"""
Expand Down Expand Up @@ -91,8 +91,8 @@ class Tab(Static):
DEFAULT_CSS = """
Tab {
width: auto;
height: 2;
padding: 1 1 0 2;
height: 1;
padding: 0 1;
text-align: center;
color: $foreground 50%;
Expand Down Expand Up @@ -201,15 +201,16 @@ class Tabs(Widget, can_focus=True):
DEFAULT_CSS = """
Tabs {
width: 100%;
height: 3;
height: 2;
&:focus {
.underline--bar {
color: $block-cursor-background;
background: $foreground 30%;
}
& .-active {
text-style: bold;
text-style: $block-cursor-text-style;
color: $block-cursor-foreground;
background: $block-cursor-background;
}
}
Expand All @@ -219,7 +220,6 @@ class Tabs(Widget, can_focus=True):
#tabs-list {
width: auto;
min-height: 2;
}
#tabs-list-bar, #tabs-list {
width: auto;
Expand Down

0 comments on commit cd5aeeb

Please sign in to comment.