Skip to content

Commit

Permalink
change api that name have Reference to use Ref, it is short; use Logg…
Browse files Browse the repository at this point in the history
…er as default Debug
  • Loading branch information
xtuzy committed Mar 2, 2023
1 parent 3602374 commit 3b6ff70
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 24 deletions.
8 changes: 4 additions & 4 deletions SharpConstraintLayout.Maui.Example/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void GroupTest(ConstraintLayout page)
var group = new Group();
var layout = page;
layout.AddElement(group, FirstButton, SecondButton, FouthTextBlock, FifthTextBox, SixthRichTextBlock);
group.ReferenceElement(FirstButton, FouthTextBlock);
group.RefElement(FirstButton, FouthTextBlock);
using (var set = new FluentConstraintSet())
{
set.Clone(layout);
Expand Down Expand Up @@ -65,7 +65,7 @@ void FlowPerformanceTest(ConstraintLayout page)
page.AddElement(flow);

page.AddElement(FifthTextBox);
flow.ReferenceElement(FifthTextBox);
flow.RefElement(FifthTextBox);
//Generate 1000 Button,all add to page

var buttonList = new List<Button>();
Expand All @@ -76,7 +76,7 @@ void FlowPerformanceTest(ConstraintLayout page)
button.Text = "Button" + i;
buttonList.Add(button);
page.AddElement(button);
flow.ReferenceElement(button);
flow.RefElement(button);
}

using (var layoutSet = new FluentConstraintSet())
Expand Down Expand Up @@ -312,7 +312,7 @@ void FlowTest(ConstraintLayout page)
flow.SetHorizontalStyle(SharpConstraintLayout.Maui.Helper.Widget.Flow.ChainSpreadInside);
var layout = page;
layout.AddElement(ThirdCanvas, FirstButton, SecondButton, FouthTextBlock, FifthTextBox, SixthRichTextBlock, flow);
flow.ReferenceElement(FirstButton, SecondButton, FouthTextBlock, FifthTextBox, SixthRichTextBlock);
flow.RefElement(FirstButton, SecondButton, FouthTextBlock, FifthTextBox, SixthRichTextBlock);

using (var layoutSet = new FluentConstraintSet())
{
Expand Down
4 changes: 2 additions & 2 deletions SharpConstraintLayout.Maui/Widget/ConstraintHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected virtual void WhenAttachedToWindow() { }
/// The view also need to have its id set in order to be added.
/// </summary>
/// <param name="view"> </param>
public virtual void ReferenceElement(FrameworkElement view)
public virtual void RefElement(FrameworkElement view)
{

if (view == this)
Expand All @@ -121,7 +121,7 @@ public virtual void ReferenceElement(FrameworkElement view)
/// </summary>
/// <param name="view"> </param>
/// <returns> index of view removed </returns>
public virtual int RemoveElement(FrameworkElement view)
public virtual int RemoveRefElement(FrameworkElement view)
{
int index = -1;
//int id = view.Id;
Expand Down
1 change: 0 additions & 1 deletion SharpConstraintLayout.Maui/Widget/ConstraintLayout.Maui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace SharpConstraintLayout.Maui.Widget
{
public partial class ConstraintLayout : IMauiConstraintLayout
{
ILogger Logger { get; set; }
public ConstraintLayout()
{
init();
Expand Down
7 changes: 6 additions & 1 deletion SharpConstraintLayout.Maui/Widget/ConstraintLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public partial class ConstraintLayout : Panel, IConstraintLayout
/// </summary>
public static bool DEBUG = false;
public string DebugName;
/// <summary>
/// 从Maui引入, Debug用它
/// </summary>
ILogger Logger { get; set; }

/// <summary>
/// if is true,will print time of measure spend.
/// </summary>
Expand Down Expand Up @@ -1083,7 +1088,7 @@ public void AndroidSourceCodeMeasureUseSpecForWindows(ConstraintWidget widget, B
// if the dimensions of the solver widget are already the same as the real view, no need to remeasure.
if (DEBUG)
{
SimpleDebug.WriteLine("SKIPPED " + child.GetType().FullName + widget);
outerInstance.Logger?.LogDebug("SKIPPED " + child.GetType().FullName + widget);
}
return;
}
Expand Down
6 changes: 3 additions & 3 deletions SharpConstraintLayout.Maui/Widget/ConstraintSet.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ public virtual void ApplyTo(ConstraintLayout constraintLayout, bool isImmediateT

int count = constraintLayout.ChildCount;
List<int> used = mConstraints.Keys.ToList();//已经设置了约束的id
if (count != used.Count) Logger.LogInformation("The count of ConstraintLayout children is not equal to temprary constraints list, maybe you not use clone.", TAG);
if (count != used.Count) Logger?.LogInformation("The count of ConstraintLayout children is not equal to temprary constraints list, maybe you not use clone.", TAG);
for (int i = 0; i < count; i++)//查看layout的child
{
View view = constraintLayout.GetChildAt(i);

int id = view.GetId();
if (!mConstraints.ContainsKey(id))
{
Logger.LogError($"id unknown {view}", TAG);
Logger?.LogError($"id unknown {view}", TAG);
continue;
}

Expand Down Expand Up @@ -316,7 +316,7 @@ public virtual void ApplyTo(ConstraintLayout constraintLayout, bool isImmediateT
}
else
{
Logger.LogWarning(TAG, "WARNING NO CONSTRAINTS for view " + id);
Logger?.LogWarning(TAG, "WARNING NO CONSTRAINTS for view " + id);
}
}

Expand Down
12 changes: 6 additions & 6 deletions SharpConstraintLayout.Maui/Widget/FluentConstraintSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,26 +1111,26 @@ public static void AddElement(this ConstraintLayout layout, params UIElement[] v
public static class FluentConstraintHelperExtension
{
#if WINDOWS && !__MAUI__
public static void ReferenceElement(this ConstraintHelper helper, params FrameworkElement[] views)
public static void RefElement(this ConstraintHelper helper, params FrameworkElement[] views)
#else
public static void ReferenceElement(this ConstraintHelper helper, params UIElement[] views)
public static void RefElement(this ConstraintHelper helper, params UIElement[] views)
#endif
{
foreach (var view in views)
{
helper.ReferenceElement(view);
helper.RefElement(view);
}
}

#if WINDOWS && !__MAUI__
public static void RemoveElement(this ConstraintHelper helper, params FrameworkElement[] views)
public static void RemoveRefElement(this ConstraintHelper helper, params FrameworkElement[] views)
#else
public static void RemoveElement(this ConstraintHelper helper, params UIElement[] views)
public static void RemoveRefElement(this ConstraintHelper helper, params UIElement[] views)
#endif
{
foreach (var view in views)
{
helper.RemoveElement(view);
helper.RemoveRefElement(view);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public interface IConstraintHelper
{
//JniPeerMembers JniPeerMembers { get; }

void ReferenceElement(View view);
void RefElement(View view);
bool ContainsId(int id);
//int[] GetReferencedIds();
int IndexFromId(int id);
//void LoadParameters(ConstraintSet.Constraint constraint, HelperWidget child, ConstraintLayout.LayoutParams layoutParams ,Dictionary<int,ConstraintWidget> mapIdToWidget);
void LoadParameters(ConstraintSet.Constraint constraint, HelperWidget child, Dictionary<int, ConstraintWidget> mapIdToWidget);
//void OnDraw(Canvas canvas);
int RemoveElement(View view);
int RemoveRefElement(View view);
void ResolveRtl(ConstraintWidget widget, bool isRtl);
//void SetReferencedIds(int[] ids);
int[] ReferencedIds { set; get; }
Expand Down
2 changes: 1 addition & 1 deletion SharpConstraintLayout.Maui/Widget/UIElementExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ internal static void SetAlpha(this UIElement element, float alpha)
#endif
}

internal static string GetViewLayoutInfo(this UIElement element)
public static string GetViewLayoutInfo(this UIElement element)
{
#if __MAUI__
return $"{element.GetType().FullName} IsVisible={element.IsVisible} Position=({element.X},{element.Y}) DesiredSize={element.DesiredSize} WidthxHeight=({element.Width}x{element.Height})";
Expand Down
2 changes: 1 addition & 1 deletion SharpConstraintLayout.Maui/Widget/UIThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static void Invoke(Action action, ConstraintLayout constraintLayout)
#elif WINDOWS
if (constraintLayout.DispatcherQueue == null)
{
SimpleDebug.WriteLine("UIThread.Invoke: ConstraintLayout.DispatcherQueue == null");
throw new Exception("UIThread.Invoke: ConstraintLayout.DispatcherQueue == null");
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion SharpConstraintLayout.Maui/Widget/ViewInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SharpConstraintLayout.Maui.Widget
using System;

namespace SharpConstraintLayout.Maui.Widget
{
public enum ViewInfoType
{
Expand Down
3 changes: 1 addition & 2 deletions SharpConstraintLayout.Maui/Widget/VirtualLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
* limitations under the License.
*/
#if __MAUI__
using Microsoft.Extensions.Logging;
using SharpConstraintLayout.Maui.Widget.Interface;
using FrameworkElement = Microsoft.Maui.Controls.View;
using UIElement = Microsoft.Maui.Controls.View;

#elif WINDOWS
using Microsoft.UI.Xaml;
using SharpConstraintLayout.Maui.Widget.Interface;
Expand All @@ -34,6 +32,7 @@
using SharpConstraintLayout.Maui.Widget.Interface;
using FrameworkElement = Android.Views.View;
#endif
using Microsoft.Extensions.Logging;
namespace SharpConstraintLayout.Maui.Widget
{

Expand Down

0 comments on commit 3b6ff70

Please sign in to comment.