]> O.S.I.I.S - jp/crow.git/commitdiff
move other classes to Drawing2d
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 5 Mar 2025 08:12:17 +0000 (09:12 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 5 Mar 2025 08:12:17 +0000 (09:12 +0100)
26 files changed:
Crow/src/Enums.cs
Crow/src/EventArgs/ListChangedEventArg.cs [deleted file]
Crow/src/EventArgs/ValueChangeEventArgs.cs [deleted file]
Crow/src/Font.cs [deleted file]
Crow/src/IObservableList.cs [deleted file]
Crow/src/ISelectable.cs [deleted file]
Crow/src/IToggle.cs [deleted file]
Crow/src/IValueChange.cs [deleted file]
Crow/src/ItemTemplate.cs
Crow/src/ObservableList.cs [deleted file]
Crow/src/Widgets/GenericStack.cs
Crow/src/Widgets/Grid.cs
Crow/src/Widgets/HorizontalStack.cs
Crow/src/Widgets/Wrapper.cs
Crow/src/XCursor.cs
Drawing2D/src/Enums copy.cs [new file with mode: 0644]
Drawing2D/src/Font.cs [new file with mode: 0644]
Drawing2D/src/IMLAttributes.cs
Drawing2D/src/IObservableList.cs [new file with mode: 0644]
Drawing2D/src/ISelectable.cs [new file with mode: 0644]
Drawing2D/src/IToggle.cs [new file with mode: 0644]
Drawing2D/src/IValueChange.cs [new file with mode: 0644]
Drawing2D/src/ListChangedEventArg.cs [new file with mode: 0644]
Drawing2D/src/ObservableList.cs [new file with mode: 0644]
Drawing2D/src/ValueChangeEventArgs.cs [new file with mode: 0644]
Samples/common/ui/Interfaces/Experimental/testGrid.crow

index 866e32a951e74623b898528a2b0e2f4dd7703210..ad113bec2d297430954d80fb7573cc6a217fe71a 100644 (file)
@@ -4,132 +4,5 @@
 
 namespace Crow
 {
-       public enum Orientation
-    {
-        Horizontal,
-        Vertical
-    }
-
-       public enum Alignment
-    {
-        Top = 0x01,
-        Left = 0x02,
-               TopLeft = 0x03,
-               Right = 0x04,
-               TopRight = 0x05,
-               Bottom = 0x08,
-        BottomLeft = 0x0a,
-        BottomRight = 0x0c,
-               Center = 0x10,
-               Undefined = 0x40
-    }
-       public enum TextAlignment
-    {
-               Left,
-               Right,
-               Center,
-               Justify
-    }
-    public enum HorizontalAlignment
-    {
-        Left,
-        Right,
-        Center,
-    }
-    public enum VerticalAlignment
-    {
-        Top,
-        Bottom,
-        Center,
-    }
-       public enum MouseCursor
-       {
-               arrow,
-               base_arrow_down,
-               base_arrow_up,
-               boat,
-               bottom_left_corner,
-               bottom_right_corner,
-               bottom_side,
-               bottom_tee,
-               center_ptr,
-               circle,
-               cross,
-               cross_reverse,
-               crosshair,
-               dot,
-               dot_box_mask,
-               double_arrow,
-               draft_large,
-               draft_small,
-               draped_box,
-               exchange,
-               fleur,
-               gumby,
-               hand,
-               hand1,
-               hand2,
-               help,
-               ibeam,
-               left_ptr,
-               left_ptr_watch,
-               left_side,
-               left_tee,
-               ll_angle,
-               lr_angle,
-               move,
-               pencil,
-               pirate,
-               plus,
-               question_arrow,
-               right_ptr,
-               right_side,
-               right_tee,
-               sailboat,
-               sb_down_arrow,
-               sb_h_double_arrow,
-               sb_left_arrow,
-               sb_right_arrow,
-               sb_up_arrow,
-               sb_v_double_arrow,
-               shuttle,
-               sizing,
-               target,
-               tcross,
-               top_left_arrow,
-               top_left_corner,
-               top_right_corner,
-               top_side,
-               top_tee,
-               trek,
-               ul_angle,
-               ur_angle,
-               watch,
-               X_cursor,
-               xterm,
-       }
-       /// <summary>
-       /// Cursor shape use in Sliders
-       /// </summary>
-       public enum CursorType
-       {
-               /// <summary>Only Background of cursor will be drawm, you may use a bmp, svg, or shape as background for custom shape.</summary>
-               None,
-               Rectangle,
-               Circle,
-               Pentagone
-       }
-       /// <summary>
-       /// Color component used in color widgets
-       /// </summary>
-       public enum ColorComponent
-       {
-               Red,
-               Green,
-               Blue,
-               Alpha,
-               Hue,
-               Saturation,
-               Value
-       }
+       
 }
diff --git a/Crow/src/EventArgs/ListChangedEventArg.cs b/Crow/src/EventArgs/ListChangedEventArg.cs
deleted file mode 100644 (file)
index 7f83cfa..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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)
-using System;
-using System.Collections.Generic;
-
-namespace Crow
-{
-       public class ListChangedEventArg : EventArgs
-       {
-               public int Index;
-               public object Element;
-               public ListChangedEventArg (int index, object element)
-               {
-                       Index = index;
-                       Element = element;
-               }
-       }
-       public class ListClearEventArg : EventArgs
-       {
-               public IEnumerable<object> Elements;
-               public ListClearEventArg (IEnumerable<object> elements) {
-                       Elements = elements;
-               }
-       }
-}
diff --git a/Crow/src/EventArgs/ValueChangeEventArgs.cs b/Crow/src/EventArgs/ValueChangeEventArgs.cs
deleted file mode 100644 (file)
index 854e2cd..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
-using System;
-
-namespace Crow
-{
-       /// <summary>
-       /// Arguments for the ValueChange event used for Binding
-       /// </summary>
-       public class ValueChangeEventArgs: EventArgs
-       {
-               /// <summary>The name of the member whose value has changed</summary>
-               public string MemberName;
-               /// <summary>New value for that member</summary>
-               public object NewValue;
-
-               /// <summary>
-               /// Initializes a new instance of the <see cref="T:Crow.ValueChangeEventArgs"/> class.
-               /// </summary>
-               /// <param name="_memberName">Member name.</param>
-               /// <param name="_newValue">New value.</param>
-               public ValueChangeEventArgs (string _memberName, object _newValue) : base()
-               {
-                       MemberName = _memberName;
-                       NewValue = _newValue;
-               }
-       }
-}
-
diff --git a/Crow/src/Font.cs b/Crow/src/Font.cs
deleted file mode 100644 (file)
index e39f912..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-// Copyright (c) 2013-2021  Bruyère Jean-Philippe jp_bruyere@hotmail.com
-//
-// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
-using System;
-using Drawing2D;
-
-namespace Crow
-{
-       public enum FontStyle
-       {
-               Normal,
-               Bold,
-               Italic,
-               Underlined
-       }
-       public class Font
-       {
-               #region CTOR
-               public Font ()
-               {
-               }
-               #endregion
-
-               string _name = "sans";
-               int _size = 10;
-               FontStyle _style = FontStyle.Normal;
-
-               public string Name {
-                       get { return _name; }
-                       set { _name = value; }
-               }
-               public int Size {
-                       get { return _size; }
-                       set { _size = value; }
-               }
-               public FontStyle Style {
-                       get { return _style; }
-                       set { _style = value; }
-               }
-
-               public FontSlant Slant {
-                       get{
-                               switch (Style) {
-                               case FontStyle.Italic:
-                                       return FontSlant.Italic;
-                               default:
-                                       return FontSlant.Normal;
-                               }
-                       }
-               }
-               public FontWeight Wheight {
-                       get{
-                               switch (Style) {
-                               case FontStyle.Bold:
-                                       return FontWeight.Bold;
-                               default:
-                                       return FontWeight.Normal;
-                               }
-                       }
-               }
-
-               #region Operators
-               public static implicit operator string(Font c) => c.ToString();
-
-               public static implicit operator Font(string s) => (Font)Parse(s);
-               #endregion
-
-               public override string ToString () =>
-                       _style == FontStyle.Normal ? $"{_name},{_size}" : $"{_name} {_style},{_size}";
-
-               public static Font Parse(string s)
-               {
-                       Font f = new Font ();
-                       ReadOnlySpan<char> tmp = s.AsSpan ().Trim ();
-                       if (tmp.Length > 0) {
-                               int ioc = tmp.IndexOf (',');
-
-                               if (ioc >= 0) {
-                                       f.Size = int.Parse (tmp.Slice (ioc + 1).Trim ());
-                                       tmp = tmp.Slice (0, ioc).TrimEnd ();
-                               }
-
-                               ioc = tmp.IndexOf (' ');
-
-                               if (ioc < 0)
-                                       f.Name = tmp.ToString ();
-                               else {
-                                       f.Name = tmp.Slice (0, ioc).ToString ();
-                                       f.Style = EnumsNET.Enums.Parse<FontStyle> (tmp.Slice (ioc + 1).ToString (), true);
-                               }
-                       }
-                       return f;
-               }
-       }
-}
-
diff --git a/Crow/src/IObservableList.cs b/Crow/src/IObservableList.cs
deleted file mode 100644 (file)
index 4c8ae23..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
-using System;
-
-namespace Crow
-{
-       public interface IObservableList {
-               event EventHandler<ListChangedEventArg> ListAdd;
-               event EventHandler<ListChangedEventArg> ListRemove;
-               event EventHandler<ListChangedEventArg> ListEdit;
-               event EventHandler<ListClearEventArg> ListClear;
-
-               void Insert ();
-               void Remove ();
-               void RaiseEdit ();
-       }
-}
-
diff --git a/Crow/src/ISelectable.cs b/Crow/src/ISelectable.cs
deleted file mode 100644 (file)
index 23fdcfd..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) 2020-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;
-
-namespace Crow
-{
-    public interface ISelectable
-    {
-               event EventHandler Selected;
-               event EventHandler Unselected;
-               
-               bool IsSelected {
-                       get;
-                       set;
-               }
-
-       }
-}
diff --git a/Crow/src/IToggle.cs b/Crow/src/IToggle.cs
deleted file mode 100644 (file)
index 6a47b40..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) 2020-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;
-
-namespace Crow
-{
-    public interface IToggle
-    {
-               event EventHandler ToggleOn;
-               event EventHandler ToggleOff;
-               BooleanTestOnInstance IsToggleable { get; set; }
-
-               bool IsToggled {
-                       get;
-                       set;
-               }
-
-       }
-}
diff --git a/Crow/src/IValueChange.cs b/Crow/src/IValueChange.cs
deleted file mode 100644 (file)
index b79c7fa..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-// 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)
-
-using System;
-using System.Collections.Generic;
-
-namespace Crow
-{
-       /// <summary>
-       /// implement `IValueChange` interface in object you want to bind to the interface.
-       /// For each property updated in code, raise a value change in the container class
-       /// to inform Crow binding system that the value has changed.
-       /// </summary>
-       public interface IValueChange
-       {
-               event EventHandler<ValueChangeEventArgs> ValueChanged;
-       }
-       /// <summary>
-       /// Container for net primitive value type implementing IValueChange
-       /// </summary>
-       public class ValueContainer<T> : IValueChange, IEquatable<T>//, IConvertible
-       {
-               public event EventHandler<ValueChangeEventArgs> ValueChanged;
-               T val;
-               public T Value {
-                       get => val;
-                       set {
-                               if (EqualityComparer<T>.Default.Equals (value, val))
-                                       return;
-                               val = value;
-                               ValueChanged?.Invoke (this, new Crow.ValueChangeEventArgs ("Value", val));
-                       }
-               }
-
-               public static implicit operator ValueContainer<T>(T v) => new ValueContainer<T> (v);
-               public static implicit operator T (ValueContainer<T> v) => v.Value;
-
-               public ValueContainer (T _val) { val = _val; }
-
-               public bool Equals (T other) => val.Equals (other);
-               public override bool Equals (object obj) => obj is ValueContainer<T> v && Equals (v);
-               public override int GetHashCode () => val.GetHashCode ();
-               public override string ToString () => val.ToString ();
-       }
-}
-
index cf5bcab3c9b299638bcdd368a28b0e67efc9262a..6d9228865cf4f5dd66d4e6489ddea2f58f052ac9 100644 (file)
@@ -20,9 +20,6 @@ using System.Collections;
 //at the root level of the item template if the dataTest is 'typeOf'...
 namespace Crow
 {
-       /// <summary> Test func on data, return yes if there's children </summary>
-       public delegate bool BooleanTestOnInstance(object instance);
-
        /// <summary>
        /// Derived from Instantiator with sub data fetching facilities for hierarchical data access.
        ///
diff --git a/Crow/src/ObservableList.cs b/Crow/src/ObservableList.cs
deleted file mode 100644 (file)
index a62e7e3..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-using System.Reflection;
-// Copyright (c) 2013-2019  Bruyère Jean-Philippe jp_bruyere@hotmail.com
-//
-// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Collections;
-
-namespace Crow
-{
-       public class ObservableList<T> : IList<T>, IObservableList, IValueChange, ICollection {
-               #region IValueChange implementation
-               public event EventHandler<ValueChangeEventArgs> ValueChanged;
-               public virtual void NotifyValueChanged (string MemberName, object _value)
-               {
-                       ValueChanged?.Invoke (this, new ValueChangeEventArgs (MemberName, _value));
-               }
-               #endregion
-
-               #region IObservableList implementation
-               public event EventHandler<ListChangedEventArg> ListAdd;
-               public event EventHandler<ListChangedEventArg> ListRemove;
-               public event EventHandler<ListChangedEventArg> ListEdit;
-               public event EventHandler<ListClearEventArg> ListClear;
-               #endregion
-
-               List<T> items;
-               public ObservableList() {
-                       items = new List<T>();
-               }
-               public ObservableList (IEnumerable<T> collection) {
-                       items = new List<T> (collection);
-               }
-
-               int selectedIndex = -1;
-
-               public int SelectedIndex {
-                       get => selectedIndex;
-                       set {
-                               if (selectedIndex == value)
-                                       return;
-
-                               if (value > Count - 1)
-                                       selectedIndex = Count - 1;
-                               else
-                                       selectedIndex = value;
-
-                               NotifyValueChanged ("SelectedIndex", selectedIndex);
-                               NotifyValueChanged ("SelectedItem", SelectedItem);
-                       }
-               }
-               public T SelectedItem {
-                       get => selectedIndex < 0 ? default(T) : this [selectedIndex];
-                       set {
-                               this [selectedIndex] = value;
-                       }
-               }
-
-               public int Count => items.Count;
-
-               public bool IsReadOnly => false;
-
-               public bool IsSynchronized => throw new NotImplementedException();
-
-               public object SyncRoot => throw new NotImplementedException();
-
-               public T this[int index] {
-                       get => items[index];
-                       set {
-
-                               if (items[index] == null) {
-                                       if (value == null)
-                                               return;
-                               }else if (items[index].Equals (value))
-                                       return;
-                               Replace (items[index], value);
-                       }
-               }
-
-               public void Add (T elem) {
-                       items.Add (elem);
-                       ListAdd.Raise (this, new ListChangedEventArg (this.Count - 1, elem));
-                       SelectedIndex = this.Count - 1;
-               }
-               public void Insert (int index, T elem) {
-                       items.Insert (index, elem);
-                       ListAdd.Raise (this, new ListChangedEventArg (index, elem));
-                       SelectedIndex = index;
-               }
-               public bool Remove (T elem) {
-                       int idx = IndexOf (elem);
-                       if (idx < 0)
-                               return false;
-                       else
-                               items.RemoveAt (idx);
-                       ListRemove.Raise (this, new ListChangedEventArg (idx, elem));
-                       return true;
-               }
-               public void Clear ()
-               {
-                       ListClearEventArg eventArg = new ListClearEventArg (this.Cast<object>());
-                       items.Clear ();
-                       ListClear.Raise (this, eventArg);
-               }
-               public void Remove () {
-                       if (selectedIndex < 0)
-                               return;
-                       RemoveAt (selectedIndex);
-                       SelectedIndex--;
-               }
-               public void Insert ()
-               {
-                       items.Insert (selectedIndex+1, default(T));
-                       SelectedIndex++;
-                       ListAdd.Raise (this, new ListChangedEventArg (selectedIndex, SelectedItem));
-               }
-               public void Replace (T oldValue, T newValue) {
-                       int idx = IndexOf (oldValue);
-                       items[idx] = newValue;
-                       ListEdit.Raise (this, new ListChangedEventArg (idx, newValue));
-               }
-               public void RaiseEdit () {
-                       if (selectedIndex < 0)
-                               return;
-                       ListEdit.Raise (this, new ListChangedEventArg (selectedIndex, SelectedItem));
-               }
-
-               public void RemoveAt (int index)
-               {
-                       items.RemoveAt (index);
-                       ListRemove.Raise (this, new ListChangedEventArg (index, null));
-               }
-               public void RaiseEditAt (int index) {
-                       ListEdit.Raise (this, new ListChangedEventArg (index, this[index]));
-               }
-
-
-               public static ObservableList<T> Parse (string str) {
-                       ObservableList<T> tmp = new ObservableList<T>();
-                       if (!string.IsNullOrEmpty (str)) {
-                               Type t = typeof(T);
-                               if (t.IsEnum) {
-                                       foreach (string s in str.Split(';'))
-                                               tmp.Add((T)Enum.Parse(t, s));
-                               } else {
-                                       MethodInfo miParse = t.GetMethod ("Parse",
-                                               BindingFlags.Static | BindingFlags.Public, Type.DefaultBinder, new Type [] {typeof (string)}, null);
-                                       if (miParse == null)
-                                               throw new Exception ("no Parse method found for: " + t.FullName);
-
-                                       foreach (string s in str.Split(';'))
-                                               tmp.Add((T)miParse.Invoke (null, new object[] {s}));                            
-                               }
-                       }
-                       return tmp;
-               }
-
-               public int IndexOf(T item) => items.IndexOf (item);
-
-               public bool Contains(T item) => items.Contains (item);
-
-               public void CopyTo(T[] array, int arrayIndex) => items.CopyTo (array, arrayIndex);
-
-
-               public IEnumerator<T> GetEnumerator() => items.GetEnumerator ();
-
-               IEnumerator IEnumerable.GetEnumerator() => items.GetEnumerator ();
-
-               public void CopyTo(Array array, int index) => items.ToArray().CopyTo (array, index);
-       }
-}
-
index 4c0a85d9f8522e84f6e94cfdb60542ede3f1e87d..d5375c5f02f578553567dea5ffeb07951744af4c 100644 (file)
@@ -109,9 +109,8 @@ namespace Crow {
                }
                Widget stretchedGO = null;
                public override bool UpdateLayout (LayoutingType layoutType) {
-                       RegisteredLayoutings &= (~layoutType);
-
                        if (layoutType == LayoutingType.ArrangeChildren) {
+                               RegisteredLayoutings &= (~layoutType);
                                //allow 1 child to have stretched size,
                                //this child will occupy remaining space
                                //if stack size policy is Fit, no child may have stretch enabled
index 4d7edced77b38488aad1c8be3b7002696daacbee..e5c0809f4d56feb705270436e586936b0b47c171 100644 (file)
@@ -1,35 +1,7 @@
-//
-// Grid.cs
+// Copyright (c) 2013-2025  Bruyère Jean-Philippe jp_bruyere@hotmail.com
 //
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
-using System;
-using System.Diagnostics;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Xml.Serialization;
 using System.ComponentModel;
 
 namespace Crow
@@ -44,59 +16,57 @@ namespace Crow
        {
                #region CTOR
                protected Grid () : base(){}
-               public Grid(Interface iface) : base(iface)
-               {
-               }
+               public Grid(Interface iface, string style = null) : base (iface, style) { }
                #endregion
 
                #region Private fields
-               int _spacing;
-               int _columnCount;
-               int _rowCount;
+               int spacing;
+               int columnCount;
+               int rowCount;
                #endregion
 
                #region Public Properties
-               [DefaultValue(2)]
-               public int Spacing
-               {
-                       get { return _spacing; }
-                       set { _spacing = value; }
+               [DefaultValue (2)]
+               public int Spacing {
+                       get => spacing;
+                       set {
+                               if (spacing == value)
+                                       return;
+                               spacing = value;
+                               NotifyValueChangedAuto (spacing);
+                               RegisterForLayouting (LayoutingType.ArrangeChildren);
+                       }
                }
                [DefaultValue(2)]
                public virtual int ColumnCount
                {
-                       get { return _columnCount; }
+                       get { return columnCount; }
                        set {
-                               if (_columnCount == value)
+                               if (columnCount == value)
                                        return;
 
-                               _columnCount = value;
+                               columnCount = value;
 
                                NotifyValueChangedAuto (ColumnCount);
-                               this.RegisterForLayouting (LayoutingType.ArrangeChildren);
+                               RegisterForLayouting (LayoutingType.ArrangeChildren);
                        }
                }
                [DefaultValue(2)]
                public virtual int RowCount
                {
-                       get { return _rowCount; }
+                       get { return rowCount; }
                        set {
-                               if (_rowCount == value)
+                               if (rowCount == value)
                                        return;
 
-                               _rowCount = value;
+                               rowCount = value;
 
                                NotifyValueChangedAuto (RowCount);
-                               this.RegisterForLayouting (LayoutingType.ArrangeChildren);
+                               RegisterForLayouting (LayoutingType.ArrangeChildren);
                        }
                }
-               public virtual int CaseWidth {
-                       get => (Slot.Width - (ColumnCount - 1) * Spacing) / ColumnCount;
-               }
-               public virtual int CaseHeight {
-                       get => (Slot.Height - (RowCount - 1) * Spacing) / RowCount;
-               }
-
+               public virtual int CaseWidth => (Slot.Width - (ColumnCount - 1) * Spacing) / ColumnCount;
+               public virtual int CaseHeight => (Slot.Height - (RowCount - 1) * Spacing) / RowCount;
                #endregion
 
                #region Widget Overrides
@@ -119,9 +89,9 @@ namespace Crow
                public override void ChildrenLayoutingConstraints (ILayoutable layoutable, ref LayoutingType layoutType)
                {
                        //Prevent child repositionning
-                       layoutType &= (~LayoutingType.Positioning);
+                       layoutType &= (~LayoutingType.Sizing);
                }
-               public override bool ArrangeChildren { get { return true; } }
+               public override bool ArrangeChildren => true;
                public virtual void ComputeChildrenPositions()
                {
                        int slotWidth = CaseWidth;
@@ -134,31 +104,43 @@ namespace Crow
                                        Widget c = Children [idx];
                                        if (!c.IsVisible)
                                                continue;
-                                       c.Slot.X = curX * (slotWidth + Spacing);
-                                       c.Slot.Y = curY * (slotHeight + Spacing);
-                                       //c.Slot.Width = slotWidth;
-                                       //c.Slot.Height = slotHeight;
+                                       int x = curX * (slotWidth + Spacing);
+                                       if (c.Slot.X != x) {
+                                               c.Slot.X = x;
+                                               c.OnLayoutChanges (LayoutingType.X);
+                                               c.LastSlots.X = c.Slot.X;
+                                               IsDirty = true;
+                                       }
+                                       int y = curY * (slotHeight + Spacing);
+                                       if (c.Slot.Y != y) {
+                                               c.Slot.Y = y;
+                                               c.OnLayoutChanges (LayoutingType.Y);
+                                               c.LastSlots.Y = c.Slot.Y;
+                                               IsDirty = true;
+                                       }
                                }
                        }
                        IsDirty = true;
                }
-               public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
-               {
-                       //base.OnChildLayoutChanges (sender, arg);
-               }
-
-               public override bool UpdateLayout (LayoutingType layoutType)
+        public override void RegisterForLayouting(LayoutingType layoutType)
+        {
+            base.RegisterForLayouting(layoutType);
+        }
+        public override void OnLayoutChanges(LayoutingType layoutType)
+        {
+            base.OnLayoutChanges(layoutType);
+        }
+        public override void OnChildLayoutChanges(object sender, LayoutingEventArgs arg)
+        {
+            base.OnChildLayoutChanges(sender, arg);
+        }
+
+        public override bool UpdateLayout (LayoutingType layoutType)
                {
-                       RegisteredLayoutings &= (~layoutType);
-
                        if (layoutType == LayoutingType.ArrangeChildren) {
+                               RegisteredLayoutings &= (~layoutType);
 
                                ComputeChildrenPositions ();
-
-                               //if no layouting remains in queue for item, registre for redraw
-                               if (RegisteredLayoutings == LayoutingType.None && IsDirty)
-                                       IFace.EnqueueForRepaint (this);
-
                                return true;
                        }
 
index 5e16c3260f33c5453d1684e03bf88dc6a0ad9ddf..517f692ecfad1a5f4df4d9128faa87e28f622d3f 100644 (file)
@@ -2,6 +2,7 @@
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
+
 namespace Crow
 {
        /// <summary>
index ef7d627a20b52a83358e77f1dfc553c3905e51ad..734227b70b8b5070f2973275de285fb7afc4406b 100644 (file)
@@ -2,6 +2,7 @@
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 using static Crow.Logger;
+
 namespace Crow
 {
        /// <summary>
@@ -180,9 +181,8 @@ namespace Crow
 
                public override bool UpdateLayout (LayoutingType layoutType)
                {
-                       RegisteredLayoutings &= (~layoutType);
-
                        if (layoutType == LayoutingType.ArrangeChildren) {
+                               RegisteredLayoutings &= (~layoutType);
                                if ((RequiredLayoutings & LayoutingType.Sizing) != 0)
                                        return false;
 
index 2fdfa5a0258af6b09b2bc0ed616945552f9e6acb..b74f72936f88070722e7d0d49c71a07e1be34482 100644 (file)
@@ -7,6 +7,7 @@ using System.IO;
 using System.Diagnostics;
 using System.Collections.Generic;
 using System.Linq;
+using Drawing2D;
 
 namespace Crow
 {
diff --git a/Drawing2D/src/Enums copy.cs b/Drawing2D/src/Enums copy.cs
new file mode 100644 (file)
index 0000000..d8a975a
--- /dev/null
@@ -0,0 +1,138 @@
+// Copyright (c) 2018-2022  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using System;
+
+namespace Crow
+{
+       
+       public enum Orientation
+    {
+        Horizontal,
+        Vertical
+    }
+
+       public enum Alignment
+    {
+        Top = 0x01,
+        Left = 0x02,
+               TopLeft = 0x03,
+               Right = 0x04,
+               TopRight = 0x05,
+               Bottom = 0x08,
+        BottomLeft = 0x0a,
+        BottomRight = 0x0c,
+               Center = 0x10,
+               Undefined = 0x40
+    }
+       public enum TextAlignment
+    {
+               Left,
+               Right,
+               Center,
+               Justify
+    }
+    public enum HorizontalAlignment
+    {
+        Left,
+        Right,
+        Center,
+    }
+    public enum VerticalAlignment
+    {
+        Top,
+        Bottom,
+        Center,
+    }
+       public enum MouseCursor
+       {
+               arrow,
+               base_arrow_down,
+               base_arrow_up,
+               boat,
+               bottom_left_corner,
+               bottom_right_corner,
+               bottom_side,
+               bottom_tee,
+               center_ptr,
+               circle,
+               cross,
+               cross_reverse,
+               crosshair,
+               dot,
+               dot_box_mask,
+               double_arrow,
+               draft_large,
+               draft_small,
+               draped_box,
+               exchange,
+               fleur,
+               gumby,
+               hand,
+               hand1,
+               hand2,
+               help,
+               ibeam,
+               left_ptr,
+               left_ptr_watch,
+               left_side,
+               left_tee,
+               ll_angle,
+               lr_angle,
+               move,
+               pencil,
+               pirate,
+               plus,
+               question_arrow,
+               right_ptr,
+               right_side,
+               right_tee,
+               sailboat,
+               sb_down_arrow,
+               sb_h_double_arrow,
+               sb_left_arrow,
+               sb_right_arrow,
+               sb_up_arrow,
+               sb_v_double_arrow,
+               shuttle,
+               sizing,
+               target,
+               tcross,
+               top_left_arrow,
+               top_left_corner,
+               top_right_corner,
+               top_side,
+               top_tee,
+               trek,
+               ul_angle,
+               ur_angle,
+               watch,
+               X_cursor,
+               xterm,
+       }
+       /// <summary>
+       /// Cursor shape use in Sliders
+       /// </summary>
+       public enum CursorType
+       {
+               /// <summary>Only Background of cursor will be drawm, you may use a bmp, svg, or shape as background for custom shape.</summary>
+               None,
+               Rectangle,
+               Circle,
+               Pentagone
+       }
+       /// <summary>
+       /// Color component used in color widgets
+       /// </summary>
+       public enum ColorComponent
+       {
+               Red,
+               Green,
+               Blue,
+               Alpha,
+               Hue,
+               Saturation,
+               Value
+       }       
+}
\ No newline at end of file
diff --git a/Drawing2D/src/Font.cs b/Drawing2D/src/Font.cs
new file mode 100644 (file)
index 0000000..e39f912
--- /dev/null
@@ -0,0 +1,97 @@
+// Copyright (c) 2013-2021  Bruyère Jean-Philippe jp_bruyere@hotmail.com
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using System;
+using Drawing2D;
+
+namespace Crow
+{
+       public enum FontStyle
+       {
+               Normal,
+               Bold,
+               Italic,
+               Underlined
+       }
+       public class Font
+       {
+               #region CTOR
+               public Font ()
+               {
+               }
+               #endregion
+
+               string _name = "sans";
+               int _size = 10;
+               FontStyle _style = FontStyle.Normal;
+
+               public string Name {
+                       get { return _name; }
+                       set { _name = value; }
+               }
+               public int Size {
+                       get { return _size; }
+                       set { _size = value; }
+               }
+               public FontStyle Style {
+                       get { return _style; }
+                       set { _style = value; }
+               }
+
+               public FontSlant Slant {
+                       get{
+                               switch (Style) {
+                               case FontStyle.Italic:
+                                       return FontSlant.Italic;
+                               default:
+                                       return FontSlant.Normal;
+                               }
+                       }
+               }
+               public FontWeight Wheight {
+                       get{
+                               switch (Style) {
+                               case FontStyle.Bold:
+                                       return FontWeight.Bold;
+                               default:
+                                       return FontWeight.Normal;
+                               }
+                       }
+               }
+
+               #region Operators
+               public static implicit operator string(Font c) => c.ToString();
+
+               public static implicit operator Font(string s) => (Font)Parse(s);
+               #endregion
+
+               public override string ToString () =>
+                       _style == FontStyle.Normal ? $"{_name},{_size}" : $"{_name} {_style},{_size}";
+
+               public static Font Parse(string s)
+               {
+                       Font f = new Font ();
+                       ReadOnlySpan<char> tmp = s.AsSpan ().Trim ();
+                       if (tmp.Length > 0) {
+                               int ioc = tmp.IndexOf (',');
+
+                               if (ioc >= 0) {
+                                       f.Size = int.Parse (tmp.Slice (ioc + 1).Trim ());
+                                       tmp = tmp.Slice (0, ioc).TrimEnd ();
+                               }
+
+                               ioc = tmp.IndexOf (' ');
+
+                               if (ioc < 0)
+                                       f.Name = tmp.ToString ();
+                               else {
+                                       f.Name = tmp.Slice (0, ioc).ToString ();
+                                       f.Style = EnumsNET.Enums.Parse<FontStyle> (tmp.Slice (ioc + 1).ToString (), true);
+                               }
+                       }
+                       return f;
+               }
+       }
+}
+
index 9a6d7dfbe08f57482f71b348c3e9faea19f01cfe..0c7a07a5b6d73e363a13f80eb31b812ce8190474 100644 (file)
@@ -6,6 +6,8 @@ using System;
 
 namespace Crow
 {
+       /// <summary> Test func on data, return yes if there's children </summary>
+       public delegate bool BooleanTestOnInstance(object instance);
        public class XmlIgnoreAttribute : Attribute
        { 
        }
diff --git a/Drawing2D/src/IObservableList.cs b/Drawing2D/src/IObservableList.cs
new file mode 100644 (file)
index 0000000..4c8ae23
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using System;
+
+namespace Crow
+{
+       public interface IObservableList {
+               event EventHandler<ListChangedEventArg> ListAdd;
+               event EventHandler<ListChangedEventArg> ListRemove;
+               event EventHandler<ListChangedEventArg> ListEdit;
+               event EventHandler<ListClearEventArg> ListClear;
+
+               void Insert ();
+               void Remove ();
+               void RaiseEdit ();
+       }
+}
+
diff --git a/Drawing2D/src/ISelectable.cs b/Drawing2D/src/ISelectable.cs
new file mode 100644 (file)
index 0000000..23fdcfd
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright (c) 2020-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;
+
+namespace Crow
+{
+    public interface ISelectable
+    {
+               event EventHandler Selected;
+               event EventHandler Unselected;
+               
+               bool IsSelected {
+                       get;
+                       set;
+               }
+
+       }
+}
diff --git a/Drawing2D/src/IToggle.cs b/Drawing2D/src/IToggle.cs
new file mode 100644 (file)
index 0000000..6a47b40
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright (c) 2020-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;
+
+namespace Crow
+{
+    public interface IToggle
+    {
+               event EventHandler ToggleOn;
+               event EventHandler ToggleOff;
+               BooleanTestOnInstance IsToggleable { get; set; }
+
+               bool IsToggled {
+                       get;
+                       set;
+               }
+
+       }
+}
diff --git a/Drawing2D/src/IValueChange.cs b/Drawing2D/src/IValueChange.cs
new file mode 100644 (file)
index 0000000..b79c7fa
--- /dev/null
@@ -0,0 +1,47 @@
+// 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)
+
+using System;
+using System.Collections.Generic;
+
+namespace Crow
+{
+       /// <summary>
+       /// implement `IValueChange` interface in object you want to bind to the interface.
+       /// For each property updated in code, raise a value change in the container class
+       /// to inform Crow binding system that the value has changed.
+       /// </summary>
+       public interface IValueChange
+       {
+               event EventHandler<ValueChangeEventArgs> ValueChanged;
+       }
+       /// <summary>
+       /// Container for net primitive value type implementing IValueChange
+       /// </summary>
+       public class ValueContainer<T> : IValueChange, IEquatable<T>//, IConvertible
+       {
+               public event EventHandler<ValueChangeEventArgs> ValueChanged;
+               T val;
+               public T Value {
+                       get => val;
+                       set {
+                               if (EqualityComparer<T>.Default.Equals (value, val))
+                                       return;
+                               val = value;
+                               ValueChanged?.Invoke (this, new Crow.ValueChangeEventArgs ("Value", val));
+                       }
+               }
+
+               public static implicit operator ValueContainer<T>(T v) => new ValueContainer<T> (v);
+               public static implicit operator T (ValueContainer<T> v) => v.Value;
+
+               public ValueContainer (T _val) { val = _val; }
+
+               public bool Equals (T other) => val.Equals (other);
+               public override bool Equals (object obj) => obj is ValueContainer<T> v && Equals (v);
+               public override int GetHashCode () => val.GetHashCode ();
+               public override string ToString () => val.ToString ();
+       }
+}
+
diff --git a/Drawing2D/src/ListChangedEventArg.cs b/Drawing2D/src/ListChangedEventArg.cs
new file mode 100644 (file)
index 0000000..7f83cfa
--- /dev/null
@@ -0,0 +1,26 @@
+// 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)
+using System;
+using System.Collections.Generic;
+
+namespace Crow
+{
+       public class ListChangedEventArg : EventArgs
+       {
+               public int Index;
+               public object Element;
+               public ListChangedEventArg (int index, object element)
+               {
+                       Index = index;
+                       Element = element;
+               }
+       }
+       public class ListClearEventArg : EventArgs
+       {
+               public IEnumerable<object> Elements;
+               public ListClearEventArg (IEnumerable<object> elements) {
+                       Elements = elements;
+               }
+       }
+}
diff --git a/Drawing2D/src/ObservableList.cs b/Drawing2D/src/ObservableList.cs
new file mode 100644 (file)
index 0000000..a62e7e3
--- /dev/null
@@ -0,0 +1,174 @@
+using System.Reflection;
+// Copyright (c) 2013-2019  Bruyère Jean-Philippe jp_bruyere@hotmail.com
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Collections;
+
+namespace Crow
+{
+       public class ObservableList<T> : IList<T>, IObservableList, IValueChange, ICollection {
+               #region IValueChange implementation
+               public event EventHandler<ValueChangeEventArgs> ValueChanged;
+               public virtual void NotifyValueChanged (string MemberName, object _value)
+               {
+                       ValueChanged?.Invoke (this, new ValueChangeEventArgs (MemberName, _value));
+               }
+               #endregion
+
+               #region IObservableList implementation
+               public event EventHandler<ListChangedEventArg> ListAdd;
+               public event EventHandler<ListChangedEventArg> ListRemove;
+               public event EventHandler<ListChangedEventArg> ListEdit;
+               public event EventHandler<ListClearEventArg> ListClear;
+               #endregion
+
+               List<T> items;
+               public ObservableList() {
+                       items = new List<T>();
+               }
+               public ObservableList (IEnumerable<T> collection) {
+                       items = new List<T> (collection);
+               }
+
+               int selectedIndex = -1;
+
+               public int SelectedIndex {
+                       get => selectedIndex;
+                       set {
+                               if (selectedIndex == value)
+                                       return;
+
+                               if (value > Count - 1)
+                                       selectedIndex = Count - 1;
+                               else
+                                       selectedIndex = value;
+
+                               NotifyValueChanged ("SelectedIndex", selectedIndex);
+                               NotifyValueChanged ("SelectedItem", SelectedItem);
+                       }
+               }
+               public T SelectedItem {
+                       get => selectedIndex < 0 ? default(T) : this [selectedIndex];
+                       set {
+                               this [selectedIndex] = value;
+                       }
+               }
+
+               public int Count => items.Count;
+
+               public bool IsReadOnly => false;
+
+               public bool IsSynchronized => throw new NotImplementedException();
+
+               public object SyncRoot => throw new NotImplementedException();
+
+               public T this[int index] {
+                       get => items[index];
+                       set {
+
+                               if (items[index] == null) {
+                                       if (value == null)
+                                               return;
+                               }else if (items[index].Equals (value))
+                                       return;
+                               Replace (items[index], value);
+                       }
+               }
+
+               public void Add (T elem) {
+                       items.Add (elem);
+                       ListAdd.Raise (this, new ListChangedEventArg (this.Count - 1, elem));
+                       SelectedIndex = this.Count - 1;
+               }
+               public void Insert (int index, T elem) {
+                       items.Insert (index, elem);
+                       ListAdd.Raise (this, new ListChangedEventArg (index, elem));
+                       SelectedIndex = index;
+               }
+               public bool Remove (T elem) {
+                       int idx = IndexOf (elem);
+                       if (idx < 0)
+                               return false;
+                       else
+                               items.RemoveAt (idx);
+                       ListRemove.Raise (this, new ListChangedEventArg (idx, elem));
+                       return true;
+               }
+               public void Clear ()
+               {
+                       ListClearEventArg eventArg = new ListClearEventArg (this.Cast<object>());
+                       items.Clear ();
+                       ListClear.Raise (this, eventArg);
+               }
+               public void Remove () {
+                       if (selectedIndex < 0)
+                               return;
+                       RemoveAt (selectedIndex);
+                       SelectedIndex--;
+               }
+               public void Insert ()
+               {
+                       items.Insert (selectedIndex+1, default(T));
+                       SelectedIndex++;
+                       ListAdd.Raise (this, new ListChangedEventArg (selectedIndex, SelectedItem));
+               }
+               public void Replace (T oldValue, T newValue) {
+                       int idx = IndexOf (oldValue);
+                       items[idx] = newValue;
+                       ListEdit.Raise (this, new ListChangedEventArg (idx, newValue));
+               }
+               public void RaiseEdit () {
+                       if (selectedIndex < 0)
+                               return;
+                       ListEdit.Raise (this, new ListChangedEventArg (selectedIndex, SelectedItem));
+               }
+
+               public void RemoveAt (int index)
+               {
+                       items.RemoveAt (index);
+                       ListRemove.Raise (this, new ListChangedEventArg (index, null));
+               }
+               public void RaiseEditAt (int index) {
+                       ListEdit.Raise (this, new ListChangedEventArg (index, this[index]));
+               }
+
+
+               public static ObservableList<T> Parse (string str) {
+                       ObservableList<T> tmp = new ObservableList<T>();
+                       if (!string.IsNullOrEmpty (str)) {
+                               Type t = typeof(T);
+                               if (t.IsEnum) {
+                                       foreach (string s in str.Split(';'))
+                                               tmp.Add((T)Enum.Parse(t, s));
+                               } else {
+                                       MethodInfo miParse = t.GetMethod ("Parse",
+                                               BindingFlags.Static | BindingFlags.Public, Type.DefaultBinder, new Type [] {typeof (string)}, null);
+                                       if (miParse == null)
+                                               throw new Exception ("no Parse method found for: " + t.FullName);
+
+                                       foreach (string s in str.Split(';'))
+                                               tmp.Add((T)miParse.Invoke (null, new object[] {s}));                            
+                               }
+                       }
+                       return tmp;
+               }
+
+               public int IndexOf(T item) => items.IndexOf (item);
+
+               public bool Contains(T item) => items.Contains (item);
+
+               public void CopyTo(T[] array, int arrayIndex) => items.CopyTo (array, arrayIndex);
+
+
+               public IEnumerator<T> GetEnumerator() => items.GetEnumerator ();
+
+               IEnumerator IEnumerable.GetEnumerator() => items.GetEnumerator ();
+
+               public void CopyTo(Array array, int index) => items.ToArray().CopyTo (array, index);
+       }
+}
+
diff --git a/Drawing2D/src/ValueChangeEventArgs.cs b/Drawing2D/src/ValueChangeEventArgs.cs
new file mode 100644 (file)
index 0000000..854e2cd
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using System;
+
+namespace Crow
+{
+       /// <summary>
+       /// Arguments for the ValueChange event used for Binding
+       /// </summary>
+       public class ValueChangeEventArgs: EventArgs
+       {
+               /// <summary>The name of the member whose value has changed</summary>
+               public string MemberName;
+               /// <summary>New value for that member</summary>
+               public object NewValue;
+
+               /// <summary>
+               /// Initializes a new instance of the <see cref="T:Crow.ValueChangeEventArgs"/> class.
+               /// </summary>
+               /// <param name="_memberName">Member name.</param>
+               /// <param name="_newValue">New value.</param>
+               public ValueChangeEventArgs (string _memberName, object _newValue) : base()
+               {
+                       MemberName = _memberName;
+                       NewValue = _newValue;
+               }
+       }
+}
+
index 1385acc491c5c459bdd387bb6011c47476896e11..2eaccda2a21758b11c3fc4a804805325f0c340f3 100644 (file)
@@ -1,6 +1,6 @@
-<Grid ColumnCount="2" RowCount="2">
-       <Label/>
-       <Label/>
-       <Label/>
-       <Label/>
+<Grid ColumnCount="3" RowCount="3" Width="Stretched" Height="Stretched" Background="Green">
+       <Label HorizontalAlignment="Right"/>
+       <Label HorizontalAlignment="Right"/>
+       <Label VerticalAlignment="Top"/>
+       <Label Background="RebeccaPurple"/>
 </Grid>
\ No newline at end of file