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

Xilem requires sibling dependency on Winit and Masonry #584

Open
TechComet opened this issue Sep 7, 2024 · 7 comments
Open

Xilem requires sibling dependency on Winit and Masonry #584

TechComet opened this issue Sep 7, 2024 · 7 comments

Comments

@TechComet
Copy link

TechComet commented Sep 7, 2024

required import winit and masonry features without import him to project

default example
https://github.com/linebender/xilem/blob/main/xilem/examples/flex.rs

required to (without required winit and masonry import in project)

use xilem::{
    widget::{CrossAxisAlignment, MainAxisAlignment},
    view::{button, flex, label, sized_box, Axis, FlexExt as _, FlexSpacer},
    EventLoop, WidgetView, Xilem,
    ArcStr,
    error::EventLoopError,
};

/// A component to make a bigger than usual button
fn big_button(
    label: impl Into<ArcStr>,
    callback: impl Fn(&mut i32) + Send + Sync + 'static,
) -> impl WidgetView<i32> {
    sized_box(button(label, callback)).width(40.).height(40.)
}

fn app_logic(data: &mut i32) -> impl WidgetView<i32> {
    flex((
        FlexSpacer::Fixed(30.0),
        big_button("-", |data| {
            *data -= 1;
        }),
        FlexSpacer::Flex(1.0),
        label(format!("count: {}", data)).text_size(32.).flex(5.0),
        FlexSpacer::Flex(1.0),
        big_button("+", |data| {
            *data += 1;
        }),
        FlexSpacer::Fixed(30.0),
    ))
    .direction(Axis::Horizontal)
    .cross_axis_alignment(CrossAxisAlignment::Center)
    .main_axis_alignment(MainAxisAlignment::Center)
}

fn main() -> Result<(), EventLoopError> {
    let app = Xilem::new(0, app_logic);
    app.run_windowed(EventLoop::with_user_event(), "Centered Flex".into())?;
    Ok(())
}
@TechComet TechComet changed the title requered some features required import winit and masonry features without import him to project Sep 7, 2024
@DJMcNab
Copy link
Member

DJMcNab commented Sep 7, 2024

We do not have any examples written in Arabic.
Please explain what issue you're seeing, and what you're expecting to see. In its current form, this issue contains scant information.

I think you are trying to express that it's not possible to use Xilem without importing Masonry and winit into your project? This is a known issue, but it's not been a priority to address, as we're still in pre-alpha.
Pull requests to add targetted re-exports to make this possible are welcome, however.

Unfortunately, due to how Rust examples work, we cannot force them to use re-exports. This can be seen in this stackoverflow discussion. This might make a good clippy lint?

@TechComet
Copy link
Author

It's my problem in type
see issues my title

@DJMcNab
Copy link
Member

DJMcNab commented Sep 9, 2024

Which of the following things are you trying to report:

  1. It is impossible to use the examples without importing Masonry and Winit
  2. The imports in the examples aren't correct, but it is otherwise possible to use the examples as-is. Your code block suggests that this is the case, but you reference items which don't exist in it.

A PR to fix either of these would be welcome.

If it's either or none of these, please update your original issue to actually state what the issue is.
Your issue does not contain enough information to determine what you mean.

@TechComet
Copy link
Author

You need to add the properties masonry and wint to xielm and call them through it.

For example, adding this code to xielm:

pub type Axis = masonry::widget::Axis;

Now, to use Axis, you don't need to manually import masonry or wint in my project anymore. It will be enough to just import the xielm library and access everything through it.

Include only the absolutely necessary components for the majority of projects.

I hope I have made my point clear.


My English isn't great, so I've been using online translation tools. But they're not always the best.

@Philipp-M
Copy link
Contributor

These variables are already exported via xilem (see xilem/src/view/flex.rs).
You can use them with use xilem::view::Axis;. E.g. the example elm uses Axis (but for whatever reason not xilem::view::{CrossAxisAlignment, MainAxisAlignment};, I guess that could be improved e.g. via a PR).

This whole issue is known and e.g. discussed here.

@TechComet
Copy link
Author

What about EventLoopError?

@TechComet
Copy link
Author

I used this a while ago, it didn't work without masonry
Axis::Horizontal, CrossAxisAlignment::Center, MainAxisAlignment::Center.

I'm using the GitHub package directly.

If I get a Cargo Crate from GitHub, do I need to manually update the cache for the crate from GitHub in any way ?, or does it update automatically when building the application?

@DJMcNab DJMcNab changed the title required import winit and masonry features without import him to project Xilem requires sibling dependency on winit and masonry Sep 11, 2024
@DJMcNab DJMcNab changed the title Xilem requires sibling dependency on winit and masonry Xilem requires sibling dependency on Winit and Masonry Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants