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

Fix first cell not showing sometimes #110

Merged
merged 1 commit into from Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/fxmisc/flowless/Navigator.java
Expand Up @@ -146,6 +146,8 @@ private void cropToNeighborhoodOf( int itemIndex ) {
int begin = Math.max( 0, getFirstVisibleIndex() );
int end = Math.max( itemIndex, getLastVisibleIndex() );
positioner.cropTo( Math.min( begin, itemIndex ), end+1 );
// Needed for correct layout in some situations
sizeTracker.getAverageLengthEstimate();
}

@Override
Expand Down
@@ -0,0 +1,33 @@
package org.fxmisc.flowless;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.Label;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class FirstCellCreationAndLayoutTest extends FlowlessTestBase
{
private VirtualFlow<Label, ?> flow;

@Override
public void start(Stage stage)
{
Label first = new Label( "First Item" );
Label second = new Label( "Second Item" );
ObservableList<Label> items = FXCollections.observableArrayList( first, second );
flow = VirtualFlow.createVertical( items, Cell::wrapNode );

stage.setScene( new Scene( flow, 200, 100 ) );
stage.show();
}

@Test
public void does_the_first_cell_layout_correctly()
{
assertEquals( 0, flow.getFirstVisibleIndex() );
}
}