CSS + GTK: A loose idea for absolute positioning of elements

Hey there,

I have been using gtk3 for quite a while now via ruby-gtk3. A few months
ago I wrote something here; this time I have more experience and solved
tons of problems.

I also got into the CSS subset that gtk supports and this works very well,
at the least for me. I actually was using perl and php (and thus knew
HTML and CSS) before ruby already, so the idea to extend support for CSS
was what I liked in gtk3.

But there is one thing that puzzles me a bit.

Say in HTML you have a div-tag and you style it via CSS such as:

<div style="width:300px; height: 50px">
  Some text here
</div>

Would this not be useful for gtk3 or gtk4 as well?

Now: I am NOT suggesting to abandon the old way. The old way can be retained,
no problem. But would it not be interesting to have style-elements be specified
in this way?

I remember Matthias from the gitlab issue tracker not seeming overwhelmed to
make CSS as central for gtk, so this may not have any chance to be added.

But I can think of two benefits:

  • Lots of users world wide would easily understand the CSS/HTML variant.
  • People may more easily be able to style the widget hierarchy in general,
    including ad-hoc overriding this.

I am mostly talking about GTK here as a toolkit; how DEs such as GNOME
handle this is up to them of course.

I think the biggest benefit for this would be that lots of people who
already know HTML/CSS would find it easier to use gtk - probably not the
C bindings as such, but say python and pygobject. (I use both ruby and
python actually; to me the two languages are so similar that it isn’t
often worth that much to argue about their differences, which IMO are
more from the philosophical point of view, not the practical side of
view. The pygobject examples that I find, work almost 1:1 via ruby as
well, for the most part.)

At any rate, coming from ruby-gtk2 originally, I like the CSS support in
ruby-gtk3. Even if it is not comparable to what a typical browser offers,
I was able to do LOTS of things already, even javascript-like transitionings
which is quite nice, for a bit eye candy (I try to not go overboard or make
it distracting, but sometimes slow colour-changes are nice to have, like
slightly brighter yellow background over a gtk-entry).

Have you seen vgtk? That might be close to what you want, although it’s Rust, not Ruby.

Regarding your example, somebody could make a similar preprocessor that transforms the HTML and CSS into a GtkConstraintLayout.

1 Like

No, it would not.

CSS is used for theming, which means it can be changed by an application’s end user; if layout were under the control of the user then any application would possibly have different layouts than the one for which they were designed. This would break things like documentation, translation, accessibility. It would make applications not look and behave as intended by their authors.

If you want to write applications using HTML and CSS, embed a WebKit web view and write your application using HTML, CSS, and JavaScript.

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