optional actions

This commit is contained in:
Will McGugan
2022-12-18 21:56:38 +00:00
parent c20bf664e8
commit 2f1bdea234
3 changed files with 43 additions and 33 deletions

View File

@@ -29,7 +29,7 @@ Sidebar {
}
Sidebar:focus-within {
offset: 0 0 !important;
offset: 0 0 !important;
}
Sidebar.-hidden {

View File

@@ -295,7 +295,6 @@ class Screen(Widget):
# No focus, so blur currently focused widget if it exists
if self.focused is not None:
self.focused.post_message_no_wait(events.Blur(self))
self.focused.emit_no_wait(events.DescendantBlur(self))
self.focused = None
self.log.debug("focus was removed")
elif widget.can_focus:
@@ -303,14 +302,12 @@ class Screen(Widget):
if self.focused is not None:
# Blur currently focused widget
self.focused.post_message_no_wait(events.Blur(self))
self.focused.emit_no_wait(events.DescendantBlur(self))
# Change focus
self.focused = widget
# Send focus event
if scroll_visible:
self.screen.scroll_to_widget(widget)
widget.post_message_no_wait(events.Focus(self))
widget.emit_no_wait(events.DescendantFocus(self))
self.log.debug(widget, "was focused")
async def _on_idle(self, event: events.Idle) -> None:

View File

@@ -2344,17 +2344,22 @@ class Widget(DOMNode):
self.mouse_over = True
def _on_focus(self, event: events.Focus) -> None:
for node in self.ancestors_with_self:
if node._has_focus_within:
self.app.update_styles(node)
self.has_focus = True
self.refresh()
self.emit_no_wait(events.DescendantFocus(self))
def _on_blur(self, event: events.Blur) -> None:
if any(node._has_focus_within for node in self.ancestors_with_self):
self.app.update_styles(self)
self.has_focus = False
self.refresh()
self.emit_no_wait(events.DescendantBlur(self))
def _on_descendant_blur(self, event: events.DescendantBlur) -> None:
if self._has_focus_within:
self.app.update_styles(self)
def _on_descendant_focus(self, event: events.DescendantBlur) -> None:
if self._has_focus_within:
self.app.update_styles(self)
def _on_mouse_scroll_down(self, event) -> None:
if self.allow_vertical_scroll:
@@ -2398,34 +2403,42 @@ class Widget(DOMNode):
def _on_scroll_to_region(self, message: messages.ScrollToRegion) -> None:
self.scroll_to_region(message.region, animate=True)
def action_scroll_home(self) -> None:
if self._allow_scroll:
self.scroll_home()
def action_scroll_home(self) -> bool | None:
if not self._allow_scroll:
return False
self.scroll_home()
def action_scroll_end(self) -> None:
if self._allow_scroll:
self.scroll_end()
def action_scroll_end(self) -> bool | None:
if not self._allow_scroll:
return False
self.scroll_end()
def action_scroll_left(self) -> None:
if self.allow_horizontal_scroll:
self.scroll_left()
def action_scroll_left(self) -> bool | None:
if not self.allow_horizontal_scroll:
return False
self.scroll_left()
def action_scroll_right(self) -> None:
if self.allow_horizontal_scroll:
self.scroll_right()
def action_scroll_right(self) -> bool | None:
if not self.allow_horizontal_scroll:
return False
self.scroll_right()
def action_scroll_up(self) -> None:
if self.allow_vertical_scroll:
self.scroll_up()
def action_scroll_up(self) -> bool | None:
if not self.allow_vertical_scroll:
return False
self.scroll_up()
def action_scroll_down(self) -> None:
if self.allow_vertical_scroll:
self.scroll_down()
def action_scroll_down(self) -> bool | None:
if not self.allow_vertical_scroll:
return False
self.scroll_down()
def action_page_down(self) -> None:
if self.allow_vertical_scroll:
self.scroll_page_down()
def action_page_down(self) -> bool | None:
if not self.allow_vertical_scroll:
return False
self.scroll_page_down()
def action_page_up(self) -> None:
if self.allow_vertical_scroll:
self.scroll_page_up()
def action_page_up(self) -> bool | None:
if not self.allow_vertical_scroll:
return False
self.scroll_page_up()