Git Product home page Git Product logo

Comments (7)

superlou avatar superlou commented on June 29, 2024

Is there any way to use this in the current version, even if it's an ugly hack? Just trying to change button background colors.

from relm.

antoyo avatar antoyo commented on June 29, 2024

Yes, you can always use GTK directly.
Please look here to see an example from the mg crate.

from relm.

superlou avatar superlou commented on June 29, 2024

That seems to be working. For whatever reason it would only work if the style_context was for the specific Widget (a gtk::Button) and the name was used to identify the style:

impl Widget for BusButton {
    fn init_view(&self, model: &mut BusButtonModel) {
        let style_context = self.bus_button.get_style_context().unwrap();
        let style = include_str!("../style/bus_button.css");
        let provider = CssProvider::new();
        provider.load_from_data(style).unwrap();
        style_context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_APPLICATION);

        if model.active {
            self.add_class("active")
        }
    }
...
    view! {
        gtk::Box {
            orientation: Vertical,
            gtk::ToggleButton {
                active: model.active,
                sensitive: false,
            }
            #[name="bus_button"]
            gtk::Button {
                clicked => Request,
                label: &(&model.channel_id + 1).to_string(),
                visible: true,
                sensitive: model.enabled,
                name: "bus-button",
            }
        }
    }

And css:

#bus-button.active {
  background-color: #ffa0a0;
}

If I tried using just button for the CSS selector it didn't work. Is that to be expected?

It would be cool if attribute addition/removal could be bound directly to model attributes. Maybe something like:

view! {
  gtk::Button {
    class-active: model.active
  }
}

So if the boolean is true, the class is added.

from relm.

antoyo avatar antoyo commented on June 29, 2024

It is expected that button does not work: it should be button > label.
Run with the environment variable GTK_DEBUG=interactive set to be able to inspect the widgets.
In the Objects tab, click of "Show details" (the bulb icon), choose CSS node and you'll see a tree of nodes that you can use in your selectors.

Also, the idea of conditional class is interesting, even thought I'll probably use another syntax.

from relm.

superlou avatar superlou commented on June 29, 2024

Oy. I completely forgot that GTK buttons have a label as their child.

The conditional class bindings was heavily based on how Ember.js handles classes in components. I'm not particular to the syntax, just hoping to cut down on some boiler-plate.

from relm.

syntapy avatar syntapy commented on June 29, 2024

Noob here

Yes, you can always use GTK directly.
Please look here to see an example from the mg crate.

I tried following that. However, I couldn't get it to compile with the get_style_context() method in the init_view method (I'm pretty sure the api has changed?) so I haven't found out how to finish this aspect

Any tips?

Also, when I use the same entries under the gtk::Entry{<entries>} I get an error on each of them

I'm using the latest version of rust gtk, and going back a few versions might be difficult

from relm.

antoyo avatar antoyo commented on June 29, 2024

@syntapy: The gtk-rs API indeed changed: when that's the case, please ask the questions to gtk-rs people (here's the place for relm questions only).
Anyway, that should work:

    fn init_view(&mut self) {
        use gtk::{CssProviderExt, StyleContextExt};
        let style_context = self.button.get_style_context();
        let style = include_bytes!("../style.css");
        let provider = gtk::CssProvider::new();
        provider.load_from_data(style).unwrap();
        style_context.add_provider(&provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
    }

from relm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.