ITextView.TextAreaViewportBounds doesn't get the visible portion of text area correctly

SyntaxEditor for WPF Forum

Posted 4 years ago by James Zheng
Version: 15.1.0624
Platform: .NET 4.5
Environment: Windows 10 (64-bit)
Avatar

Hi Actipro,

It seems that TextAreaViewportBounds doesn't give me the correct visible horizontal bound when horizonal scroll bar is visible.

Steps to reproduce this issue:

1. Run sample project

2. Navigate to "SyntaxEditor - General QuickStarts" >> "Adornments 7 - Watermark".

3. Zoom the editor until you can see the horizonal bar becomes visible.

4. Make the sample application's window size smaller by half.

5. You can see the 'Watermark' word stays at the center of the editor. This is correct.

6. Scroll the horizontal scroll bar

7. The 'Watermark' word moves with scroll bar and no longer stays at the center of the editor.

Best Regards,

James Zheng

[Modified 4 years ago]

Comments (4)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi James,

In this scenario, the TextAreaViewportBounds is working properly since that is intended to give the bounds of the viewport where the text area is located.  The bounds doesn't factor in scroll position, nor is it supposed to.  But this sample should factor the horizontal scroll position in.  You can fix it with code like this in WatermarkAdornmentManager.OnViewTextAreaLayout:

// Get the horizontal scroll
IEditorView view = e.View as IEditorView;
double firstVisibleX = (view != null ? view.FirstVisibleX : 0.0);

// Determine the center of the text area viewport
Rect textAreaViewportBounds = e.View.TextAreaViewportBounds;
Point center = new Point(firstVisibleX + textAreaViewportBounds.Width / 2 / e.View.SyntaxEditor.ZoomLevelAnimated,
    textAreaViewportBounds.Height / 2 / e.View.SyntaxEditor.ZoomLevelAnimated);


Actipro Software Support

Posted 4 years ago by James Zheng
Avatar

Hi Actipro,

Thanks for prompt response. Your suggestion to use FirstVisibleX fixed my issue. However, there is another issue with the watermark display.

Steps to reproduce:

1. Run sample project

2. Navigate to "SyntaxEditor - General QuickStarts" >> "Adornments 7 - Watermark".

3. Drag the window’s horizontal border up and down.

4. You can see the 'Watermark' word adjusts itself to fit into the center of the window.

5. Drag the window’s vertical border left and right.

6. However, you can see the 'Watermark' word doesn’t adjust itself to fit into the center of the window.

After some debugging, it’s found that the “OnViewTextAreaLayout” is not called when adjusting the vertical border.

Regards,

James Zheng

[Modified 4 years ago]

Answer - Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi James,

Correct since in that case the view text area doesn't need a layout (the existing view lines are valid).  What you can do is in the WatermarkAdornmentManager, also attach to this:

view.VisualElement.SizeChanged += VisualElement_SizeChanged;

And put a corresponding detach in the OnClosed method.  In that handler, look for the scenario e.WidthChanged and !e.HeightChanged, and then execute the watermark layout logic again in that case.  You'll want to basically move all the logic currently in OnViewTextAreaLayout to a new method that can be called from OnViewTextAreaLayout and VisualElement_SizeChanged.  That should fix the problem.


Actipro Software Support

Posted 4 years ago by James Zheng
Avatar

Thanks!

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.