18
submitted 2 weeks ago* (last edited 2 weeks ago) by Doods@infosec.pub to c/rust@programming.dev

It might be lack of sleep, but I can't figure this out.

I have a Label, and I want its text to be red when it represents an error, and I want it be green when it represent "good to go".

I found search result for C and maybe a solution for Python, but nothing for Rust.

I tried manually setting the css-classes property and running queue_draw(); it didn't work.

I can have a gtk::Box or a Frame that I place where the Label should go, then declare two Labels, and use set_child() to switch between them, but that seems like an ugly solution.

Do you have a solution?

SOLVED:

I have to add a "." before declaring a CSS "thing" for it to be considered a class.

Ex:

.overlay {
        background: rgba(60, 60, 60, 1);
        font-size: 25px;
}

instead of:

overlay {
        background: rgba(60, 60, 60, 1);
        font-size: 25px;)
}

Just use label.add_css_class(), label.remove_css_class() or label.set_css_classes() and make sure to properly load your CSS style sheets,

Source: the comment of d_k_bo@feddit.org

you are viewing a single comment's thread
view the rest of the comments
[-] Doods@infosec.pub 5 points 2 weeks ago

This is embarrassing, but when was it not?

I have to add a "." before the name of a css class, I must learn my tools.

[-] zlatko@programming.dev 3 points 2 weeks ago

I mean, it is not embarrassing for you. In the browser, the CSS's "native platform", you add classes, via the JavaScript API, without the dot. It's not a stupid assumption.

To have to add the dot in the CSS class name seems a bit of an oversight in the gtkrs API.

[-] zlatko@programming.dev 1 points 3 days ago

(sorry for the late response, I have to get in the habit of checking my Lemmy account)

No, I get that - a stylesheet denotes a class by having a dot. A JavaScript API for adding a CSS class omits this redundancy.

I was saying that the author might not be wrong to want to avoid the redundancy in rust example as well (since it explicitly mentions CSS classes).

[-] d_k_bo@feddit.org 1 points 2 weeks ago

I think you understood their comment wrong. In your code (e.g. label.add_css_class("green");) you don't use a dot, but in the CSS stylesheet. It works the same as with HTML/JS/CSS.

[-] d_k_bo@feddit.org 2 points 2 weeks ago

Well, that's CSS :D

Note that if you create a custom Widget class, you can set a CSS name, wich isn't a CSS class and doesn't use a leading dot.

[-] Doods@infosec.pub 1 points 2 weeks ago

you can set a CSS name, wich isn’t a CSS class and doesn’t use a leading dot.

Yeah that's what I've been using all along.

this post was submitted on 31 Oct 2024
18 points (95.0% liked)

Rust

5999 readers
19 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS