Saxonite 1.2.11.3. Sandtrap.

This commit is contained in:
Andy Howard
2024-04-24 17:18:05 +01:00
parent 496aaeee0b
commit 7748941680
104 changed files with 5615 additions and 177 deletions
@@ -0,0 +1,287 @@
using Sarand.Net.Standard.Base.App;
using Sarand.Net.Standard.Base.Core;
using Sarand.Net.Standard.Base.Dbas;
using Sarand.Net.Standard.Base.Helpers;
using Sarand.Net.Standard.Base.Utils;
using Sarand.Net.Mobile.Xamarin.Forms.Controls;
using Sarand.Net.Mobile.Xamarin.Forms.Layouts;
using Sarand.Net.Mobile.Xamarin.Forms.Views;
using Sarand.Net.Mobile.Xamarin.Utils;
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace Sarand.Net.Mobile.Xamarin.Forms.Panels
{
//=======================================================================
public class SaxPanel_ItemListHeader : SaxPanel
{
//-------------------------------------------------------------------
// Definitions.
public class Config
{
public Thickness? Margin { get; set; } = new Thickness(0, 0, 0, 8);
public String Caption { get; set; }
public double HeaderBorderWidth { get; set; } = 4.0;
public float HeaderBorderRadius { get; set; } = 8.0f;
public Color HeaderBorderColor { get; set; } = Color.FromHex("#808080");
public Color HeaderBackgroundColor { get; set; } = Color.FromHex("#F0F0F0");
// Labels.
// Styling.
public double CaptionLabelFontSizeRatio { get; set; } = 1.0;
public double PagingLabelFontSizeRatio { get; set; } = 1.0;
public Thickness? LabelMargin { get; set; } = null;
// Paging controls.
public static int PagingButtonWidthMin { get; } = 40;
public static int PagingButtonWidthMax { get; } = 64;
public static int PagingButtonWidthDefault { get; } = PagingButtonWidthMin;
public int PagingButtonWidth { get; set; } = PagingButtonWidthDefault;
public static int PagingButtonHeightMin { get; } = 40;
public static int PagingButtonHeightMax { get; } = 64;
public static int PagingButtonHeightDefault { get; } = PagingButtonHeightMin;
public int PagingButtonHeight { get; set; } = PagingButtonHeightDefault;
// Filters.
public List<SacsFilterPropertyType> FilterPropertyTypes { get; } = new List<SacsFilterPropertyType>();
public ushort FiltersToDisplay { get; set; } = 2;
}
//-------------------------------------------------------------------
// Data members.
private Config config;
// Layout.
private SaxFrame frame = new SaxFrame();
private SaxStackLayout mainLayout = new SaxStackLayout() { Orientation = StackOrientation.Vertical };
// Header.
private SaxWrapLayout headerLayout = new SaxWrapLayout() { SpacingX = 8.0 };
private SaxContentView captionLabelView = new SaxContentView();
private SaxLabel labelCaption = new SaxLabel() { Text = "" };
private double initialLabelFontSize = 0;
// Paging.
private class PagingData : DbQuery.Paging
{
public int TotalItems { get; set; }
public int TotalPages { get { return PageLength > 0 ? (int)Math.Ceiling((double)TotalItems / PageLength) : 0; } }
public override bool Paged { get { return base.Paged && TotalItems > 0; } }
}
private readonly PagingData paging = new PagingData();
private SaxStackLayout pagingStack = new SaxStackLayout() { Orientation = StackOrientation.Horizontal };
private SaxLabel labelPaging = new SaxLabel() { Text = "[Paging]" };
private SaxImageButton buttonPagingFirst = new SaxImageButton() { WidthRequest = 32, HeightRequest = 32, Aspect = Aspect.AspectFit, Padding = new Thickness(2, 4), BackgroundColor = Color.Transparent };
private SaxImageButton buttonPagingPrev = new SaxImageButton() { WidthRequest = 32, HeightRequest = 32, Aspect = Aspect.AspectFit, Padding = new Thickness(2, 4), BackgroundColor = Color.Transparent };
private SaxImageButton buttonPagingNext = new SaxImageButton() { WidthRequest = 32, HeightRequest = 32, Aspect = Aspect.AspectFit, Padding = new Thickness(2, 4), BackgroundColor = Color.Transparent };
private SaxImageButton buttonPagingLast = new SaxImageButton() { WidthRequest = 32, HeightRequest = 32, Aspect = Aspect.AspectFit, Padding = new Thickness(2, 4), BackgroundColor = Color.Transparent };
//-------------------------------------------------------------------
// Construction.
public SaxPanel_ItemListHeader(Config config)
{
this.config = config;
initialLabelFontSize = labelCaption.FontSize;
InitialiseComponents();
}
//-------------------------------------------------------------------
// Properties.
// Filter.
public SaxPanel_ItemFilter PanelFilter { get; private set; }
// Paging.
public uint PageNo { get { return paging.PageNo; } }
public ushort PageLength { get { return paging.PageLength; } }
public int TotalItems { get { return paging.TotalItems; } }
//-------------------------------------------------------------------
// I n i t i a l i s e
//-------------------------------------------------------------------
private void InitialiseComponents()
{
// Frame - to allow rounded corners.
Content = frame;
frame.Content = mainLayout;
// Header.
mainLayout.Spacing = 0;
mainLayout.HorizontalOptions = LayoutOptions.StartAndExpand;
mainLayout.BackgroundColor = Color.Transparent;
//headerLayout.BackgroundColor = Color.LightYellow;
mainLayout.Children.Add(headerLayout);
// Header - Caption.
captionLabelView.VerticalOptions = LayoutOptions.Center;
labelCaption.FontAttributes = FontAttributes.Bold;
labelCaption.HorizontalOptions = LayoutOptions.StartAndExpand;
labelCaption.VerticalOptions = LayoutOptions.CenterAndExpand;
labelCaption.LineBreakMode = LineBreakMode.NoWrap;
labelCaption.PropertyChanging += LabelCaption_PropertyChanging;
// Label is embedded in view to ensure correct sizing.
captionLabelView.Content = labelCaption;
headerLayout.Children.Add(captionLabelView);
// Header - Paging.
pagingStack.HorizontalOptions = LayoutOptions.EndAndExpand;
pagingStack.VerticalOptions = LayoutOptions.CenterAndExpand;
headerLayout.Children.Add(pagingStack);
labelPaging.VerticalOptions = LayoutOptions.CenterAndExpand;
pagingStack.Children.Add(labelPaging);
pagingStack.Children.Add(buttonPagingFirst);
pagingStack.Children.Add(buttonPagingPrev);
pagingStack.Children.Add(buttonPagingNext);
pagingStack.Children.Add(buttonPagingLast);
// Paging actions.
buttonPagingFirst.Clicked += ButtonPagingFirst_Clicked;
buttonPagingPrev.Clicked += ButtonPagingPrev_Clicked;
buttonPagingNext.Clicked += ButtonPagingNext_Clicked;
buttonPagingLast.Clicked += ButtonPagingLast_Clicked;
// Complete panel configuration.
ConfigurePanel();
}
private void LabelCaption_PropertyChanging(object sender, PropertyChangingEventArgs e)
{
if (e.PropertyName.EqualsCI("Height"))
{
}
}
//-------------------------------------------------------------------
// C o n f i g u r e P a n e l
//-------------------------------------------------------------------
private void ConfigurePanel()
{
if (config.Margin != null)
frame.Margin = (Thickness)config.Margin;
// Header.
labelCaption.Text = StringUtil.EmptyOnNull(config.Caption);
frame.Padding = new Thickness(config.HeaderBorderWidth);
frame.CornerRadius = config.HeaderBorderRadius;
frame.BorderColor = config.HeaderBorderColor;
frame.BackgroundColor = config.HeaderBackgroundColor;
// Labels.
labelCaption.FontSize = initialLabelFontSize * config.CaptionLabelFontSizeRatio;
labelPaging.FontSize = initialLabelFontSize * config.PagingLabelFontSizeRatio;
if (config.LabelMargin != null)
{
labelCaption.Margin = (Thickness)config.LabelMargin;
labelPaging.Margin = (Thickness)config.LabelMargin;
}
// Paging controls.
buttonPagingFirst.Source = SacsImageUtils.GetImageFromByteArray(SacsResourceHelper.GetResourceImage(SacsResourceHelper.ImageResource.Arrow_Left_Double_Black_24_png));
buttonPagingFirst.WidthRequest = Math.Max(Config.PagingButtonWidthMin, Math.Min(Config.PagingButtonWidthMax, config.PagingButtonWidth));
buttonPagingFirst.HeightRequest = Math.Max(Config.PagingButtonHeightMin, Math.Min(Config.PagingButtonHeightMax, config.PagingButtonHeight));
buttonPagingPrev.Source = SacsImageUtils.GetImageFromByteArray(SacsResourceHelper.GetResourceImage(SacsResourceHelper.ImageResource.Arrow_Left_Black_24_png));
buttonPagingPrev.WidthRequest = Math.Max(Config.PagingButtonWidthMin, Math.Min(Config.PagingButtonWidthMax, config.PagingButtonWidth));
buttonPagingPrev.HeightRequest = Math.Max(Config.PagingButtonHeightMin, Math.Min(Config.PagingButtonHeightMax, config.PagingButtonHeight));
buttonPagingNext.Source = SacsImageUtils.GetImageFromByteArray(SacsResourceHelper.GetResourceImage(SacsResourceHelper.ImageResource.Arrow_Right_Black_24_png));
buttonPagingNext.WidthRequest = Math.Max(Config.PagingButtonWidthMin, Math.Min(Config.PagingButtonWidthMax, config.PagingButtonWidth));
buttonPagingNext.HeightRequest = Math.Max(Config.PagingButtonHeightMin, Math.Min(Config.PagingButtonHeightMax, config.PagingButtonHeight));
buttonPagingLast.Source = SacsImageUtils.GetImageFromByteArray(SacsResourceHelper.GetResourceImage(SacsResourceHelper.ImageResource.Arrow_Right_Double_Black_24_png));
buttonPagingLast.WidthRequest = Math.Max(Config.PagingButtonWidthMin, Math.Min(Config.PagingButtonWidthMax, config.PagingButtonWidth));
buttonPagingLast.HeightRequest = Math.Max(Config.PagingButtonHeightMin, Math.Min(Config.PagingButtonHeightMax, config.PagingButtonHeight));
RefreshPaging();
// Property type filters.
SaxPanel_ItemFilter.Config propertyFilterConfig = new SaxPanel_ItemFilter.Config();
propertyFilterConfig.FilterPropertyTypes.AddRange(config.FilterPropertyTypes);
propertyFilterConfig.FiltersToDisplay = config.FiltersToDisplay;
if (PanelFilter == null)
{
PanelFilter = new SaxPanel_ItemFilter(propertyFilterConfig);
mainLayout.Children.Add(PanelFilter);
}
else
{
PanelFilter.SetConfig(propertyFilterConfig);
}
}
//-------------------------------------------------------------------
// P a g i n g
//-------------------------------------------------------------------
public void SetPaging(uint pageNo, ushort pageLength, int totalItems)
{
paging.PageNo = pageNo;
paging.PageLength = pageLength;
paging.TotalItems = totalItems;
RefreshPaging();
}
private void RefreshPaging()
{
String pagingText = "";
Boolean paged = (paging.Paged && paging.TotalPages > 1);
if (paging.TotalItems > 0)
{
if (paged)
pagingText = "Page " + paging.PageNo + " of " + paging.TotalPages;
else
pagingText = paging.TotalItems + " items";
}
labelPaging.Text = pagingText;
// Control visibility.
labelPaging.IsVisible = !StringUtil.IsEmpty(labelPaging.Text);
buttonPagingFirst.IsVisible = paged;
buttonPagingPrev.IsVisible = paged;
buttonPagingNext.IsVisible = paged;
buttonPagingLast.IsVisible = paged;
// Button activity.
buttonPagingFirst.IsEnabled = paging.PageNo > 1;
buttonPagingPrev.IsEnabled = paging.PageNo > 1;
buttonPagingNext.IsEnabled = paging.PageNo < paging.TotalPages;
buttonPagingLast.IsEnabled = paging.PageNo < paging.TotalPages;
}
//-------------------------------------------------------------------
// Paging events.
public enum PagingActionType
{
Unknown,
First,
Next,
Prev,
Last
}
public class PagingActionEventArgs : EventArgs
{
public PagingActionType PagingActionType { get; set; } = PagingActionType.Unknown;
}
public event EventHandler<PagingActionEventArgs> PagingAction;
private void FirePagingActionEvent(PagingActionType pagingActionType)
{
PagingActionEventArgs filterChangedEventArgs = new PagingActionEventArgs()
{
PagingActionType = pagingActionType,
};
if (PagingAction != null) PagingAction.Invoke(this, filterChangedEventArgs);
}
//-------------------------------------------------------------------
// Paging actions.
private void ButtonPagingFirst_Clicked(object sender, EventArgs e)
{
FirePagingActionEvent(PagingActionType.First);
}
private void ButtonPagingPrev_Clicked(object sender, EventArgs e)
{
FirePagingActionEvent(PagingActionType.Prev);
}
private void ButtonPagingNext_Clicked(object sender, EventArgs e)
{
FirePagingActionEvent(PagingActionType.Next);
}
private void ButtonPagingLast_Clicked(object sender, EventArgs e)
{
FirePagingActionEvent(PagingActionType.Last);
}
//-------------------------------------------------------------------
// P a n e l E v e n t s
//-------------------------------------------------------------------
//-------------------------------------------------------------------
}
//=======================================================================
}