palexdev / VirtualizedFX

GNU Lesser General Public License v3.0
46 stars 4 forks source link

SimpleVirtualFlow deprecated, what should be used? #13

Closed JustTalDevelops closed 4 months ago

JustTalDevelops commented 1 year ago

Heyo,

I noticed the SimpleVirtualFlow is deprecated now. While it does seem to work for my use case, I just want to make sure I'm not relying on something that is not intended to be maintained and also using what is expected. What is it's replacement? How can I use it?

Thanks!

palexdev commented 1 year ago

Docs

brr53 commented 1 year ago

@palexdev why is it deprecated? Is there any use for it anymore? Would appreciate if you could offer some insight so we can contribute better to the repo.

palexdev commented 1 year ago

@JustTalDevelops @brr53 Sorry! I didn't notice the edits. Yes, SimpleVirtualFlow is deprecated, and I won't offer support, not because I don't want to help, but it was a bit more complicated in certain areas and I can't exactly remember all its caveats/mechanisms It's deprecated in favor of the new implementation VirtualFlow which is essentially better in anything, performance, code organization, documentation. I'm planning on removing SimpleVirtualFlow as soon as MaterialFX doesn't require it anymore.

I highly suggest you to use the new implementation. In combination with the VirtualScrollPane you can create a full ListView in a few lines of code ;)

Also, in the past days, I've been thinking about some major changes to all new virtualized containers. I plan on changing how cells are updated when changes occur in the data structure. The current algorithm is pretty good, but I fear it may not be flawless. I may change the Cell API by adding a method to check whether a cell needs to be updated or not. I'm still thinking though

brr53 commented 1 year ago

Thank you @palexdev

I will let you report any flaws if I find them.

I've noticed you have a discord link on the repo. But it's expired. Do you have the active one or mind sharing your discord? Thank you.

palexdev commented 1 year ago

Thank you @palexdev

I will let you report any flaws if I find them.

I've noticed you have a discord link on the repo. But it's expired. Do you have the active one or mind sharing your discord? Thank you.

Ah yes, at the time I didn't know they would expire Since no one ever joined even when it was ok, I didn't bother updating it and I closed the channel. I should update the README when I got some spare time

JustTalDevelops commented 1 year ago

Thanks for the timely response, appreciate your work on this project and VirtualizedFX loads.

I tried VirtualFlow - seems it is a drop in replacement for SimpleVirtualFlow. However the only issue I noticed is with a lot of cells, it will start to skip a bunch of them basically. Here's a reproduceable test:

    @Override
    public void start(Stage primaryStage) {
        var input = new ArrayList<String>();
        for (int i = 0; i < 200_000; ++i) {
            input.add("Item " + (i + 1));
        }

        var items = FXCollections.observableArrayList(input);
        var flow = new VirtualFlow<>(
                FXCollections.observableArrayList(items),
                LabelCell::new,
                Orientation.VERTICAL
        );

        var scrollPane = flow.wrap();
        scrollPane.setPrefWidth(500);
        scrollPane.setPrefHeight(500);

        var vbox = new VBox(scrollPane);
        var scene = new Scene(vbox, scrollPane.getPrefWidth(), scrollPane.getPrefHeight());

        primaryStage.setTitle("VirtualizedFX Layout Test (200K items)");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

    class LabelCell extends HBox implements Cell<String> {

        protected final Label label;

        public LabelCell(String s) {
            this.label = new Label(s);
            this.setStyle("-fx-background-color: #808080");
            getChildren().add(this.label);
        }

        @Override
        public Node getNode() {
            return this;
        }

        @Override
        public void updateItem(String s) {
            this.label.setText(s);
        }

    }

If you try scrolling down with the scroll wheel, it will skip 2000 items a time in this case. Is there any way I can ensure it scrolls an even amount? Thanks again.

palexdev commented 1 year ago

By "skip" you mean it just scrolls past them? Are they correctly visualized though?

Edit: did a bit of math, you have to setup the scroll pane speed too, it's not automatic By default every time you scroll in any direction, the scroll bars will increment the position by 0.01% You have 200_000 elements, cells of size 32px for a total length of 64_000_000px. Each time you scroll by 0.01% it advances by 64_000px (64_000_000px * 0.01), divide by the cell size and you skip exactly 2000 cells (64_000px / 32)

Anyway, math aside, you can set the speed to suit your needs by using the VSPUtils class. Make sure to read the method docs as there are three different parameters