by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    antoyo
    @antoyo
    By structs, you mean with the #[widget] attribute?
    Glade is not supported for now: you could use it, but you wouldn't have the bindings between properties and model attributes.
    Justin Wood
    @ankhers
    I did. Thanks. I will go with the widget attribute for now.
    Justin Wood
    @ankhers
    If I had a start button and wanted to play a sound repeatedly until I pressed the stop button, what would that look like in relm?
    antoyo
    @antoyo
    @ankhers: You can have buttons with event handlers like explained there: https://relm.antoyo.xyz/documentation/tutorial/02-counter
    Justin Wood
    @ankhers
    I was thinking about putting a playing: bool field in my model. Have a message setup on the start and stop buttons. The start button would set the playing field to true and then play the first sound. But I'm really not sure if this all happens on the main thread. So would I need to start a thread in order to do it repeatedly?
    Sorry, I sent that message before fully writing out my question. I don't really know why.
    antoyo
    @antoyo
    It depends on your sound library. Does it allow to play a sound repetedly?
    Justin Wood
    @ankhers
    Well, I used that to simplify. I am going to be playing a random sound.
    antoyo
    @antoyo
    If you know when your sound ends, maybe you can just send a message back to play the sound again?
    Justin Wood
    @ankhers
    Yes. that was what I was thinking, I just wasn't sure how to send the message back.
    antoyo
    @antoyo
    The Relm object has a stream() method (https://docs.rs/relm/0.20.0/relm/struct.Relm.html#method.stream) which returns an EventStream which has an emit() method (https://docs.rs/relm/0.20.0/relm/struct.EventStream.html#method.emit) to send a message.
    Justin Wood
    @ankhers
    Awesome. Thank you!
    antoyo
    @antoyo
    You can save this Relm object by cloning it into your Model in the model() method.
    Devin Brite
    @dwbrite

    How can I call a set_xyz function with multiple parameters from inside the view! macro? More specifically I'm trying to use set_default_size(_, _).

    My current non-working code looks like:
    gtk::Window { default_size: (1280, 720), ... }

    antoyo
    @antoyo
    @dwbrite: It's unsupported for now (antoyo/relm#59). Sometimes, you can get away by using different properties (like http://gtk-rs.org/docs/gtk/trait.WidgetExt.html#tymethod.set_property_height_request). If there's none, you'll have to call the function in init_view().
    Devin Brite
    @dwbrite
    Cool, thanks - that works. I did figure to try it in init_view(), but set_default_size() doesn't really work if you call it too late.
    ido77778
    @ido77778
    I am intending to use a grid and place a list (TreeView) in it. Both the grid and the list are implemented using relm, but not using the widget attribute and the view! macro, since they are unsupported as far as I understand. Anyway, I wanted to ask how can I instance exactly the TreeView widget so that I can attach it to the grid? Since it is a relm widget, there's no new() function, so I'm not sure what to do.
    That should solve your issue.
    ido77778
    @ido77778
    Oh my, I can't believe I missed it. :) But just out of curiosity and for the future, how do you instance relm widgets without resorting to the view! macro?
    antoyo
    @antoyo
    @ido77778: You can call add_widget (https://github.com/antoyo/relm/blob/master/relm-examples/tests/communication.rs#L258) to add a relm widget to a container.
    emmanueltouzery
    @emmanueltouzery
    Hi, I wonder if I can directly add a ComboBoxText with entry without using init_view
                gtk::ComboBoxText {
                    hexpand: true,
                },
    obviously this adds a ComboBoxText which does NOT have an entry
    gtk::ComboBoxText has ::new and ::new_with_entry
    antoyo
    @antoyo

    @emmanueltouzery You should be able to do so with construct properties. Something like:

    gtk::ComboBoxText({has_entry: true}) {
        hexpand: true,
    }

    These properties are currently not checked at compile-time, they're checked at run-time by gtk+ itself, so check stderr if that doesn't work.
    When I switch to using builders, it will be checked at compile-time.

    emmanueltouzery
    @emmanueltouzery
    this works \o/
    relm keeps amazing me :+1:
    Poly
    @PolyMeilex

    How would I implement 2-way communication witch parent <-> child components setup, let's say that my child has 3 sliders and I have to get values of those in a parent component.
    Is this a recommended way?

    1. Send give_me_data event from parent to child
    2. Recrive event in child
    3. Send returned_data envent from child to parent

    I'm using this setup, but it feels kinda overkill for such a simple task

    antoyo
    @antoyo
    @PolyMeilex: I'm not sure how you do it, but there's an example here: https://github.com/antoyo/relm/blob/master/relm-examples/tests/communication-attribute.rs#L166
    Poly
    @PolyMeilex
    I do it in a way less elegant way, but I think the concept is the same, I have to bubble up events to parent
    Thanks attribute way is a lot cleaner
    emmanueltouzery
    @emmanueltouzery

    Hi, I'm wondering if there's a better way to retrieve data from a dialog when the user clicks 'save': I have a relm component that I add to a dialog:

            // need to keep a reference else event processing dies when
            // the component gets dropped
            self.model.server_add_edit_dialog = Some(
                relm::init::<ServerAddEditDialog>((
                    self.model.db_sender.clone(),
                    server.unwrap().project_id,
                    server.cloned(),
                ))
                .expect("error initializing the server add edit modal"),
            );
            let dialog_contents = self.model.server_add_edit_dialog.as_ref().unwrap();
            dialog
                .get_content_area()
                .pack_start(dialog_contents.widget(), true, true, 0);
            dialog.add_button("Cancel", gtk::ResponseType::Cancel);
            let save = dialog.add_button("Save", gtk::ResponseType::Ok);
            save.get_style_context().add_class("suggested-action");
            dialog.connect_response(move |d, r| {
                d.close();
                if r == gtk::ResponseType::Ok {
                    // handle the action...
                }
            });
            dialog.show_all();

    so, the component does not get notified directly when the dialog is closed, it's the parent window that opened the dialog that gets notified in the connect_response. What I would do is a little roundabout.. in the connect_response handler, I would send a signal to the dialog component: dialog_contents.stream().emit(DialogSaveTriggered), then in the component itself, when I get that message, I'd gather the values for all the fields in the dialog, and emit DialogSaved with the value for all the fields. Is there a simpler/more idiomatic way?

    antoyo
    @antoyo
    @emmanueltouzery: I'm not sure if that would help, but one idea I had was to create a relm widget for Dialog. Do you think that would help you?
    emmanueltouzery
    @emmanueltouzery
    relm widget for dialog.. maybe, i guess it would wrap that. but in the end what i plan on doing is not really that bad. it just feels a little verbose, back-and-forth. but it's simple and i'm pretty sure it'll work without issues
    ok if there's no specific pattern i'll go with the approach i had in mind then
    emmanueltouzery
    @emmanueltouzery
    I'm asking just in case, maybe there is a known issue related to this...
    In one my screens, I put visible: false in my view! next to some components and there is no effect
    i know this works in general
    right now i'm baffled how come this has no effect in my case. If I change the other attributes, they work, this one somehow doesn't work (as confirmed by the gtk inspector.. and if i change visible to false in the gtk inspector it works as expected)
    i'm aware there are a million reasons why it could come to that, i'm pretty sure the issue is on my side.. still asking in case there's a known gotcha related to that
    i'll try to make a small test-case to reproduce the issue otherwise. but i'm 80% sure the issue is on my side
    emmanueltouzery
    @emmanueltouzery
    although i'll more likely work around it by just calling set_visible() in the init_view() :(
    now that's interesting.. doing that, calling set_visible(false) in the init_view(), ALSO has no effect
    i'm adding the contents in a dialog. i'll try to see if that's connected maybe
        let dialog = gtk::DialogBuilder::new()
            .use_header_bar(1)
            .default_width(width)
            .default_height(height)
            .title(title)
            .modal(true)
            .build();
    
        dialog
            .get_content_area()
            .pack_start(dialog_contents.widget(), true, true, 0); // <--- adding it here
    emmanueltouzery
    @emmanueltouzery
    right. so i was doing dialog.show_all()
    i thought show_all would just call show recursively. so, mystery solved, sorry for the noise!
    emmanueltouzery
    @emmanueltouzery
    hi, the way to set up radio buttons in gtk-rs is very non-relmish.. declare several RadioButtons in the view! then from the second to the last, in the init_view, one must do.. self.radioN.join_group(Some(&self.radio1));. Unless there's a nicer way that I've missed?
    antoyo
    @antoyo
    @emmanueltouzery: There seems to be missing methods in gtk-rs, but maybe you could do something like: gtk::RadioButton({group: self.first_radio_button.get_group()}) {} but I'm not sure that would work.