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

[BUG] The css_classes() in the GtkWidget builder is problematic #1110

Open
melix99 opened this issue Aug 31, 2022 · 5 comments
Open

[BUG] The css_classes() in the GtkWidget builder is problematic #1110

melix99 opened this issue Aug 31, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@melix99
Copy link

melix99 commented Aug 31, 2022

Bug description

When creating a widget using a builder and using its function css_classes to set custom CSS classes, what it does is calling its internal setter set_css_classes which clears any existing css classes and then it adds the one defined by the user. The problem with this is that it also removes css classes that are set by GTK internally, so this often result to undesired behavior. This is an example:

let button = gtk::Button::builder()
    .icon_name("media-playback-start-symbolic")
    .halign(gtk::Align::Center)
    .valign(gtk::Align::Center)
    .css_classes(vec!["flat".into()])
    .build();

In this example, GTK normally adds the css class "image-button" to style the button correctly (in this case it tweaks internal spacing), but with the code above, because of the css_classes, it removes that class and only set the "flat" CSS class. In this specific case it causes the widget to not have a perfectly squared allocation. I guess this can create bigger problems with other combinations.

I think that css_classes() should probably be changed to only add CSS classes to avoid confusion.

@melix99 melix99 added the bug Something isn't working label Aug 31, 2022
@bilelmoussaoui
Copy link
Member

Should it? that is the behaviour of such "property" in general, so I don't feel like we should do anything about it.

@melix99
Copy link
Author

melix99 commented Aug 31, 2022

Should it? that is the behaviour of such "property" in general, so I don't feel like we should do anything about it.

Well, honestly it was quite annoying to debug since I expected that function to behave like the XML "<style>" UI definition, where it does not behave like that.

@bilelmoussaoui
Copy link
Member

That would be an issue to report to gtk itself I guess, to either document the behaviour clearly or to make it keep the default CSS classes somehow

@bilelmoussaoui
Copy link
Member

An alternative would be removing the setter from the builder pattern, but we don't have any way to configure the builder pattern yet.

@bilelmoussaoui
Copy link
Member

See gtk-rs/gir#1302

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants