Skip to content

Instantly share code, notes, and snippets.

@cwensley
Last active March 21, 2022 08:47
Show Gist options
  • Save cwensley/2e25c8496bedc99bff3e to your computer and use it in GitHub Desktop.
Save cwensley/2e25c8496bedc99bff3e to your computer and use it in GitHub Desktop.
Custom drawable template for Eto
using Eto.Forms;
using Eto.Drawing;
namespace CustomDrawable
{
public class MyDrawable : Drawable
{
bool mouseDragging;
public MyDrawable()
{
Size = new Size(100, 20); // set preferred size of ruler
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// do your painting of the ruler using e.Graphics
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Buttons == MouseButtons.Primary)
{
// check the position of the mouse (e.Location) to detect if it is over a margin indicator
mouseDragging = true;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (mouseDragging)
{
// move the margin
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (e.Buttons == MouseButtons.Primary && mouseDragging)
{
// finished dragging operation
mouseDragging = false;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment