Skip to content

[Proposal] DrawingView #108

Closed

Description

@TheCodeTraveler

DrawingView

  • Proposed
  • Prototype
  • Implementation
    • iOS Support
    • Android Support
    • macOS Support
    • Windows Support
  • Unit Tests
  • Sample
  • Documentation

Summary

Allows you to draw one or multiple lines on a canvas

Detailed Design

DrawingView.shared.cs

public class DrawingView : View
{
  public static readonly BindableProperty ClearOnFinishProperty;
  public static readonly BindableProperty MultiLineModeProperty;
  public static readonly BindableProperty LinesProperty;
  public static readonly BindableProperty DrawingLineCompletedCommandProperty;
  public static readonly BindableProperty DefaultLineColorProperty;
  public static readonly BindableProperty DefaultLineWidthProperty;
  
  public event EventHandler<DrawingLineCompletedEventArgs>? DrawingLineCompleted;
  
  public Color DefaultLineColor { get; set; }
  public float DefaultLineWidth { get; set; }
  public ICommand? DrawingLineCompletedCommand { get; set; }
  public ObservableCollection<Line> Lines { get; set; }
  public bool MultiLineMode { get; set; }
  public bool ClearOnFinish { get; set; }
  
  public Stream GetImageStream(double imageSizeWidth, double imageSizeHeight);
  public static Stream GetImageStream(IEnumerable<Line> lines, Size imageSize, Color backgroundColor);
}

Usage Syntax

XAML Usage

<views:DrawingView x:Name="DrawingViewControl" 
   BackgroundColor="LightGray" 
   HeightRequest="200"
   DefaultLineColor="Red"
   DefaultLineWidth="3"
   Lines="{Binding Lines, Mode=TwoWay}"
   ClearOnFinish="{Binding Source={x:Reference ClearOnFinish}, Path=IsToggled}"
   MultiLineMode="{Binding Source={x:Reference MultiLineMode}, Path=IsToggled}"/>

C# Usage

new DrawingView
{
   BackgroundColor = Colors.LightGray,
   HeightRequest = 200,
   DefaultLineColor = Colors.Red,
   DefaultLineWidth = 3
}.Bind(DrawingView.Lines, nameof(ViewModel.Lines))
 .Bind(DrawingView.ClearOnFinish, nameof(ViewModel.ShouldClear))
 .Bind(DrawingView.MultiLineMode, nameof(ViewModel.ShouldAllowMultiLine));

Alternatives

Might be a duplicate of Microsoft.Maui.Graphics?

Unresolved Questions

Is DrawingView still necessary? Or has it been superseded by Microsoft.Maui.Graphics?

Activity

  1. added
    proposalA fully fleshed out proposal describing a new feature in syntactic and semantic detail
    on Sep 28, 2021
  2. added this to the v1.0.0 milestone on Sep 28, 2021
  3. VladislavAntonyuk commented on Sep 28, 2021

    @VladislavAntonyuk
    Contributor

    Duplicate #4

  4. VladislavAntonyuk commented on Sep 28, 2021

    @VladislavAntonyuk
    Contributor

    DrawingView allows to draw any shape (draw the line by finger), while Maui Graphics has predefined shapes: lines, rectangles.

  5. TheCodeTraveler commented on Sep 28, 2021

    @TheCodeTraveler
    CollaboratorAuthor

    @jsuarezruiz Could you confirm whether or not Microsoft.Maui.Graphics will make DrawingView obsolete?

  6. VladislavAntonyuk commented on Oct 6, 2021

    @VladislavAntonyuk
    Contributor

    @jsuarezruiz maybe DrawingView can be a part of Maui Graphics? Or is it not enough stable yet?

  7. jsuarezruiz commented on Oct 7, 2021

    @jsuarezruiz
    Contributor

    I think could be part of the Toolkit or maybe also of .NET MAUI Graphics. What does make sense to me is directly use Maui Graphics in GraphicsView. Could simplified the code and at the end benefits also Graphics.

  8. TheCodeTraveler commented on Jan 6, 2022

    @TheCodeTraveler
    CollaboratorAuthor

    May be duplicate of GraphicsView: dotnet/maui#923

  9. VladislavAntonyuk commented on Jan 6, 2022

    @VladislavAntonyuk
    Contributor

    @brminnick I don't think it is a duplicate.
    Maui.Graphics provides control to draw - GraphicsView (consider it to be a paper), But DrawingView actually draws on it (like a pencil).
    We can use controls from Maui.Graphics (https://github.com/dotnet/Microsoft.Maui.Graphics/blob/main/src/Microsoft.Maui.Graphics/Android/NativeGraphicsView.cs) instead of implementing our own (https://github.com/VladislavAntonyuk/Maui/commit/23503b47026f1e99416f8a38f5d3a717dbfc2fa1#diff-ba611d8a56be8ce1566b9bd46df26cd055b8fbc3fb05df9560d7ecb8cb48ecbcR24)

  10. ghost added
    championA member of the .NET MAUI Toolkit core team has chosen to champion this feature
    on Feb 3, 2022
  11. ghost removed on Feb 3, 2022
  12. ghost added
    approvedThis Proposal has been approved and is ready to be added to the Toolkit
    on Mar 4, 2022
  13. ghost added
    help wantedThis proposal has been approved and is ready to be implemented
    on Mar 4, 2022
  14. ghost reopened this on Apr 19, 2022
  15. ghost reopened this on Apr 27, 2022
  16. ghost removed on Apr 27, 2022
  17. ghost closed this as completedon Apr 27, 2022
  18. locked and limited conversation to collaborators on Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

approvedThis Proposal has been approved and is ready to be added to the ToolkitchampionA member of the .NET MAUI Toolkit core team has chosen to champion this featuredocumentation approvedproposalA fully fleshed out proposal describing a new feature in syntactic and semantic detail

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions