]> O.S.I.I.S - jp/crow.git/commitdiff
widget Margin as Size -> h and v margin now textBufferForLabel
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 29 Jul 2025 08:48:01 +0000 (10:48 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 29 Jul 2025 08:48:01 +0000 (10:48 +0200)
13 files changed:
Backends/CairoBackend/src/ImageBackend.cs
Crow/src/Widgets/GenericStack.cs
Crow/src/Widgets/Image.cs
Crow/src/Widgets/Label.cs
Crow/src/Widgets/Label2.cs
Crow/src/Widgets/Shape.cs
Crow/src/Widgets/Table.cs
Crow/src/Widgets/TemplatedGroup.cs
Crow/src/Widgets/Widget.cs
Crow/src/Widgets/Wrapper.cs
Drawing2D/src/Rectangle.cs
Drawing2D/src/Size.cs
Samples/common/ui/Interfaces/Divers/0.crow

index 20a5c64ef2f01f111eeb7ff0d4a1f48e4184714c..33a7dbd1084fac42128f2526887ec805d6ee3616 100644 (file)
@@ -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);
index 9325238d6181cf96d4362ffa255f12ed1124f93c..f11835e8480f204c18316e16e41a699d13bd5380 100644 (file)
@@ -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 {
index a6f559379fa5583b11e6a9061773f40c21fbbbc6..48c86c504170b3c4f9ace70541c232c0a8e2f72a 100644 (file)
@@ -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)
                {
index a35151ea8c90230228fb842eebac59d65f282014..14eb67fdccf37c3be736e8841ce34c9be3557871 100644 (file)
@@ -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)
index ffe5bf4e16547a8be22105734fd0acc0aae236b3..be0c2872cbddf9071c9442869d5efd6623806e73 100644 (file)
@@ -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);
                        }
index 8322543e2051795c842c0561a2a1276f3fb16ae7..9ab5e74e4195d86adf47723239f5d2bb3c615df8 100644 (file)
@@ -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;
                }
        }
 }
index f5eb3188f5409bef510258041f05aa5a06527cdd..71149328a7aff37e9e431ada610d886a98539079 100644 (file)
@@ -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);
index 1b4cf320ad03b59bfe25c3e1b27eb1373fa2da49..3ae151b9f82b302c1ab69cbeed4bf5ebba3ebfa3 100644 (file)
@@ -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;
index 1a7f1e7ba0befe6410b2443795a17b4c8f91b0c9..a087e763e7f8fe96c039ebfe49ad87a1d98e13a6 100644 (file)
@@ -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;
                }
                /// <summary>
                /// Widget coordintate relative to the main drawing surface, normally a GLFW window.
@@ -925,7 +925,7 @@ namespace Crow
                /// </summary>
                [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.
                /// </summary>
-               [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
                /// <summary>
                /// set the visible state of the control, invisible controls does reserve space in the layouting system.
                /// </summary>
-               [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);
                        }
index b4a7484cf46c7eaf0e5fb1db1fe66358a6e3245c..ed402be79424b164ff51ab397a09d064bccdf313 100644 (file)
@@ -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);       
index d120de693ee8d2d6cea087cc286320f1525dbeb1..a959b55543e2fad414e209a891f35a4a131d10fb 100644 (file)
@@ -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);
index dd3a6c1bc5ed8a4ac78b5cb75d749f54ae1090d4..4fdf0cd5fdef5a90575b46f1c2370af1bf50b83c 100644 (file)
@@ -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
index a00a5281268309d3b521be64c08c3310b7e51bfb..08296cf38c98286d38104ef3629cc7823f54567d 100644 (file)
@@ -17,8 +17,8 @@
                                        </HorizontalStack>
                                </ItemTemplate>
                        </ListBox>
-                       <Label Width="Stretched" Margin="3" Background="DimGrey" />
-                       <TextBox Text="TextBox" Multiline="true" Margin="3" />
+                       <Label Width="Stretched" Margin="3,1" Background="DimGrey" />
+                       <TextBox Text="TextBox" Multiline="true" Margin="3,1" />
                        <HorizontalStack Height="Fit"  Background="Jet" CornerRadius="10" Margin="5">
                                <VerticalStack Spacing="5" Width="50%">
                                        <CheckBox Fit="true" Caption="test" />