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

How to set property requiring more than one parameter? #21

Open
paulolieuthier opened this issue Nov 23, 2019 · 6 comments
Open

How to set property requiring more than one parameter? #21

paulolieuthier opened this issue Nov 23, 2019 · 6 comments

Comments

@paulolieuthier
Copy link

I'm trying to set a fixed size for a widget:

gtk! {
    <AspectFrame::new(None, 0.5, 0.5, 1f32, false) size_request=(100, -1)>
        <Button label="xalala" />
    </AspectFrame>
}

I'm passing the parameters as a tuple because that's what feels natural in this case. However, I get an error:

error[E0061]: this function takes 2 parameters but 1 parameter was supplied
  --> example.rs
   |
   |             <AspectFrame::new(None, 0.5, 0.5, 1f32, false) size_request=(100, -1)>
   |                                                            ^^^^^^^^^^^^ expected 2 parameters

How can I set it? Is it necessary to add helper to vgtk (WidgetHelpers) for it?

@paulolieuthier
Copy link
Author

Just for the record, setting the size can be done using distinct properties for width and height:

gtk! {
    <AspectFrame::new(None, 0.5, 0.5, 1f32, false)
                property_width_request=100
                property_height_request=100>
        <Button label="xalala" />
    </AspectFrame>
}

@bodil
Copy link
Owner

bodil commented Nov 27, 2019

The right thing to do here, I think, is to go with the two individual properties. However, I hate those "property_" names and I think I'll need to add helper methods for them. Leaving the issue open for that.

@archseer
Copy link

archseer commented Nov 27, 2019 via email

@bodil
Copy link
Owner

bodil commented Nov 27, 2019

But those two set different properties - Window::set_default_size sets Window::default-width and Window::default-height while Widget::set_size_request sets Widget::height-request and Widget::width-request. And there are individual setters for all of them, albeit with the annoying property_ prefix.

The reason I'm extremely reluctant to add syntax for this is that the only reasonable syntax I can imagine for it ((1, 2)) would override the syntax for setting a property that takes a tuple, which would be a plausible scenario when custom Gtk classes land in gtk-rs, especially if it turns out those make a better way to build subcomponents. I'm also just generally wary of adding more syntax than strictly necessary.

@archseer
Copy link

Weird, I'm not sure how I missed that, thanks!

Agreed, although I'd still like a way to be able to wrap calls that require more than one argument. I'm currently experimenting with adding an extension trait for https://github.com/subgraph/gtk-layer-shell-rs/blob/master/examples/example.rs#L21-L39

I guess my trait's method could just take a single parameter that would be a tuple, i.e. (gtk_layer_shell::Edge::Left, 40) and then I would unwrap that and call the actual setter.

@nt8r
Copy link
Contributor

nt8r commented May 29, 2020

This is also necessary for setters like Notebook::set_action_widget.

On the topic of syntax, what about adopting tuple-splatting from python (e.g., size_request=*(100, -1))?

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

4 participants