CSS styling vs. Programmatic styling, best practices

GTK4 (and presumably GTK5) provide styling information both via programmatic functions (Rust: widget.hexpand(true), etc) and through CSS.

Are there any guidelines as to circumstances when I should choose one method or the other? At the moment I’m making rather a mess of both.

Some things cannot be set via CSS, like: preferred size, or alignment, or anything that is layout-related, since allowing that would turn every UI into the CSS Zen Garden.

In general, use CSS for things that can be set via CSS, like margins, padding, background, etc; and if it can’t be set via CSS, use the corresponding widget API.

Prefer CSS, use programmatic APIs when that fails. Got it.

Thing is, I’ve been coding web pages for so long and through so many generations of ideology, that I have no idea whether CSS Zen Garden is a good thing or a bad thing :lolsob:

The problem with the Zen Garden is that it works perfectly fine for a document; GUI applications are not documents. :wink:

If CSS could re-arrange the controls of any application, it would be impossible to document the UI, or to establish a coherent visual grammar; imagine if none of the native apps you have installed on your system looked or behaved in a similar way: it would be a disaster.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.