More work on layouts
This commit is contained in:
Родитель
6d634c3135
Коммит
2e08a25572
|
@ -19,6 +19,11 @@ namespace HotUI.UWP.Handlers
|
|||
_layoutManager = layoutManager;
|
||||
}
|
||||
|
||||
public SizeF GetAvailableSize()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public SizeF GetSize(UIElement view)
|
||||
{
|
||||
if (view.RenderSize.Width <= 0 && view.RenderSize.Height <= 0) return view.DesiredSize.ToSizeF();
|
||||
|
|
|
@ -18,6 +18,11 @@ namespace HotUI.WPF.Handlers
|
|||
_layoutManager = layoutManager;
|
||||
}
|
||||
|
||||
public SizeF GetAvailableSize()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public SizeF GetSize(UIElement view)
|
||||
{
|
||||
if (view.RenderSize.Width <= 0 && view.RenderSize.Height <= 0)
|
||||
|
|
|
@ -11,10 +11,9 @@ namespace HotUI.iOS {
|
|||
}
|
||||
public static UIViewController ToViewController (this View view, bool allowNav = true)
|
||||
{
|
||||
var handler = view.ToIUIView ();
|
||||
|
||||
var vc = new HotUIViewController {
|
||||
CurrentView = handler,
|
||||
var vc = new HotUIViewController
|
||||
{
|
||||
CurrentView = view,
|
||||
};
|
||||
if (view.BuiltView is NavigationView nav && allowNav) {
|
||||
var navController = new UINavigationController ();
|
||||
|
|
|
@ -11,6 +11,8 @@ namespace HotUI.iOS
|
|||
private readonly ILayoutManager<UIView> _layoutManager;
|
||||
private AbstractLayout _view;
|
||||
|
||||
public AbstractLayout Layout => _view;
|
||||
|
||||
protected AbstractLayoutHandler(CGRect rect, ILayoutManager<UIView> layoutManager) : base(rect)
|
||||
{
|
||||
_layoutManager = layoutManager;
|
||||
|
@ -22,6 +24,11 @@ namespace HotUI.iOS
|
|||
_layoutManager = layoutManager;
|
||||
}
|
||||
|
||||
public SizeF GetAvailableSize()
|
||||
{
|
||||
return Superview?.Bounds.Size.ToSizeF() ?? Bounds.Size.ToSizeF();
|
||||
}
|
||||
|
||||
public SizeF GetSize(UIView view)
|
||||
{
|
||||
return view.Bounds.Size.ToSizeF();
|
||||
|
@ -130,7 +137,16 @@ namespace HotUI.iOS
|
|||
|
||||
public override void LayoutSubviews()
|
||||
{
|
||||
if (Superview == null)
|
||||
return;
|
||||
|
||||
_layoutManager.Layout(this, this, _view);
|
||||
}
|
||||
|
||||
public override void MovedToSuperview()
|
||||
{
|
||||
base.MovedToSuperview();
|
||||
SetNeedsLayout();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using UIKit;
|
||||
|
||||
// ReSharper disable ClassNeverInstantiated.Global
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
namespace HotUI.iOS
|
||||
{
|
||||
public class SpacerHandler : UIView, IUIView
|
||||
{
|
||||
private static readonly PropertyMapper<Spacer, UIView> Mapper = new PropertyMapper<Spacer, UIView>()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
private Spacer _spacer;
|
||||
|
||||
public UIView View => this;
|
||||
|
||||
public void Remove(View view)
|
||||
{
|
||||
_spacer = null;
|
||||
}
|
||||
|
||||
public void SetView(View view)
|
||||
{
|
||||
_spacer = view as Spacer;
|
||||
Mapper.UpdateProperties(this, _spacer);
|
||||
}
|
||||
|
||||
public void UpdateValue(string property, object value)
|
||||
{
|
||||
Mapper.UpdateProperty(this, _spacer, property);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,6 +47,7 @@
|
|||
<Compile Include="Extensions\CoreGraphicsExtensions.cs" />
|
||||
<Compile Include="Handlers\AbstractLayoutHandler.cs" />
|
||||
<Compile Include="Handlers\HStackHandler.cs" />
|
||||
<Compile Include="Handlers\SpacerHandler.cs" />
|
||||
<Compile Include="Handlers\VStackHandler.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Handlers\ButtonHandler.cs" />
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using CoreGraphics;
|
||||
using CoreGraphics;
|
||||
using UIKit;
|
||||
|
||||
namespace HotUI.iOS
|
||||
|
@ -10,20 +9,22 @@ namespace HotUI.iOS
|
|||
{
|
||||
}
|
||||
|
||||
IUIView currentView;
|
||||
private View _view;
|
||||
private IUIView _handler;
|
||||
|
||||
public IUIView CurrentView
|
||||
public View CurrentView
|
||||
{
|
||||
get => currentView;
|
||||
get => _view;
|
||||
set
|
||||
{
|
||||
if (value == currentView)
|
||||
|
||||
if (value == _view)
|
||||
return;
|
||||
currentView = value;
|
||||
if (currentView is ViewHandler vh)
|
||||
{
|
||||
|
||||
_view = value;
|
||||
_handler = _view.ToIUIView();
|
||||
if (_handler is ViewHandler vh)
|
||||
vh.ViewChanged = SetView;
|
||||
}
|
||||
|
||||
SetView();
|
||||
}
|
||||
|
@ -33,9 +34,10 @@ namespace HotUI.iOS
|
|||
|
||||
void SetView()
|
||||
{
|
||||
if (this.ViewIfLoaded == null || CurrentView == null)
|
||||
if (ViewIfLoaded == null || CurrentView == null)
|
||||
return;
|
||||
var view = CurrentView?.View;
|
||||
|
||||
var view = _handler?.View;
|
||||
if (view == currentlyShownView)
|
||||
return;
|
||||
currentlyShownView?.RemoveFromSuperview();
|
||||
|
@ -70,6 +72,15 @@ namespace HotUI.iOS
|
|||
bounds.Y += safe.Top;
|
||||
bounds.Height -= safe.Top + safe.Bottom;
|
||||
bounds.Width -= safe.Left + safe.Right;
|
||||
|
||||
var padding = _view.GetPadding();
|
||||
if (!padding.IsEmpty)
|
||||
{
|
||||
bounds.X += padding.Left;
|
||||
bounds.Y += padding.Top;
|
||||
bounds.Width -= padding.HorizontalThickness;
|
||||
bounds.Height -= padding.VerticalThickness;
|
||||
}
|
||||
|
||||
if (currentlyShownView is UITableView lv)
|
||||
currentlyShownView.Frame = bounds;
|
||||
|
|
|
@ -26,6 +26,8 @@ namespace HotUI.iOS {
|
|||
Registrar.Handlers.Register<ListView, ListViewHandler> ();
|
||||
Registrar.Handlers.Register<View, ViewHandler> ();
|
||||
Registrar.Handlers.Register<ContentView, ContentViewHandler> ();
|
||||
Registrar.Handlers.Register<Spacer, SpacerHandler> ();
|
||||
|
||||
ModalView.PerformPresent = (o) => {
|
||||
PresentingViewController.PresentViewController (o.ToViewController(), true,null);
|
||||
};
|
||||
|
|
|
@ -28,6 +28,11 @@ namespace HotUI
|
|||
return view;
|
||||
}
|
||||
|
||||
public static Thickness GetPadding (this View view)
|
||||
{
|
||||
return view.GetPadding(Thickness.Empty);
|
||||
}
|
||||
|
||||
public static Thickness GetPadding (this View view, Thickness defaultPadding)
|
||||
{
|
||||
var padding = view.GetEnvironment<Thickness?> (EnvironmentKeys.Layout.Padding);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace HotUI.Layout
|
||||
{
|
||||
|
@ -9,19 +11,61 @@ namespace HotUI.Layout
|
|||
T parentView,
|
||||
AbstractLayout layout)
|
||||
{
|
||||
var x = 0f;
|
||||
var y = 0f;
|
||||
var height = 0f;
|
||||
|
||||
var index = 0;
|
||||
var nonSpacerWidth = 0f;
|
||||
var spacerCount = 0;
|
||||
List<SizeF> sizes = new List<SizeF>();
|
||||
|
||||
foreach (var subview in handler.GetSubviews())
|
||||
{
|
||||
var size = handler.GetSize(subview);
|
||||
var view = layout[index];
|
||||
if (view is Spacer)
|
||||
{
|
||||
spacerCount++;
|
||||
sizes.Add(new SizeF());
|
||||
}
|
||||
else
|
||||
{
|
||||
var size = handler.GetSize(subview);
|
||||
sizes.Add(size);
|
||||
height = Math.Max(size.Height, height);
|
||||
nonSpacerWidth += size.Width;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
var spacerWidth = 0f;
|
||||
if (spacerCount>0)
|
||||
{
|
||||
var parentSize = handler.GetAvailableSize();
|
||||
var availableWidth = parentSize.Width - nonSpacerWidth;
|
||||
spacerWidth = availableWidth / spacerCount;
|
||||
}
|
||||
|
||||
var x = 0f;
|
||||
var y = 0f;
|
||||
index = 0;
|
||||
foreach (var subview in handler.GetSubviews())
|
||||
{
|
||||
var view = layout[index];
|
||||
SizeF size;
|
||||
if (view is Spacer)
|
||||
{
|
||||
size = new SizeF(spacerWidth, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
size = sizes[index];
|
||||
index++;
|
||||
}
|
||||
|
||||
handler.SetFrame(subview,x,y,size.Width, size.Height);
|
||||
x += size.Width;
|
||||
|
||||
height = Math.Max(size.Height, height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
handler.SetSize(parentView, x, height);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ using System.Drawing;
|
|||
namespace HotUI.Layout
|
||||
{
|
||||
public interface ILayoutHandler<T>
|
||||
{
|
||||
{
|
||||
SizeF GetAvailableSize();
|
||||
SizeF GetSize(T view);
|
||||
void SetSize(T view, float width, float height);
|
||||
void SetFrame(T view, float x, float y, float width, float height);
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace HotUI.Layout
|
|||
var x = 0f;
|
||||
var y = 0f;
|
||||
var width = 0f;
|
||||
|
||||
|
||||
foreach (var subview in handler.GetSubviews())
|
||||
{
|
||||
var size = handler.GetSize(subview);
|
||||
|
|
|
@ -5,6 +5,8 @@ namespace HotUI
|
|||
[DebuggerDisplay("Left={Left}, Top={Top}, Right={Right}, Bottom={Bottom}, HorizontalThickness={HorizontalThickness}, VerticalThickness={VerticalThickness}")]
|
||||
public struct Thickness
|
||||
{
|
||||
public static readonly Thickness Empty = new Thickness(0);
|
||||
|
||||
public float Left { get; set; }
|
||||
|
||||
public float Top { get; set; }
|
||||
|
@ -17,7 +19,7 @@ namespace HotUI
|
|||
|
||||
public float VerticalThickness => Top + Bottom;
|
||||
|
||||
internal bool IsEmpty => Left == 0 && Top == 0 && Right == 0 && Bottom == 0;
|
||||
public bool IsEmpty => Left == 0 && Top == 0 && Right == 0 && Bottom == 0;
|
||||
|
||||
public Thickness(float uniformSize) : this(uniformSize, uniformSize, uniformSize, uniformSize)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче