From: Jean-Philippe Bruyère Date: Tue, 29 Jul 2025 08:48:01 +0000 (+0200) Subject: widget Margin as Size -> h and v margin now X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=04b647974ed73fe719e5acfaedfcffb2e09717d9;p=jp%2Fcrow.git widget Margin as Size -> h and v margin now --- diff --git a/Backends/CairoBackend/src/ImageBackend.cs b/Backends/CairoBackend/src/ImageBackend.cs index 20a5c64e..33a7dbd1 100644 --- a/Backends/CairoBackend/src/ImageBackend.cs +++ b/Backends/CairoBackend/src/ImageBackend.cs @@ -71,14 +71,14 @@ namespace Crow.CairoBackend ctx.Rectangle (clipping.GetRectangle (i)); ctx.Clip (); - ctx.PushGroup (); + //ctx.PushGroup (); return ctx; } public override void FlushUIFrame(IContext ctx) { - ctx.PopGroupToSource (); - ctx.Paint (); + /*ctx.PopGroupToSource (); + ctx.Paint ();*/ surf.Flush (); base.FlushUIFrame (ctx); diff --git a/Crow/src/Widgets/GenericStack.cs b/Crow/src/Widgets/GenericStack.cs index 9325238d..f11835e8 100644 --- a/Crow/src/Widgets/GenericStack.cs +++ b/Crow/src/Widgets/GenericStack.cs @@ -64,13 +64,13 @@ namespace Crow { if (Orientation == Orientation.Horizontal) //return contentSize.Width + totSpace + 2 * Margin; return stretchedGO == null ? - contentSize.Width + totSpace + 2 * Margin : - contentSize.Width + stretchedGO.measureRawSize(lt) + totSpace + 2 * Margin; + contentSize.Width + totSpace + 2 * Margin.Width : + contentSize.Width + stretchedGO.measureRawSize(lt) + totSpace + 2 * Margin.Width; } else if (Orientation == Orientation.Vertical) //return contentSize.Height + totSpace + 2 * Margin; return stretchedGO == null ? - contentSize.Height + totSpace + 2 * Margin : - contentSize.Height + stretchedGO.measureRawSize(lt) + totSpace + 2 * Margin; + contentSize.Height + totSpace + 2 * Margin.Height : + contentSize.Height + stretchedGO.measureRawSize(lt) + totSpace + 2 * Margin.Height; return base.measureRawSize (lt); } finally { diff --git a/Crow/src/Widgets/Image.cs b/Crow/src/Widgets/Image.cs index a6f55937..48c86c50 100644 --- a/Crow/src/Widgets/Image.cs +++ b/Crow/src/Widgets/Image.cs @@ -234,15 +234,15 @@ namespace Crow public override int measureRawSize (LayoutingType lt) { if (_pic == null) - return 2 * Margin; + return lt == LayoutingType.Width ? 2 * Margin.Width : 2 * Margin.Height; if (!_pic.IsLoaded) _pic.load (IFace); //_pic = "#Crow.Images.Icons.IconAlerte.svg"; //TODO:take scalling in account if (lt == LayoutingType.Width) - return _pic.Dimensions.Width + 2 * Margin; + return _pic.Dimensions.Width + 2 * Margin.Width; else - return _pic.Dimensions.Height + 2 * Margin; + return _pic.Dimensions.Height + 2 * Margin.Width; } protected override void onDraw (IContext gr) { diff --git a/Crow/src/Widgets/Label.cs b/Crow/src/Widgets/Label.cs index a35151ea..14eb67fd 100644 --- a/Crow/src/Widgets/Label.cs +++ b/Crow/src/Widgets/Label.cs @@ -656,7 +656,7 @@ namespace Crow } } DbgLogger.EndEvent(DbgEvtType.GOMeasure); - return Margin * 2 + (lt == LayoutingType.Height ? cachedTextSize.Height : cachedTextSize.Width); + return lt == LayoutingType.Height ? cachedTextSize.Height + 2 * Margin.Height : cachedTextSize.Width + 2 * Margin.Width; } protected override void onDraw (IContext gr) diff --git a/Crow/src/Widgets/Label2.cs b/Crow/src/Widgets/Label2.cs index ffe5bf4e..be0c2872 100644 --- a/Crow/src/Widgets/Label2.cs +++ b/Crow/src/Widgets/Label2.cs @@ -600,7 +600,7 @@ namespace Crow measureTextBounds (gr); } } - return Margin * 2 + (lt == LayoutingType.Height ? cachedTextSize.Height : cachedTextSize.Width); + return lt == LayoutingType.Height ? cachedTextSize.Height + 2 * Margin.Height : cachedTextSize.Width + 2 * Margin.Width; } finally { DbgLogger.EndEvent(DbgEvtType.GOMeasure); } diff --git a/Crow/src/Widgets/Shape.cs b/Crow/src/Widgets/Shape.cs index 8322543e..9ab5e74e 100644 --- a/Crow/src/Widgets/Shape.cs +++ b/Crow/src/Widgets/Shape.cs @@ -251,7 +251,7 @@ namespace Crow } } return lt == LayoutingType.Width ? - contentSize.Width + 2 * Margin : contentSize.Height + 2 * Margin; + contentSize.Width + 2 * Margin.Width : contentSize.Height + 2 * Margin.Height; } } } diff --git a/Crow/src/Widgets/Table.cs b/Crow/src/Widgets/Table.cs index f5eb3188..71149328 100644 --- a/Crow/src/Widgets/Table.cs +++ b/Crow/src/Widgets/Table.cs @@ -357,7 +357,7 @@ namespace Crow double x = 0; if (VerticalLineWidth > 0) { gr.LineWidth = VerticalLineWidth; - x = cb.Left + HeaderRow.Margin + 0.5 * ColumnSpacing + HeaderRow.Children[0].Slot.Width;// - 0.5 * VerticalLineWidth; + x = cb.Left + HeaderRow.Margin.Width + 0.5 * ColumnSpacing + HeaderRow.Children[0].Slot.Width;// - 0.5 * VerticalLineWidth; for (int i = 1; i < HeaderRow.Children.Count ; i++) { gr.MoveTo (x, cb.Y); @@ -369,7 +369,7 @@ namespace Crow if (HorizontalLineWidth > 0) { gr.LineWidth = HorizontalLineWidth; - x = cb.Top + 0.5 * Spacing + Children[0].Slot.Height;// - 0.5 * HorizontalLineWidth; + x = cb.Top + HeaderRow.Margin.Height + 0.5 * Spacing + Children[0].Slot.Height;// - 0.5 * HorizontalLineWidth; for (int i = 1; i < Children.Count; i++) { gr.MoveTo (cb.Left, x); diff --git a/Crow/src/Widgets/TemplatedGroup.cs b/Crow/src/Widgets/TemplatedGroup.cs index 1b4cf320..3ae151b9 100644 --- a/Crow/src/Widgets/TemplatedGroup.cs +++ b/Crow/src/Widgets/TemplatedGroup.cs @@ -618,7 +618,7 @@ namespace Crow { if (scroller != null && selectedItemContainer != null && itemsContainer is GenericStack gs) { Rectangle scrollerCb = scroller.ClientRectangle; Rectangle cb = gs.Slot; - Rectangle rItem = selectedItemContainer.Slot + new Point (gs.Margin); + Rectangle rItem = selectedItemContainer.Slot + gs.Margin; if (gs.Orientation == Orientation.Vertical) { if (rItem.Y - scroller.ScrollY < 0) scroller.ScrollY = rItem.Y; diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index 1a7f1e7b..a087e763 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -275,7 +275,7 @@ namespace Crow protected Measure width, height; int left, top; double cornerRadius; - int margin; + Size margin; bool focusable ; bool hasFocus; bool isActive; @@ -438,7 +438,7 @@ namespace Crow return Slot; if (Parent is Widget p) return Slot + p.RelativeSlot (target).Position + Margin; - return Slot + new Point(Margin, Margin); + return Slot + Margin; } /// /// Widget coordintate relative to the main drawing surface, normally a GLFW window. @@ -925,7 +925,7 @@ namespace Crow /// [DesignCategory ("Appearance")][DefaultValue(0.0)] public virtual double CornerRadius { - get { return cornerRadius; } + get => cornerRadius; set { if (value == cornerRadius) return; @@ -938,9 +938,9 @@ namespace Crow /// This is a single integer for the 4 direction, a gap between the control and it's container, /// by default it is filled with the background. /// - [DesignCategory ("Layout")][DefaultValue(0)] - public virtual int Margin { - get { return margin; } + [DesignCategory ("Layout")][DefaultValue("0,0")] + public virtual Size Margin { + get => margin; set { if (value == margin) return; @@ -952,7 +952,7 @@ namespace Crow /// /// set the visible state of the control, invisible controls does reserve space in the layouting system. /// - [Obsolete][DesignCategory ("Appearance")][DefaultValue(true)] + [Obsolete("Use IsVisible instead.")][DesignCategory ("Appearance")][DefaultValue(true)] public virtual bool Visible { get => IsVisible; set => IsVisible = value; @@ -1627,7 +1627,7 @@ namespace Crow try { DbgLogger.SetMsg(DbgEvtType.GOMeasure, $"{lt} contentSize:{contentSize}"); return lt == LayoutingType.Width ? - contentSize.Width + 2 * margin : contentSize.Height + 2 * margin; + contentSize.Width + 2 * margin.Width : contentSize.Height + 2 * margin.Height; } finally { DbgLogger.EndEvent(DbgEvtType.GOMeasure); } diff --git a/Crow/src/Widgets/Wrapper.cs b/Crow/src/Widgets/Wrapper.cs index b4a7484c..ed402be7 100644 --- a/Crow/src/Widgets/Wrapper.cs +++ b/Crow/src/Widgets/Wrapper.cs @@ -136,7 +136,7 @@ namespace Crow if (dy == 0) tmp -= Spacing; - return tmp + largestChild + 2 * Margin; + return tmp + largestChild + 2 * Margin.Width; } } else if (Orientation == Orientation.Horizontal) { Height = Measure.Stretched; @@ -171,7 +171,7 @@ namespace Crow if (dx == 0) tmp -= Spacing; - return tmp + tallestChild + 2 * Margin; + return tmp + tallestChild + 2 * Margin.Height; } } finally { DbgLogger.EndEvent(DbgEvtType.GOMeasure); diff --git a/Drawing2D/src/Rectangle.cs b/Drawing2D/src/Rectangle.cs index d120de69..a959b555 100644 --- a/Drawing2D/src/Rectangle.cs +++ b/Drawing2D/src/Rectangle.cs @@ -72,6 +72,13 @@ namespace Drawing2D { this.Y -= yDelta; this.Height += 2 * yDelta; } + public void Inflate(Size delta) + { + this.X -= delta.Width; + this.Width += 2 * delta.Width; + this.Y -= delta.Height; + this.Height += 2 * delta.Height; + } public void Inflate(int delta) { Inflate (delta, delta); diff --git a/Drawing2D/src/Size.cs b/Drawing2D/src/Size.cs index dd3a6c1b..4fdf0cd5 100644 --- a/Drawing2D/src/Size.cs +++ b/Drawing2D/src/Size.cs @@ -44,8 +44,11 @@ namespace Drawing2D public static bool operator != (Size s, int i) => (s.Width != i || s.Height != i);*/ public static Size operator + (Size s1, Size s2) => new Size (s1.Width + s2.Width, s1.Height + s2.Height); public static Size operator + (Size s, int i) => new Size (s.Width + i, s.Height + i); + public static Size operator - (Size s1, Size s2) => new Size (s1.Width - s2.Width, s1.Height - s2.Height); + public static Size operator - (Size s, int i) => new Size (s.Width - i, s.Height - i); public static Size operator * (Size s, int i) => new Size (s.Width * i, s.Height * i); public static Size operator / (Size s, int i) => new Size (s.Width / i, s.Height / i); + public static Size operator -(Size s) => new Size (-s.Width, -s.Height); public static Size operator * (Size s, double i) => new Size ((int)(s.Width * i), (int)(s.Height * i)); #endregion diff --git a/Samples/common/ui/Interfaces/Divers/0.crow b/Samples/common/ui/Interfaces/Divers/0.crow index a00a5281..08296cf3 100644 --- a/Samples/common/ui/Interfaces/Divers/0.crow +++ b/Samples/common/ui/Interfaces/Divers/0.crow @@ -17,8 +17,8 @@ -