mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
prevent scroll
This commit is contained in:
@@ -899,7 +899,7 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
self.log.system(f"{self.screen} is active")
|
self.log.system(f"{self.screen} is active")
|
||||||
return previous_screen
|
return previous_screen
|
||||||
|
|
||||||
def set_focus(self, widget: Widget | None, scroll_visible: bool = False) -> None:
|
def set_focus(self, widget: Widget | None, scroll_visible: bool = True) -> None:
|
||||||
"""Focus (or unfocus) a widget. A focused widget will receive key events first.
|
"""Focus (or unfocus) a widget. A focused widget will receive key events first.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -300,8 +300,11 @@ class Screen(Widget):
|
|||||||
except errors.NoWidget:
|
except errors.NoWidget:
|
||||||
self.app.set_focus(None)
|
self.app.set_focus(None)
|
||||||
else:
|
else:
|
||||||
if isinstance(event, events.MouseDown) and widget.can_focus:
|
if isinstance(event, events.MouseUp) and widget.can_focus:
|
||||||
self.app.set_focus(widget)
|
if self.app.focused is not widget:
|
||||||
|
self.app.set_focus(widget)
|
||||||
|
event.stop()
|
||||||
|
return
|
||||||
event.style = self.get_style_at(event.screen_x, event.screen_y)
|
event.style = self.get_style_at(event.screen_x, event.screen_y)
|
||||||
if widget is self:
|
if widget is self:
|
||||||
event.set_forwarded()
|
event.set_forwarded()
|
||||||
|
|||||||
@@ -1435,9 +1435,14 @@ class Widget(DOMNode):
|
|||||||
self._layout_required = False
|
self._layout_required = False
|
||||||
screen.post_message_no_wait(messages.Layout(self))
|
screen.post_message_no_wait(messages.Layout(self))
|
||||||
|
|
||||||
def focus(self) -> None:
|
def focus(self, scroll_visible: bool = True) -> None:
|
||||||
"""Give input focus to this widget."""
|
"""Give focus to this widget.
|
||||||
self.app.set_focus(self)
|
|
||||||
|
Args:
|
||||||
|
scroll_visible (bool, optional): Scroll parent to make this widget
|
||||||
|
visible. Defaults to True.
|
||||||
|
"""
|
||||||
|
self.app.set_focus(self, scroll_visible=scroll_visible)
|
||||||
|
|
||||||
def capture_mouse(self, capture: bool = True) -> None:
|
def capture_mouse(self, capture: bool = True) -> None:
|
||||||
"""Capture (or release) the mouse.
|
"""Capture (or release) the mouse.
|
||||||
|
|||||||
Reference in New Issue
Block a user