scroll test

This commit is contained in:
Will McGugan
2022-07-13 14:12:17 +01:00
parent 0c56570b94
commit 3b003deea9
5 changed files with 76 additions and 8 deletions

24
sandbox/will/buttons.css Normal file
View File

@@ -0,0 +1,24 @@
Button {
margin: 1;
width: 100%;
}
Vertical {
height: auto;
}
Horizontal {
height: auto;
}
Horizontal Button {
width: 20;
margin: 1 2 ;
}
#scroll {
height: 10;
}

46
sandbox/will/scroll.py Normal file
View File

@@ -0,0 +1,46 @@
from textual import layout, events
from textual.app import App, ComposeResult
from textual.widgets import Button
class ButtonsApp(App[str]):
def compose(self) -> ComposeResult:
yield layout.Vertical(
Button("default", id="foo"),
Button("Where there is a Will"),
Button("There is a Way"),
Button("There can be only one"),
Button.success("success", id="bar"),
layout.Horizontal(
Button("Where there is a Will"),
Button("There is a Way"),
Button("There can be only one"),
Button.warning("warning", id="baz"),
Button("Where there is a Will"),
Button("There is a Way"),
Button("There can be only one"),
id="scroll",
),
Button.error("error", id="baz"),
Button("Where there is a Will"),
Button("There is a Way"),
Button("There can be only one"),
)
def handle_pressed(self, event: Button.Pressed) -> None:
self.app.bell()
async def on_key(self, event: events.Key) -> None:
await self.dispatch_key(event)
def key_d(self):
self.dark = not self.dark
app = ButtonsApp(
log_path="textual.log", css_path="buttons.css", watch_css=True, log_verbosity=2
)
if __name__ == "__main__":
result = app.run()
print(repr(result))

View File

@@ -411,11 +411,7 @@ class DOMNode(MessagePump):
def focusable_children(self) -> list[DOMNode]:
"""Get the children which may be focused."""
# TODO: This may be the place to define order, other focus related rules
return [
child
for child in self.children
if child.display and child.visible and child.can_focus
]
return [child for child in self.children if child.display and child.visible]
def get_pseudo_classes(self) -> Iterable[str]:
"""Get any pseudo classes applicable to this Node, e.g. hover, focus.

View File

@@ -289,10 +289,12 @@ class Widget(DOMNode):
def watch_scroll_x(self, new_value: float) -> None:
self.horizontal_scrollbar.position = int(new_value)
self.refresh(layout=True)
self.horizontal_scrollbar.refresh()
def watch_scroll_y(self, new_value: float) -> None:
self.vertical_scrollbar.position = int(new_value)
self.refresh(layout=True)
self.vertical_scrollbar.refresh()
def validate_scroll_x(self, value: float) -> float:
return clamp(value, 0, self.max_scroll_x)
@@ -724,7 +726,7 @@ class Widget(DOMNode):
region.translate(-scroll_offset)
.translate(-widget.scroll_offset)
.translate(container.virtual_region.offset)
)
).intersection(container.virtual_region)
widget = container
return scrolled
@@ -765,7 +767,7 @@ class Widget(DOMNode):
def __init_subclass__(
cls,
can_focus: bool = True,
can_focus: bool = False,
can_focus_children: bool = True,
inherit_css: bool = True,
) -> None:

View File

@@ -104,7 +104,7 @@ class Coord(NamedTuple):
return Coord(row + 1, column)
class DataTable(ScrollView, Generic[CellType]):
class DataTable(ScrollView, Generic[CellType], can_focus=True):
CSS = """
DataTable {