mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
scroll test
This commit is contained in:
24
sandbox/will/buttons.css
Normal file
24
sandbox/will/buttons.css
Normal 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
46
sandbox/will/scroll.py
Normal 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))
|
||||
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user