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

ListView does not render correctly before focus #2705

Closed
Pieshka opened this issue Jun 8, 2023 · 2 comments · Fixed by #2707
Closed

ListView does not render correctly before focus #2705

Pieshka opened this issue Jun 8, 2023 · 2 comments · Fixed by #2707
Labels

Comments

@Pieshka
Copy link

Pieshka commented Jun 8, 2023

Describe the bug
When I switch from one window, to another that has not yet been displayed, the ListView is rendered incorrectly. The moment I focus on the window, everything gets fixed. I have noticed that the problem is present as of this commit and has not been fixed in either v1.12.1 or the develop branch.

To Reproduce
Steps to reproduce the behavior:

  1. use the code attached below
  2. select the second window from the bar menu
  3. the part of the ListView above the buttons is unrendered

Expected behavior
ListView will render correctly without having to focus the window.

Screenshots

image

Additional context
The code I used:

List<string> list = new List<string>();
for (int i = 0; i < 100; i++) 
{
    list.Add("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec non velit dignissim, mollis sem id, aliquet nisl.");
}

Application.Init();
Toplevel topLvl = Application.Top;
Window topWindow = new Window("Top Window");
Window firstWindow = new Window("First Window");
Window secondWindow = new Window("Second Window");
MenuBar toolBar = new MenuBar(
    new MenuBarItem[] {
        new MenuBarItem("Window Switcher", new MenuItem[]
        {
            new MenuItem("First Window","",()=>{
                topWindow.RemoveAll();
                topWindow.Add(firstWindow);
            }),
            new MenuItem("Second Window","",()=>{
                topWindow.RemoveAll();
                topWindow.Add(secondWindow);
            })
        })
    });

/* Second Window Content */
ListView newLV = new ListView(list)
{
    X = 2,
    Y = 2,
    Height = Dim.Fill(3),
    Width = Dim.Fill(3),
    ColorScheme = Colors.Dialog,
    AllowsMarking = false,
    AllowsMultipleSelection = false,
    TextAlignment = TextAlignment.Justified
};
Button refreshB = new Button("Refresh") { X = 2, Y = Pos.Bottom(secondWindow) - 5, Enabled = true };
Button addNewB = new Button("Add New") { X = Pos.Right(refreshB) + 1, Y = Pos.Bottom(secondWindow) - 5, Enabled = true };
Button deleteB = new Button("Delete") { X = Pos.Right(addNewB) + 1, Y = Pos.Bottom(secondWindow) - 5, Enabled = true };

secondWindow.Add(newLV, refreshB, addNewB, deleteB);

topWindow.Add(firstWindow);
topLvl.Add(toolBar);
topLvl.Add(topWindow);
Application.Run();
Application.Shutdown();
@BDisp
Copy link
Collaborator

BDisp commented Jun 8, 2023

Since you are using RmoveAll you have to recreate both Window. Instead of creating outside the menu bar, create it inside the menu or create a method where the menu will call it. Also you have to use firstWindow.Dispose() and secondWindow.Dispose(). If you running this on the UICatalog the Debug.Assert (inst.WasDisposed); will throw.

@Pieshka
Copy link
Author

Pieshka commented Jun 9, 2023

To be precise, I actually write my application as in the code below, i.e. each custom window is a separate class, and in the MenuBar I create new instances of windows, rather than using the already instantiated ones. I rewrote my test code just like this and the problem still occurs - now it's even every time I change windows you can see the unrendered part of the list. After adding Dispose, nothing improved either. In version 1.9.0 this problem does not occur, even without Dispose.

public class SecondWindow : Window
{
    public SecondWindow(string title) : base(title)
    {
        InitializeControls();
    }
    private void InitializeControls()
    {
        List<string> list = new List<string>();
        for (int i = 0; i < 100; i++)
        {
            list.Add("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec non velit dignissim, mollis sem id, aliquet nisl.");
        }

        ListView newLV = new ListView(list)
        {
            X = 2,
            Y = 2,
            Height = Dim.Fill(3),
            Width = Dim.Fill(3),
            ColorScheme = Colors.Dialog,
            AllowsMarking = false,
            AllowsMultipleSelection = false,
            TextAlignment = TextAlignment.Justified
        };
        Button refreshB = new Button("Refresh") { X = 2, Y = Pos.Bottom(this) - 5, Enabled = true };
        Button addNewB = new Button("Add New") { X = Pos.Right(refreshB) + 1, Y = Pos.Bottom(this) - 5, Enabled = true };
        Button deleteB = new Button("Delete") { X = Pos.Right(addNewB) + 1, Y = Pos.Bottom(this) - 5, Enabled = true };
        Add(newLV, refreshB, addNewB, deleteB);
    }
}
public class Program
{
    static void Main(string[] args)
    { 
        Application.Init();
        Toplevel topLvl = Application.Top;
        Window topWindow = new Window("Top Window");
        MenuBar toolBar = new MenuBar(
            new MenuBarItem[] {
                new MenuBarItem("Window Switcher", new MenuItem[]
                {
                    new MenuItem("First Window","",()=>{
                        foreach (View child in topWindow.Subviews)
                            child.Dispose();
                        topWindow.RemoveAll();
                        topWindow.Add(new Window("First Window"));
                    }),
                    new MenuItem("Second Window","",()=>{
                        foreach (View child in topWindow.Subviews)
                            child.Dispose();
                        topWindow.RemoveAll();
                        topWindow.Add(new SecondWindow("Second Window"));
                    })
                })
            });
        topLvl.Add(toolBar);
        topLvl.Add(topWindow);
        Application.Run();
        Application.Shutdown();
    }
}

issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants