dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.75k forks source link

Text bounces while invalidating the Drawable #6368

Open BharanikhumarSR opened 2 years ago

BharanikhumarSR commented 2 years ago

Description

I am creating custom control where the text of control needs to be updated dynamically. To update the text I have used the ICanvas DrawString in the GraphicsView. But when I'm invalidating the GraphicsView to update the text, I'm noticing bouncing of existing constant texts randomly. Note: This happens on setting a certain height, and width.

XAML

<ContentPage.Content>
        <local:SampleView VerticalOptions="Start"
                          HorizontalOptions="Start"
                          WidthRequest="400"
                          HeightRequest="300" />
  </ContentPage.Content>

C#

 public class SampleView : GraphicsView
 {
    readonly GraphicsDrawable graphicsDrawable;

    public SampleView()
        {
        graphicsDrawable = new GraphicsDrawable();
        this.Drawable = graphicsDrawable;
                this.StartInteraction += SampleView_StartInteraction;
                this.DragInteraction += SampleView_DragInteraction;
                this.EndInteraction += SampleView_EndInteraction;
    }
        private void SampleView_EndInteraction(object sender, TouchEventArgs e)
        {
        graphicsDrawable.SetTouchPoints(e.Touches[0]);
        this.Invalidate();
    }
        private void SampleView_DragInteraction(object sender, TouchEventArgs e)
        {
        graphicsDrawable.SetTouchPoints(e.Touches[0]);
        this.Invalidate();
    }
        private void SampleView_StartInteraction(object sender, TouchEventArgs e)
        {
        graphicsDrawable.SetTouchPoints(e.Touches[0]);
        this.Invalidate();
        }
    }

public class GraphicsDrawable : IDrawable
 {
        string xPoint;
    string yPoint;

    public void Draw(ICanvas canvas, RectF dirtyRect)
    {
        canvas.FillColor = Colors.CornflowerBlue;
        canvas.FillRectangle(dirtyRect);
        canvas.DrawString("Constant bouncing text", 10, 50, HorizontalAlignment.Left);

        if (xPoint != null)
           canvas.DrawString(string.Concat("Dynamic text: ", "X Point- ", xPoint, ", ", "Y Point-", yPoint), 10, 80, HorizontalAlignment.Left);
    }

    public void SetTouchPoints(Point point)
        {
        xPoint =  point.X.ToString();
        xPoint = xPoint.Substring(0, xPoint.IndexOf(".") + 2);
        yPoint = point.X.ToString();
        yPoint = yPoint.Substring(0, yPoint.IndexOf(".") + 2);
       }
}

Steps to Reproduce

  1. Create a new Maui App
  2. Create a new class, which extend the class from GraphicsDrawable
  3. Create a new class that implements IDrawable, and assign to this Drawable to GraphicsDrawable
  4. Draw a custom text using ICanvas DrawString.
  5. Invalidate the GraphicsView to redraw text while dragging the pointer.
  6. Notice that the text is bouncing while dragging. Label bouncing issue - windows.zip

Version with bug

Release Candidate 1 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows SDK 10.0.19041

Did you find any workaround?

No

Relevant log output

No response

XamlTest commented 2 years ago

Verified this issue with Visual Studio Enterprise 17.3.0 Preview 1.0 [32414.199.main]. Repro on Windows with above project.

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

PaulAndersonS commented 1 year ago

Any update on the reported issue? facing the same issue at our end. On Mouse hover in windows the Drawing gets called and the text jumps

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.6.0 Preview 4.0. Repro on Windows 11 with below Project: 6368.zip

anandhan-rajagopal commented 8 months ago

Any update on this issue?

Dokug commented 1 month ago

I face the same issue, would appreciate an update on this.