diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2014-02-22 00:09:17 +0400 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2014-02-22 00:09:17 +0400 |
commit | a59d93f117a8f1a4dda753c3239c7ee0b2d23269 (patch) | |
tree | 78a3af449526f39532d014ff0db0debf4c6bdd27 /TestApps | |
parent | 2fb9b0ad97837a640379e39494b2a12437cd45a5 (diff) |
Add support for mouse events to CellView
Diffstat (limited to 'TestApps')
-rw-r--r-- | TestApps/Samples/Samples/ListView1.cs | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/TestApps/Samples/Samples/ListView1.cs b/TestApps/Samples/Samples/ListView1.cs index e0ab24e3..6af9a614 100644 --- a/TestApps/Samples/Samples/ListView1.cs +++ b/TestApps/Samples/Samples/ListView1.cs @@ -10,7 +10,7 @@ namespace Samples DataField<Image> icon = new DataField<Image> (); DataField<string> text = new DataField<string> (); DataField<Image> icon2 = new DataField<Image> (); - DataField<int> progress = new DataField<int> (); + DataField<CellData> progress = new DataField<CellData> (); public ListView1 () { @@ -20,7 +20,7 @@ namespace Samples list.DataSource = store; list.Columns.Add ("Name", icon, name); list.Columns.Add ("Text", icon2, text); - list.Columns.Add ("Progress", new CustomCell () { ValueField = progress }); + list.Columns.Add ("Progress", new TextCellView () { TextField = text }, new CustomCell () { ValueField = progress }); var png = Image.FromResource (typeof(App), "class.png"); @@ -32,7 +32,7 @@ namespace Samples store.SetValue (r, name, "Value " + n); store.SetValue (r, icon2, png); store.SetValue (r, text, "Text " + n); - store.SetValue (r, progress, rand.Next () % 100); + store.SetValue (r, progress, new CellData { Value = rand.Next () % 100 }); } PackStart (list, true); @@ -48,9 +48,15 @@ namespace Samples } } + class CellData + { + public int Value; + public double YPos = -1; + } + class CustomCell: CanvasCellView { - public IDataField<int> ValueField { get; set; } + public IDataField<CellData> ValueField { get; set; } protected override Size OnGetRequiredSize () { @@ -59,16 +65,52 @@ namespace Samples protected override void OnDraw (Context ctx, Rectangle cellArea) { + ctx.Rectangle (BackgroundBounds); + ctx.SetColor (new Color (0.9, 0.9, 0.9)); + ctx.Fill (); + + ctx.Rectangle (Bounds); + ctx.SetColor (new Color (0.7, 0.7, 0.7)); + ctx.Fill (); + var pct = GetValue (ValueField); - var size = (cellArea.Width * pct) / 100f; + var size = (cellArea.Width * pct.Value) / 100f; cellArea.Width = (int) size; ctx.SetLineWidth (1); ctx.Rectangle (cellArea.Inflate (-0.5, -0.5)); - ctx.SetColor (Colors.LightBlue); + ctx.SetColor (Selected ? Colors.Blue : Colors.LightBlue); ctx.FillPreserve (); ctx.SetColor (Colors.Gray); ctx.Stroke (); + + if (pct.YPos != -1) { + ctx.MoveTo (cellArea.Right, Bounds.Y + pct.YPos); + ctx.Arc (cellArea.Right, Bounds.Y + pct.YPos, 2.5, 0, 360); + ctx.SetColor (Colors.Red); + ctx.Fill (); + } + } + + protected override void OnMouseMoved (MouseMovedEventArgs args) + { + var data = GetValue (ValueField); + data.Value = (int) (100 * ((args.X - Bounds.X) / Bounds.Width)); + data.YPos = args.Y - Bounds.Y; + QueueDraw (); + base.OnMouseMoved (args); + } + + protected override void OnButtonPressed (ButtonEventArgs args) + { + Console.WriteLine ("Press: " + args.Position); + base.OnButtonPressed (args); + } + + protected override void OnButtonReleased (ButtonEventArgs args) + { + Console.WriteLine ("Release: " + args.Position); + base.OnButtonReleased (args); } } } |