Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Adding comments to Update CheckBoxHandler.cs #138

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 68 additions & 57 deletions src/GraphicsControls/Handlers/CheckBox/CheckBoxHandler.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,84 @@
using System.Linq;
using System.Linq;

namespace Microsoft.Maui.Graphics.Controls
{
public class CheckBoxHandler : GraphicsControlHandler<ICheckBoxDrawable, ICheckBox>
{
readonly DrawableType _drawableType;
public class CheckBoxHandler : GraphicsControlHandler<ICheckBoxDrawable, ICheckBox>
{
readonly DrawableType _drawableType;

public CheckBoxHandler() : base(DrawMapper, PropertyMapper)
{
// Constructor for CheckBoxHandler with no arguments
public CheckBoxHandler() : base(DrawMapper, PropertyMapper)
{
}

}
// Constructor for CheckBoxHandler with DrawableType argument
public CheckBoxHandler(DrawableType drawableType) : base(DrawMapper, PropertyMapper)
{
_drawableType = drawableType;
}

public CheckBoxHandler(DrawableType drawableType) : base(DrawMapper, PropertyMapper)
{
_drawableType = drawableType;
}
// PropertyMapper for ICheckBox properties
public static PropertyMapper<ICheckBox> PropertyMapper = new PropertyMapper<ICheckBox>(ViewHandler.Mapper)
{
[nameof(ICheckBox.IsChecked)] = ViewHandler.MapInvalidate,
[nameof(ICheckBox.Foreground)] = ViewHandler.MapInvalidate,
};

public static PropertyMapper<ICheckBox> PropertyMapper = new PropertyMapper<ICheckBox>(ViewHandler.Mapper)
{
[nameof(ICheckBox.IsChecked)] = ViewHandler.MapInvalidate,
[nameof(ICheckBox.Foreground)] = ViewHandler.MapInvalidate,
};
// DrawMapper for ICheckBoxDrawable and ICheckBox
public static DrawMapper<ICheckBoxDrawable, ICheckBox> DrawMapper = new DrawMapper<ICheckBoxDrawable, ICheckBox>(ViewHandler.DrawMapper)
{
["Background"] = MapDrawBackground,
["Mark"] = MapDrawMark,
["Text"] = MapDrawText
};

public static DrawMapper<ICheckBoxDrawable, ICheckBox> DrawMapper = new DrawMapper<ICheckBoxDrawable, ICheckBox>(ViewHandler.DrawMapper)
{
["Background"] = MapDrawBackground,
["Mark"] = MapDrawMark,
["Text"] = MapDrawText
};
// Default drawing order for CheckBox layers
public static string[] DefaultCheckBoxLayerDrawingOrder =
ViewHandler.DefaultLayerDrawingOrder.ToList().InsertAfter(new string[]
{
"Background",
"Mark",
}, "Text").ToArray();

public static string[] DefaultCheckBoxLayerDrawingOrder =
ViewHandler.DefaultLayerDrawingOrder.ToList().InsertAfter(new string[]
{
"Background",
"Mark",
}, "Text").ToArray();
// Override method to return the layer drawing order
public override string[] LayerDrawingOrder() =>
DefaultCheckBoxLayerDrawingOrder;

public override string[] LayerDrawingOrder() =>
DefaultCheckBoxLayerDrawingOrder;
// Create an ICheckBoxDrawable based on the DrawableType
protected override ICheckBoxDrawable CreateDrawable()
{
switch (_drawableType)
{
default:
case DrawableType.Material:
return new MaterialCheckBoxDrawable();
case DrawableType.Cupertino:
return new CupertinoCheckBoxDrawable();
case DrawableType.Fluent:
return new FluentCheckBoxDrawable();
}
}

protected override ICheckBoxDrawable CreateDrawable()
{
switch (_drawableType)
{
default:
case DrawableType.Material:
return new MaterialCheckBoxDrawable();
case DrawableType.Cupertino:
return new CupertinoCheckBoxDrawable();
case DrawableType.Fluent:
return new FluentCheckBoxDrawable();
}
}
// Method to draw the background of the CheckBox
public static void MapDrawBackground(ICanvas canvas, RectF dirtyRect, ICheckBoxDrawable drawable, ICheckBox view)
=> drawable.DrawBackground(canvas, dirtyRect, view);

public static void MapDrawBackground(ICanvas canvas, RectF dirtyRect, ICheckBoxDrawable drawable, ICheckBox view)
=> drawable.DrawBackground(canvas, dirtyRect, view);
// Method to draw the check mark of the CheckBox
public static void MapDrawMark(ICanvas canvas, RectF dirtyRect, ICheckBoxDrawable drawable, ICheckBox view)
=> drawable.DrawMark(canvas, dirtyRect, view);

public static void MapDrawMark(ICanvas canvas, RectF dirtyRect, ICheckBoxDrawable drawable, ICheckBox view)
=> drawable.DrawMark(canvas, dirtyRect, view);
// Method to draw the text of the CheckBox
public static void MapDrawText(ICanvas canvas, RectF dirtyRect, ICheckBoxDrawable drawable, ICheckBox view)
=> drawable.DrawText(canvas, dirtyRect, view);

public static void MapDrawText(ICanvas canvas, RectF dirtyRect, ICheckBoxDrawable drawable, ICheckBox view)
=> drawable.DrawText(canvas, dirtyRect, view);
// Override method to handle user interaction with the CheckBox
public override bool StartInteraction(PointF[] points)
{
if (VirtualView != null)
VirtualView.IsChecked = !VirtualView.IsChecked;

public override bool StartInteraction(PointF[] points)
{
if (VirtualView != null)
VirtualView.IsChecked = !VirtualView.IsChecked;
return base.StartInteraction(points);
}
}
}

return base.StartInteraction(points);
}
}
}