Hi Team,
How do I style the Gtk widgets such as button? I’m aware that gtk supports CSS but I want to do it using rust.
Say for example I create a button as below. How do I add additional styling such as background-color, padding etc,.
let button = Button::builder()
.label("Press me!")
.margin_top(12)
.margin_bottom(12)
.margin_start(12)
.margin_end(12)
.build();
Thanks,
Arun
ebassi
(Emmanuele Bassi)
November 29, 2021, 2:00pm
2
You add CSS classes using the ButtonBuilder.css_classes() method.
The CSS classes are loaded by a CSSProvider .
Is it not possible to add other css styling like we add margin_top, margin_bottom using rust methods?
ebassi
(Emmanuele Bassi)
December 3, 2021, 11:09am
4
Those are not CSS properties: the margin set using the Widget API is applied regardless of the style.
jfrancis
(Jason Francis)
December 3, 2021, 6:33pm
5
I assume you want to do something similar to the DOM API where you can set inline styles on an HTML element, this is not currently possible although someone could probably come up with a way to emulate it using Widget::set_name and CssProvider.