Skip to content

Nested view! macros use inner view as outer root #305

@msrd0

Description

@msrd0

I have the following code:

#[widget]
impl Widget for MyWidget {
	// ...
	view! {
		gtk::Box {
			orientation: Orientation::Horizontal,
			spacing: 10,

			// ...

			gtk::ToolButton {
				hexpand: false,
				clicked => Msg::Delete,
				icon_widget: view! {
					gtk::Image {
						icon_name: Some("edit-delete"),
						icon_size: IconSize::Button
					}
				}
			}
		}
	}
}

At runtime, the entire widget is not rendered, and instead I see this message on the terminal:

(myapp:104508): Gtk-WARNING **: 19:28:54.676: Attempting to add a widget with type GtkImage to a container of type GtkBox, but the widget is already inside a container of type GtkButton, please remove the widget from its existing container first.

The macro outputs the following code, which I believe is wrong:

impl Widget for MyWidget {
    // ...
    type Root = gtk::Image;
    fn root(&self) -> Self::Root {
        self.widgets.gtkimage1.clone()
    }
}

The widget is added inside a gtk::Box in another widget, but what I believe is happening is that only the image in the inner view! macro is being added, instead of the outer view! macro.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions