xilem icon indicating copy to clipboard operation
xilem copied to clipboard

Xilem requires sibling dependency on Winit and Masonry

Open TechComet opened this issue 1 year ago • 7 comments

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 avatar Sep 07 '24 10:09 TechComet

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?

DJMcNab avatar Sep 07 '24 10:09 DJMcNab

It's my problem in type see issues my title

TechComet avatar Sep 07 '24 11:09 TechComet

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.

DJMcNab avatar Sep 09 '24 07:09 DJMcNab

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.

TechComet avatar Sep 10 '24 08:09 TechComet

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.

Philipp-M avatar Sep 10 '24 08:09 Philipp-M

What about EventLoopError?

TechComet avatar Sep 10 '24 08:09 TechComet

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?

TechComet avatar Sep 10 '24 15:09 TechComet

There are plans to restruccture the crates quite a bit. We can come back to talking about re-exporting gaps when the crate hierarchy has stabilized more.

xStrom avatar May 21 '25 11:05 xStrom