-
-
Notifications
You must be signed in to change notification settings - Fork 685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Canvas does not render in ScrollContainer #579
Comments
Canvas inside scrollcontainer works for me on macOS 10.14: |
Not working on mac os Cataline 10.15.3 with this code import toga from toga import App as TogaApp from toga.style import Pack class ScrollContainerTest(TogaApp):
def main(): if name == "main": |
After further investigation I found that it is necessary to set the height and width of the Box container in order to reveal the canvas. |
Ok - this is starting to make sense. The Canvas widget currently sets it's hint size to it's fitting size - which is the size of the view, which is, by default, 0x0. The box containing it then has a size of 0x0 (because it will shrink to be as small as possible, and the scrollbox then has no size. If you manually set the size on the canvas, the problem goes away because the box will then wrap the canvas's specified size, and the scrollview has something to display. Another fix is to modify the rehint() method of the canvas to return a minimum size (e.g., using However, the other observation I can make is that this is a microcosm of some problems that have been reported recently with computing layouts on the overall window. The underlying problem is largely the same - even though the available space is large, "flexing" the outer box doesn't cause the top level box to "fill" the available area. The viewport of the scrollcontainer is behaving in much the same way in this instance. This suggests to me that there is something fundamental needing attention here. |
In this particular case what I was expecting was that the canvas would resize to fit the space available which would be the width of the container and the height of the container minus the fixed height of a toolbar and that this relationship would be maintained through a window resize operation. |
Looking into this a bit more using the debugger the scroll container shows layout parameters of 'layout: <Box (640x480 @ 0,0)>' which seems to be in order. It's layout width and height have been set to fill the main window to which it is attached. As you say, explicitly setting the height/width of the ScrollContainer works as expected but in this case shouldn't the style of flex=1 override the height/width when they are set to 0? Addition: I have now compared this to the operation of a SplitContainer which works as expected (it always shows the canvas content). In this test the right panel also contains a box which has a canvas as its content in the same manner as the ScrollContainer. This box that contains the canvas shows 'layout: Box<315,458 @ 0,0> which is, of course, correct. |
Expected Behavior
I would expect canvas widgets to display in a scroll container
Current Behavior
Scroll Container is empty, and see no calls in the implementation draw functions
Steps to reproduce
Below is a code sample I am using to see the bug, I am currently trying to track it down, but could use some pointers on where to look
`
self.main_window = toga.MainWindow(title=self.name)
self.canvas = toga.Canvas(style=Pack(flex=1))
with self.canvas.stroke() as stroker:
with stroker.closed_path(50, 50) as closer:
closer.line_to(100, 100)
closer.line_to(100, 50)
self.right_content = toga.Box(
children=[self.canvas],
style=Pack(direction=COLUMN, padding_top=50)
)
self.right_container = toga.ScrollContainer()
self.right_container.content = self.right_content
self.main_window.content = self.right_container
self.main_window.show()
`
Your Environment
Python Version (list the specific version number)
3
Operating System and Version (select from the following and list the specific version number; if your OS is not listed, list that as well)
Toga Target (the type of app you are trying to generate)
The text was updated successfully, but these errors were encountered: