aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2025-07-29 10:48:01 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2025-07-29 10:48:01 +0200
commit04b647974ed73fe719e5acfaedfcffb2e09717d9 (patch)
tree4a7fd9efb458e5c56a36d710d33c3e7713f3bd49
parent3f16c00248623bac4c883d3c6cd43afeaaa0d630 (diff)
widget Margin as Size -> h and v margin nowtextBufferForLabel
-rw-r--r--Backends/CairoBackend/src/ImageBackend.cs6
-rw-r--r--Crow/src/Widgets/GenericStack.cs8
-rw-r--r--Crow/src/Widgets/Image.cs6
-rw-r--r--Crow/src/Widgets/Label.cs2
-rw-r--r--Crow/src/Widgets/Label2.cs2
-rw-r--r--Crow/src/Widgets/Shape.cs2
-rw-r--r--Crow/src/Widgets/Table.cs4
-rw-r--r--Crow/src/Widgets/TemplatedGroup.cs2
-rw-r--r--Crow/src/Widgets/Widget.cs16
-rw-r--r--Crow/src/Widgets/Wrapper.cs4
-rw-r--r--Drawing2D/src/Rectangle.cs7
-rw-r--r--Drawing2D/src/Size.cs3
-rw-r--r--Samples/common/ui/Interfaces/Divers/0.crow4
13 files changed, 38 insertions, 28 deletions
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;
}
/// <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);
}
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 @@
</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" />