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

Scroll control doesn't work properly #2562

Closed
ttool22 opened this issue Apr 17, 2023 · 27 comments
Closed

Scroll control doesn't work properly #2562

ttool22 opened this issue Apr 17, 2023 · 27 comments
Labels
question v2 For discussions, issues, etc... relavant for v2

Comments

@ttool22
Copy link

ttool22 commented Apr 17, 2023

C# code is below

var scrollView = new ScrollView();
scrollView.X = 0;
scrollView.Y = 0;
scrollView.Width = Dim.Fill();
scrollView.Height = Dim.Fill();
scrollView.ContentSize = new Size(Console.WindowWidth, Console.WindowHeight * 2);


When I scroll down, I got this error(below), I have win 11 ;(

A clear and concCollection was modified; enumeration operation may not execute.
at System.Collections.Generic.List1.Enumerator.MoveNext() at Terminal.Gui.View.Redraw(Rect bounds) at Terminal.Gui.FrameView.Redraw(Rect bounds) at Terminal.Gui.View.Redraw(Rect bounds) at Terminal.Gui.ScrollView.Redraw(Rect region) at Terminal.Gui.View.Redraw(Rect bounds) at Terminal.Gui.Window.Redraw(Rect bounds) at Terminal.Gui.Application.RunMainLoopIteration(RunState& state, Boolean wait, Boolean& firstIteration) at Terminal.Gui.Application.RunLoop(RunState state, Boolean wait) at Terminal.Gui.Application.Run(Toplevel view, Func2 errorHandler)
at Terminal.Gui.MessageBox.QueryFull(Boolean useErrorColors, Int32 width, Int32 height, ustring title, ustring message, Int32

@tig tig added the bug label Apr 17, 2023
@BDisp
Copy link
Collaborator

BDisp commented Apr 17, 2023

I couldn't reproduce this. I see you are using the scroll inside a frame. On what Terminal.Gui version you are running, v1 or v2?

@tznind
Copy link
Collaborator

tznind commented Apr 17, 2023

Or if you are using the Nuget package? If so what version? Are you able to provide a link to your source code or give any more details. For example where do you launch the View, do you call Application.Init etc.

@ttool22
Copy link
Author

ttool22 commented Apr 18, 2023

I ha have 1.72 version with win 11, I have added scroll inside window
win.Add(scrollView);
Application.Run(win, (e) =>
{
MessageBox.ErrorQuery("Error", e.ToString(), "Ok");
return false;
});

@ttool22
Copy link
Author

ttool22 commented Apr 18, 2023

When I run my app on win 11, controls are mixed then I fix it by expanding the window with the mouse.

@BDisp
Copy link
Collaborator

BDisp commented Apr 18, 2023

I recommend you to download the current v1 from the repo, which is the develop branch and check if the issue still exist.

@ttool22
Copy link
Author

ttool22 commented Apr 18, 2023

image

I work with frame in scrollView, I fill it dinamic also I can't delete frame, I tryed FrameView.SubViews[0].Subviews.Clear(); but it throws error

FrameView FrameControl = new FrameView()
{
X = 0,
Y = 30
Width = 120,
Height = 0,
Border = new Border() { BorderStyle = BorderStyle.None, BorderThickness = new Thickness(1, 1, 1, 1) },
Visible = false,
Id = "Frame"
};
FrameControl .Add(new Label() { Y = brLines * 4, X = 12, Text = "1" });
FrameControl .Add(new Label() { Y = brLines * 4, X = 24, Text = "x", });
FrameControl .Add(new Label() { Y = brLines * 4, X = 36, Text = "2" });****

@ttool22
Copy link
Author

ttool22 commented Apr 18, 2023

When scroll controls become mixed then throw this error

@BDisp
Copy link
Collaborator

BDisp commented Apr 18, 2023

You can't remove the FrameView with FrameView.SubViews[0].Subviews.Clear(). If you added the FrameView into the ScrollView and want to remove it you have to use scrollView.Remove(FrameControl);.

@BDisp
Copy link
Collaborator

BDisp commented Apr 18, 2023

This scenario https://github.com/gui-cs/Terminal.Gui/blob/develop/UICatalog/Scenarios/ASCIICustomButton.cs use a FrameView inside a ScrollView. Maybe it can help you to check what you are doing wrong.

@tig
Copy link
Collaborator

tig commented Apr 18, 2023

This scenario https://github.com/gui-cs/Terminal.Gui/blob/develop/UICatalog/Scenarios/ASCIICustomButton.cs use a FrameView inside a ScrollView. Maybe it can help you to check what you are doing wrong.

I don't think that's a great sample. It's quite convoluted.

Character Map also shows this, but it too does a lot of other things.

@ttool22
Copy link
Author

ttool22 commented Apr 19, 2023

Neither do I, btw labels not clickable anymore in the latest version, lot of bugs...

@ttool22
Copy link
Author

ttool22 commented Apr 19, 2023

image

Why I have this problem on win 11?

@ttool22
Copy link
Author

ttool22 commented Apr 19, 2023

Controls are mixed by default

@BDisp
Copy link
Collaborator

BDisp commented Apr 19, 2023

Very strange. Do you are using Windows Terminal?

@ttool22
Copy link
Author

ttool22 commented Apr 19, 2023

Yes it is windows console

@ttool22
Copy link
Author

ttool22 commented Apr 19, 2023

image

When I scroll up, it throws this error in windows terminal, I don't have any clue how I can resolve it

@ttool22
Copy link
Author

ttool22 commented Apr 19, 2023

image

@ttool22
Copy link
Author

ttool22 commented Apr 19, 2023

image

Is the problem with windows driver or sth else?

@BDisp
Copy link
Collaborator

BDisp commented Apr 19, 2023

When I scroll up, it throws this error in windows terminal, I don't have any clue how I can resolve it

It seems that you are removing some views while Redraw and LayoutSubviews is running. You can't do it on Redraw. It's possible to you upload to your github a simple demo that reproduce this issue? If you want to test with another driver put Application.UseSystemConsole = true before Application.Init().

@ttool22
Copy link
Author

ttool22 commented Apr 19, 2023

Yes every one sec I have to use the same frameView with new data. The frameview contains some controls(labels and textfields). How can I do scroll and represent these dates in frameView? Can you write some lines with small example? The important thing is that frameView creates dinamically. My question is that how I can do scroll and fill data every sec in frameview?

@tznind
Copy link
Collaborator

tznind commented Apr 19, 2023

When updating Terminal.Gui from a Thread, the most important thing to do is to ensure any UI related code goes via Application.MainLoop.Invoke. This is how cross thread UI access is managed in Terminal.Gui. I can provide you with a more detailed example later but this may get you started.

@BDisp
Copy link
Collaborator

BDisp commented Apr 19, 2023

@tznind thanks for clarifying.
If you had said soon you were using threads, that would be more easy. If you are initializing the FrameView every one sec on a thread, then you have to do this inside the thread method:

Application.MainLoop.Invoke () => {
scrollView.Remove(FrameControl);
FrameView FrameControl = new FrameView()
{
X = 0,
Y = 30
Width = 120,
Height = 0,
Border = new Border() { BorderStyle = BorderStyle.None, BorderThickness = new Thickness(1, 1, 1, 1) },
Visible = false,
Id = "Frame"
};
FrameControl .Add(new Label() { Y = brLines * 4, X = 12, Text = "1" });
FrameControl .Add(new Label() { Y = brLines * 4, X = 24, Text = "x", });
FrameControl .Add(new Label() { Y = brLines * 4, X = 36, Text = "2" });
scrollView.Add(FrameControl);
};

@ttool22
Copy link
Author

ttool22 commented Apr 19, 2023

Thank you guys, it doesn't throws error but scroll does not work smoothly after some period

@ttool22
Copy link
Author

ttool22 commented Apr 19, 2023

I call it on this way Application.MainLoop.Invoke(async()=> { await RepresentData })}); RepresentData is a Task

@BDisp
Copy link
Collaborator

BDisp commented Apr 19, 2023

Thank you guys, it doesn't throws error but scroll does not work smoothly after some period

Because your are forcing it redrawing every one sec. Maybe you can increase that. Try this to enforce FrameControl disposing before recreating.

scrollView.Remove(FrameControl);
FrameControl.Dispose();
FrameControl=null;
...

@BDisp
Copy link
Collaborator

BDisp commented Apr 19, 2023

I call it on this way Application.MainLoop.Invoke(async()=> { await RepresentData })}); RepresentData is a Task

That's ok, but you still must use inside the RepresentData again the Application.MainLoop.Invoke to recreate the FrameView.

@tig tig added question v2 For discussions, issues, etc... relavant for v2 and removed bug labels Apr 19, 2023
@tig
Copy link
Collaborator

tig commented May 7, 2023

Doesn't seem like there's a bug here. Reopen if I'm wrong.

@tig tig closed this as completed May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question v2 For discussions, issues, etc... relavant for v2
Projects
None yet
Development

No branches or pull requests

4 participants