floem icon indicating copy to clipboard operation
floem copied to clipboard

`virtual_list` breaks when nested in an `v_stack` and styles as position absolute

Open dominikwilkowski opened this issue 1 year ago • 4 comments

This one took me a while to track down...

Given the virtual_list example we have in the repo now: https://github.com/lapce/floem/blob/7e78abb06eac12609d661728ce2fbb0064d5451d/examples/virtual_list/src/main.rs#L14-L32

All I have to do to break it is to nest the entire view inside a v_stack and make the list .position(Position::Absolute):

use floem::{
    reactive::create_signal,
+   style::Position,
    unit::UnitExt,
    view::View,
    views::virtual_list,
    views::Decorators,
+   views::{container, label, scroll, v_stack, VirtualListDirection, VirtualListItemSize},
};

fn app_view() -> impl View {
    let long_list: im::Vector<i32> = (0..1000000).collect();
    let (long_list, _set_long_list) = create_signal(long_list);

+   v_stack((
        container(
            scroll(
                virtual_list(
                    VirtualListDirection::Vertical,
                    VirtualListItemSize::Fixed(Box::new(|| 20.0)),
                    move || long_list.get(),
                    move |item| *item,
                    move |item| label(move || item.to_string()).style(|s| s.height(20.0)),
                )
                .style(|s| s.flex_col()),
            )
            .style(|s| s.width(100.0).height(100.pct()).border(1.0)),
        )
        .style(|s| {
            s.size(100.pct(), 100.pct())
                .padding_vert(20.0)
                .flex_col()
                .items_center()
+               .position(Position::Absolute)
+       }),
+   ))
}

fn main() {
    floem::launch(app_view);
}

And I get a list that looks like this: image

From what I can gather it looks like the list is thinking the items visible are none and so it loads non of them.

dominikwilkowski avatar Dec 16 '23 00:12 dominikwilkowski

To me it looks like the problem is that the v_stack isn't given a width or a height

EDIT: Just tested it and adding a size to the vstack does fix the problem. This isn't unique to the virtual list, this will happen to all views but it is strange that the virtual list draws anythign at all

jrmoulton avatar Dec 16 '23 20:12 jrmoulton

Interesting. The outside container does have a size which wraps the scroll so why would the outside stack have an impact here? In my case I can't give it a specific size as it uses flex to take the available space.

dominikwilkowski avatar Dec 16 '23 21:12 dominikwilkowski

I'm guessing that the discussion in https://discord.com/channels/946858761413328946/1179715246315806740 is the same problem as in your actual code.

I would try adding .flex_basis(0.0).min_height(0.0).flex_grow(1.0) to the scroll in your code

jrmoulton avatar Dec 16 '23 21:12 jrmoulton

Ohh I see now. The issue is that the outer container that you gave a size to has a percentage size not a size in pixels. Which means that it will inherit from the parent and if the parent doesn't have a size then it will just be 0

jrmoulton avatar Dec 16 '23 21:12 jrmoulton