From ebb15c9f57cf0ccddcf1345648e9f2d031bae637 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Wed, 5 Mar 2025 09:12:17 +0100 Subject: [PATCH] move other classes to Drawing2d --- Crow/src/Enums.cs | 129 +--------------- Crow/src/ItemTemplate.cs | 3 - Crow/src/Widgets/GenericStack.cs | 3 +- Crow/src/Widgets/Grid.cs | 132 ++++++++--------- Crow/src/Widgets/HorizontalStack.cs | 1 + Crow/src/Widgets/Wrapper.cs | 4 +- Crow/src/XCursor.cs | 1 + Drawing2D/src/Enums copy.cs | 138 ++++++++++++++++++ {Crow => Drawing2D}/src/Font.cs | 0 Drawing2D/src/IMLAttributes.cs | 2 + {Crow => Drawing2D}/src/IObservableList.cs | 0 {Crow => Drawing2D}/src/ISelectable.cs | 0 {Crow => Drawing2D}/src/IToggle.cs | 0 {Crow => Drawing2D}/src/IValueChange.cs | 0 .../src}/ListChangedEventArg.cs | 0 {Crow => Drawing2D}/src/ObservableList.cs | 0 .../src}/ValueChangeEventArgs.cs | 0 .../ui/Interfaces/Experimental/testGrid.crow | 10 +- 18 files changed, 208 insertions(+), 215 deletions(-) create mode 100644 Drawing2D/src/Enums copy.cs rename {Crow => Drawing2D}/src/Font.cs (100%) rename {Crow => Drawing2D}/src/IObservableList.cs (100%) rename {Crow => Drawing2D}/src/ISelectable.cs (100%) rename {Crow => Drawing2D}/src/IToggle.cs (100%) rename {Crow => Drawing2D}/src/IValueChange.cs (100%) rename {Crow/src/EventArgs => Drawing2D/src}/ListChangedEventArg.cs (100%) rename {Crow => Drawing2D}/src/ObservableList.cs (100%) rename {Crow/src/EventArgs => Drawing2D/src}/ValueChangeEventArgs.cs (100%) diff --git a/Crow/src/Enums.cs b/Crow/src/Enums.cs index 866e32a9..ad113bec 100644 --- a/Crow/src/Enums.cs +++ b/Crow/src/Enums.cs @@ -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, - } - /// - /// Cursor shape use in Sliders - /// - public enum CursorType - { - /// Only Background of cursor will be drawm, you may use a bmp, svg, or shape as background for custom shape. - None, - Rectangle, - Circle, - Pentagone - } - /// - /// Color component used in color widgets - /// - public enum ColorComponent - { - Red, - Green, - Blue, - Alpha, - Hue, - Saturation, - Value - } + } diff --git a/Crow/src/ItemTemplate.cs b/Crow/src/ItemTemplate.cs index cf5bcab3..6d922886 100644 --- a/Crow/src/ItemTemplate.cs +++ b/Crow/src/ItemTemplate.cs @@ -20,9 +20,6 @@ using System.Collections; //at the root level of the item template if the dataTest is 'typeOf'... namespace Crow { - /// Test func on data, return yes if there's children - public delegate bool BooleanTestOnInstance(object instance); - /// /// Derived from Instantiator with sub data fetching facilities for hierarchical data access. /// diff --git a/Crow/src/Widgets/GenericStack.cs b/Crow/src/Widgets/GenericStack.cs index 4c0a85d9..d5375c5f 100644 --- a/Crow/src/Widgets/GenericStack.cs +++ b/Crow/src/Widgets/GenericStack.cs @@ -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 diff --git a/Crow/src/Widgets/Grid.cs b/Crow/src/Widgets/Grid.cs index 4d7edced..e5c0809f 100644 --- a/Crow/src/Widgets/Grid.cs +++ b/Crow/src/Widgets/Grid.cs @@ -1,35 +1,7 @@ -// -// Grid.cs +// Copyright (c) 2013-2025 Bruyère Jean-Philippe jp_bruyere@hotmail.com // -// Author: -// Jean-Philippe Bruyère -// -// 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; } diff --git a/Crow/src/Widgets/HorizontalStack.cs b/Crow/src/Widgets/HorizontalStack.cs index 5e16c326..517f692e 100644 --- a/Crow/src/Widgets/HorizontalStack.cs +++ b/Crow/src/Widgets/HorizontalStack.cs @@ -2,6 +2,7 @@ // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + namespace Crow { /// diff --git a/Crow/src/Widgets/Wrapper.cs b/Crow/src/Widgets/Wrapper.cs index ef7d627a..734227b7 100644 --- a/Crow/src/Widgets/Wrapper.cs +++ b/Crow/src/Widgets/Wrapper.cs @@ -2,6 +2,7 @@ // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using static Crow.Logger; + namespace Crow { /// @@ -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; diff --git a/Crow/src/XCursor.cs b/Crow/src/XCursor.cs index 2fdfa5a0..b74f7293 100644 --- a/Crow/src/XCursor.cs +++ b/Crow/src/XCursor.cs @@ -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 index 00000000..d8a975ad --- /dev/null +++ b/Drawing2D/src/Enums copy.cs @@ -0,0 +1,138 @@ +// Copyright (c) 2018-2022 Jean-Philippe Bruyère +// +// 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, + } + /// + /// Cursor shape use in Sliders + /// + public enum CursorType + { + /// Only Background of cursor will be drawm, you may use a bmp, svg, or shape as background for custom shape. + None, + Rectangle, + Circle, + Pentagone + } + /// + /// Color component used in color widgets + /// + public enum ColorComponent + { + Red, + Green, + Blue, + Alpha, + Hue, + Saturation, + Value + } +} \ No newline at end of file diff --git a/Crow/src/Font.cs b/Drawing2D/src/Font.cs similarity index 100% rename from Crow/src/Font.cs rename to Drawing2D/src/Font.cs diff --git a/Drawing2D/src/IMLAttributes.cs b/Drawing2D/src/IMLAttributes.cs index 9a6d7dfb..0c7a07a5 100644 --- a/Drawing2D/src/IMLAttributes.cs +++ b/Drawing2D/src/IMLAttributes.cs @@ -6,6 +6,8 @@ using System; namespace Crow { + /// Test func on data, return yes if there's children + public delegate bool BooleanTestOnInstance(object instance); public class XmlIgnoreAttribute : Attribute { } diff --git a/Crow/src/IObservableList.cs b/Drawing2D/src/IObservableList.cs similarity index 100% rename from Crow/src/IObservableList.cs rename to Drawing2D/src/IObservableList.cs diff --git a/Crow/src/ISelectable.cs b/Drawing2D/src/ISelectable.cs similarity index 100% rename from Crow/src/ISelectable.cs rename to Drawing2D/src/ISelectable.cs diff --git a/Crow/src/IToggle.cs b/Drawing2D/src/IToggle.cs similarity index 100% rename from Crow/src/IToggle.cs rename to Drawing2D/src/IToggle.cs diff --git a/Crow/src/IValueChange.cs b/Drawing2D/src/IValueChange.cs similarity index 100% rename from Crow/src/IValueChange.cs rename to Drawing2D/src/IValueChange.cs diff --git a/Crow/src/EventArgs/ListChangedEventArg.cs b/Drawing2D/src/ListChangedEventArg.cs similarity index 100% rename from Crow/src/EventArgs/ListChangedEventArg.cs rename to Drawing2D/src/ListChangedEventArg.cs diff --git a/Crow/src/ObservableList.cs b/Drawing2D/src/ObservableList.cs similarity index 100% rename from Crow/src/ObservableList.cs rename to Drawing2D/src/ObservableList.cs diff --git a/Crow/src/EventArgs/ValueChangeEventArgs.cs b/Drawing2D/src/ValueChangeEventArgs.cs similarity index 100% rename from Crow/src/EventArgs/ValueChangeEventArgs.cs rename to Drawing2D/src/ValueChangeEventArgs.cs diff --git a/Samples/common/ui/Interfaces/Experimental/testGrid.crow b/Samples/common/ui/Interfaces/Experimental/testGrid.crow index 1385acc4..2eaccda2 100644 --- a/Samples/common/ui/Interfaces/Experimental/testGrid.crow +++ b/Samples/common/ui/Interfaces/Experimental/testGrid.crow @@ -1,6 +1,6 @@ - -