-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a scrollbar to the slide contents when needed. (#195)
* This PR adds a scrollbar to the slide contents when needed.
- Loading branch information
1 parent
0a6667a
commit efe843e
Showing
9 changed files
with
468 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import urwid | ||
|
||
|
||
from lookatme.widgets.scrollbar import Scrollbar | ||
from lookatme.tutorial import tutor | ||
|
||
|
||
@tutor( | ||
"general", | ||
"scrolling", | ||
r""" | ||
The scrollbar that kkjjj | ||
Scroll with: | ||
| amount | up key | down key | | ||
|-------:|----------|------------| | ||
| line | up arrow | down arrow | | ||
| page | page up | page down | | ||
Try scrolling through the numbers 0-49 below: | ||
{numbers} | ||
""".format( | ||
numbers="\n\n ".join(str(n) for n in range(50)) | ||
), | ||
order=0.2, | ||
) | ||
class ScrollMonitor(urwid.Frame): | ||
def __init__(self, main_widget: urwid.Widget, scrollbar: Scrollbar): | ||
self.main_widget = main_widget | ||
self.scrollbar = scrollbar | ||
super().__init__(self.main_widget) | ||
|
||
def render(self, size, focus: bool = True): | ||
if not self.scrollbar.should_display(size): | ||
return super().render(size, focus) | ||
|
||
width, height = size | ||
|
||
main_canvas = super().render((width - 1, height), focus) | ||
if not isinstance(main_canvas, urwid.CompositeCanvas): | ||
main_canvas = urwid.CompositeCanvas(main_canvas) | ||
|
||
scroll_canvas = self.scrollbar.render((1, height), focus) | ||
if not isinstance(scroll_canvas, urwid.CompositeCanvas): | ||
scroll_canvas = urwid.CompositeCanvas(scroll_canvas) | ||
|
||
return urwid.CanvasJoin( | ||
[ | ||
(main_canvas, None, True, main_canvas.cols()), | ||
(scroll_canvas, None, False, scroll_canvas.cols()), | ||
] | ||
) |
Oops, something went wrong.