-// Copyright (c) 2013-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+// Copyright (c) 2013-2021 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
/// <summary>
/// Measure class allow proportional sizes as well as stretched and fit on content.
/// </summary>
- public struct Measure
+ public struct Measure : IEquatable<Measure>
{
/// <summary>
/// Integer value of the measure
/// </summary>
public bool IsRelativeToParent { get { return Value >= 0 && Units == Unit.Percent; }}
#region Operators
- public static implicit operator int(Measure m){
- return m.Value;
- }
- public static implicit operator Measure(int i){
- return new Measure(i);
- }
- public static implicit operator string(Measure m){
- return m.ToString();
- }
- public static implicit operator Measure(string s){
- return Measure.Parse(s);
- }
+ public static implicit operator int(Measure m) => m.Value;
+ public static implicit operator Measure(int i) => new Measure(i);
+ public static implicit operator string(Measure m) => m.ToString();
+ public static implicit operator Measure(string s) => Measure.Parse(s);
- public static bool operator ==(Measure m1, Measure m2){
- return m1.Value == m2.Value && m1.Units == m2.Units;
- }
- public static bool operator !=(Measure m1, Measure m2){
- return !(m1.Value == m2.Value && m1.Units == m2.Units);
- }
+ public static bool operator ==(Measure m1, Measure m2) => m1.Equals (m2);
+ public static bool operator !=(Measure m1, Measure m2) => !m1.Equals (m2);
#endregion
+ public bool Equals(Measure other) => Value == other.Value && Units == other.Units;
+
#region Object overrides
- public override int GetHashCode ()
- {
- return Value.GetHashCode ();
- }
- public override bool Equals (object obj)
- {
- return (obj == null || obj.GetType() != typeof(Measure)) ?
- false :
- this == (Measure)obj;
- }
+ public override int GetHashCode () => HashCode.Combine (Value, Units);
+ public override bool Equals (object obj) => obj is Measure m ? Equals (m) : false;
public override string ToString ()
{
return Units == Unit.Inherit ? "Inherit" :
-using System.Linq;
-// Copyright (c) 2019-2021 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+// Copyright (c) 2019-2021 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
using System.ComponentModel;
+using System.Linq;
+using Crow.Cairo;
+using Glfw;
namespace Crow
{
base.OnChildLayoutChanges (sender, arg);
}*/
+ int splitIndex = -1;
+ const int minColumnSize = 10;
+ public override void onMouseMove(object sender, MouseMoveEventArgs e)
+ {
+ if (Spacing > 0 && Table != null && Table.Children.Count > 0) {
+ Point m = ScreenPointToLocal (e.Position);
+ if (IFace.IsDown (Glfw.MouseButton.Left) && splitIndex >= 0) {
+ TableRow firstRow = Table.Children[0] as TableRow;
+ Rectangle cb = ClientRectangle;
+ int splitPos = (int)(0.5 * Spacing + m.X);
+ if (splitPos > firstRow.Children[splitIndex].Slot.Left + minColumnSize && splitPos < firstRow.Children[splitIndex+1].Slot.Right - minColumnSize) {
+ Table.Columns[splitIndex+1].Width = firstRow.Children[splitIndex+1].Slot.Right - splitPos;
+ splitPos -= Spacing;
+ Table.Columns[splitIndex].Width = splitPos - firstRow.Children[splitIndex].Slot.Left;
+ Table.RegisterForLayouting (LayoutingType.Width);
+ }
+ //Console.WriteLine ($"left:{firstRow.Children[splitIndex].Slot.Left} right:{firstRow.Children[splitIndex+1].Slot.Right} cb.X:{cb.X} splitPos:{splitPos} m:{m}");
+ } else {
+ splitIndex = -1;
+ for (int i = 0; i < Children.Count - 1; i++)
+ {
+ Rectangle r = Children[i].Slot;
+ if (m.X >= r.Right) {
+ r = Children[i+1].Slot;
+ if (m.X <= r.Left && Table.Columns.Count - 1 > i ) {
+ Console.WriteLine ($"Set cursor Table row on mouse move. {m}");
+ IFace.MouseCursor = MouseCursor.sb_h_double_arrow;
+ splitIndex = i;
+ e.Handled = true;
+ break;
+ }
+ }
+ }
+ if (splitIndex < 0) {
+ IFace.MouseCursor = MouseCursor.top_left_arrow;
+ Console.WriteLine ($"RESet cursor Table row on mouse move. {m}");
+ }
+ }
+ }
+ base.onMouseMove(sender, e);
+ }
}
}