Skip to content
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

[DOC] How to set the size of a Widget ? #459

Open
Kochise opened this issue Nov 5, 2021 · 5 comments
Open

[DOC] How to set the size of a Widget ? #459

Kochise opened this issue Nov 5, 2021 · 5 comments

Comments

@Kochise
Copy link

Kochise commented Nov 5, 2021

I have a MPLCanvas I'd like to reshape at runtime and the whole parent Window to resize accordingly, how is it possible ?

All what've found so far is Window.set_size() but I need the MPLCanvas child to have a specific size instead.

https://enaml.readthedocs.io/en/latest/api_ref/widgets/window.html?highlight=size#enaml.widgets.window.Window.set_size

@MatthieuDartiailh
Copy link
Member

This is not the typical way to use enaml layout engine but you can specify the width and height as part of the constraints on the container which is the parent of your canvas as below (sizes are in pixel):

enamldef Main(Window):
    Container:
        constraints = [
            vbox(
                hbox(cbox, check, spacer),
                canvas,
            ),
            cbox.v_center == check.v_center,
            canvas.width == 1024,
            canvas.height == 480,
        ]
        ComboBox: cbox:
            items = ['one', 'two']
            index = 0
        CheckBox: check:
            text = 'Toolbar Visible'
            checked := canvas.toolbar_visible
        MPLCanvas: canvas:
            figure << figures[cbox.selected_item]

@Kochise
Copy link
Author

Kochise commented Nov 5, 2021

Yet I'd like to do MPLCanvas.set_size() instead, because I only need to set it's size from time to time.

I use the MPLCanvas to display a VNC connection and regarding the server screen's size, update the canvas' size accordingly.

Then I don't want to prevent the user from resizing the parent Window to its liking though.

Btw, thank for the hint.

@MatthieuDartiailh
Copy link
Member

Setting the constraints can be done dynamically (be careful to no simply update the list in place though) and will get you what you want. You can access the canvas parent using the parent attribute. You can even have you canvas alone in a container in which case you size constraints will be the only ones.

@Kochise
Copy link
Author

Kochise commented Nov 5, 2021

mplcanvas_resizing

@Kochise
Copy link
Author

Kochise commented Nov 5, 2021

The problem is even a Container is derived from Widget which doesn't support .set_size().

When I say I'd like to "resize" the canvas, it's only at the connection, then leave the user "unconstrained" to resize the window.

The best would be to set a "constraint" on the canvas' ratio, so that when changing the Window width, its height also adapts accordingly in real time.

snow_ratio_resize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants