Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I flex a collection of elements to be the same width/fill remaining space? #746

Closed
WilliamVenner opened this issue Feb 24, 2021 · 7 comments · Fixed by #1044
Closed
Labels
feature New feature or request

Comments

@WilliamVenner
Copy link

How could I flex these buttons to fill the remaining space (designated by the red square)?

Code

Container::new(Column::new()

    .push(

        Container::new(Column::new()
        .align_items(Align::Center)
        .width(Length::Shrink)

        .push(
            Image::new(image::Handle::from_memory(include_bytes!("../assets/gmpublisher.png").to_vec()))
            .width(Length::Units(128))
        )

        .push(
            Text::new(format!("gmpublisher v{} by Billy", env!("CARGO_PKG_VERSION")))
            .horizontal_alignment(HorizontalAlignment::Center)
            .color(Color::WHITE)
        )

        .push(
            Landing::button(star_btn, "Star on GitHub")
            .on_press(Message::GitHubStar)
        )

        .push(
            Landing::button(new_addon_btn, "New Addon")
            .on_press(Message::NewAddon)
        )

        .push(
            Landing::button(open_addon_btn, "Open Addon")
            .on_press(Message::OpenAddon)
        )

        .push(
            Landing::button(my_workshop_btn, "My Workshop")
            .on_press(Message::MyWorkshop)
        )

        .push(
            Landing::button(settings_btn, "Settings")
            .on_press(Message::Settings)
        )

        .push(
            Landing::button(help_btn, "Help")
            .on_press(Message::Help)
        )

        .push(
            Landing::button(close_btn, "Close")
            .on_press(Message::Close)
        )

    )
    .width(Length::Fill)
    .height(Length::Fill)
    .center_x()
    .center_y()

    )

    .push(
        Column::new()
        .align_items(Align::Center)
        .width(Length::Fill)

        .push(
            Text::new(
                match &app_vars.gmod {
                    Some(gmod) => gmod.to_string_lossy().to_string(),
                    None => String::from("Garry's Mod installation directory not found! Add it in Settings.")
                }
            )
            .horizontal_alignment(HorizontalAlignment::Center)
            .color(Color::WHITE)
        )

    )

)

.width(Length::Fill)
.height(Length::Fill)
.center_x()
.center_y()
.padding(20).into()

Result

image

@WilliamVenner WilliamVenner changed the title How can I flex a collection of elements to be the same width? How can I flex a collection of elements to be the same width/fill remaining space? Feb 24, 2021
@Kaiden42
Copy link
Contributor

Have you tried to set the width of the buttons to Length::Fill?

Button::new(&mut state, "Press Me!").width(Length::Fill)

@WilliamVenner
Copy link
Author

Yes, this causes them to fill the width of the entire window.

@hangleang
Copy link

Just wrap all those buttons in a button group (Container) and give the container a specified width, then set all buttons width to Length::Fill.

@WilliamVenner
Copy link
Author

I don't want to specify a fixed width.

In HTML/CSS you can just do this:

<style>
    #container {
        display: flex;
    }
    #container .btn {
        flex: 1;
    }
</style>
<div id="container">
    <div class="btn">...</div>
    <div class="btn">...</div>
    <div class="btn">...</div>
    ...
</div>

No need to specify any widths. The .btns will just fill the remaining space in their #container.

Druid is capable of this, which apparently the flex component of iced is inspired by: linebender/druid#1608 (comment)

@hecrj hecrj added the feature New feature or request label Feb 27, 2021
@ruza-net
Copy link

ruza-net commented Mar 4, 2021

Is the fix of this particularly hard? Can I perhaps contribute in any way (I haven't yet looked at the inner workings of iced)?

I'm doing a school project with iced which depends on this functionality, and I need to know if this has potential to land in time, or if I'm better off migrating to druid.

@WilliamVenner
Copy link
Author

You might be better off with using Tauri, I found the data model of Druid very complex and the documentation is very poor. I don't think we're GUI yet, at least for a full blown application.

@Surferlul
Copy link

How do you fix this, now that #1735 has reverted #1044?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants