From a887133288ecdce1a347b6947a6aa94fd101dd5b Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Thu, 9 Nov 2017 13:03:56 -0800 Subject: [PATCH] Use spaces to match Ooui --- Ooui.Forms/Exports.cs | 16 +- Ooui.Forms/Forms.cs | 146 +++++------ Ooui.Forms/Ooui.Forms.csproj | 7 + Ooui.Forms/PageExtensions.cs | 54 ++-- Ooui.Forms/Platform.cs | 286 ++++++++++---------- Ooui.Forms/Renderers/ButtonRenderer.cs | 12 +- Ooui.Forms/Renderers/DefaultRenderer.cs | 12 +- Ooui.Forms/Renderers/ViewRenderer.cs | 2 +- Ooui.Forms/ResourcesProvider.cs | 3 +- Ooui.Forms/VisualElementRenderer.cs | 220 ++++++++-------- Ooui.Forms/VisualElementTracker.cs | 329 ++++++++++++------------ Ooui.sln | 1 + Ooui/Element.cs | 6 - Ooui/Style.cs | 18 +- 14 files changed, 560 insertions(+), 552 deletions(-) diff --git a/Ooui.Forms/Exports.cs b/Ooui.Forms/Exports.cs index 566bd81..128ce70 100644 --- a/Ooui.Forms/Exports.cs +++ b/Ooui.Forms/Exports.cs @@ -9,12 +9,12 @@ using Xamarin.Forms.Internals; namespace Ooui.Forms { - [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class ExportRendererAttribute : HandlerAttribute - { - public ExportRendererAttribute (Type handler, Type target) - : base (handler, target) - { - } - } + [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class ExportRendererAttribute : HandlerAttribute + { + public ExportRendererAttribute (Type handler, Type target) + : base (handler, target) + { + } + } } diff --git a/Ooui.Forms/Forms.cs b/Ooui.Forms/Forms.cs index 786cb33..cf3feb8 100644 --- a/Ooui.Forms/Forms.cs +++ b/Ooui.Forms/Forms.cs @@ -11,101 +11,101 @@ using Ooui; namespace Xamarin.Forms { - public static class Forms - { - public static bool IsInitialized { get; private set; } + public static class Forms + { + public static bool IsInitialized { get; private set; } - public static void Init () - { - if (IsInitialized) - return; - IsInitialized = true; + public static void Init () + { + if (IsInitialized) + return; + IsInitialized = true; - Log.Listeners.Add (new DelegateLogListener ((c, m) => Trace.WriteLine (m, c))); + Log.Listeners.Add (new DelegateLogListener ((c, m) => Trace.WriteLine (m, c))); - Device.SetIdiom (TargetIdiom.Desktop); - Device.PlatformServices = new OouiPlatformServices (); - Device.Info = new OouiDeviceInfo (); + Device.SetIdiom (TargetIdiom.Desktop); + Device.PlatformServices = new OouiPlatformServices (); + Device.Info = new OouiDeviceInfo (); - Registrar.RegisterAll (new[] { - typeof(ExportRendererAttribute), + Registrar.RegisterAll (new[] { + typeof(ExportRendererAttribute), //typeof(ExportCellAttribute), //typeof(ExportImageSourceHandlerAttribute), }); - } + } - public static event EventHandler ViewInitialized; + public static event EventHandler ViewInitialized; - public static void SendViewInitialized (this VisualElement self, Ooui.Element nativeView) - { - ViewInitialized?.Invoke (self, new ViewInitializedEventArgs { View = self, NativeView = nativeView }); - } + public static void SendViewInitialized (this VisualElement self, Ooui.Element nativeView) + { + ViewInitialized?.Invoke (self, new ViewInitializedEventArgs { View = self, NativeView = nativeView }); + } - class OouiDeviceInfo : DeviceInfo - { - public override Size PixelScreenSize => new Size (640, 480); + class OouiDeviceInfo : DeviceInfo + { + public override Size PixelScreenSize => new Size (640, 480); - public override Size ScaledScreenSize => PixelScreenSize; + public override Size ScaledScreenSize => PixelScreenSize; - public override double ScalingFactor => 1; - } + public override double ScalingFactor => 1; + } - class OouiPlatformServices : IPlatformServices - { - public bool IsInvokeRequired => false; + class OouiPlatformServices : IPlatformServices + { + public bool IsInvokeRequired => false; - public string RuntimePlatform => "Ooui"; + public string RuntimePlatform => "Ooui"; - public void BeginInvokeOnMainThread (Action action) - { - Task.Run (action); - } + public void BeginInvokeOnMainThread (Action action) + { + Task.Run (action); + } - public Ticker CreateTicker () - { - throw new NotImplementedException (); - } + public Ticker CreateTicker () + { + throw new NotImplementedException (); + } - public Assembly[] GetAssemblies () - { - return AppDomain.CurrentDomain.GetAssemblies (); - } + public Assembly[] GetAssemblies () + { + return AppDomain.CurrentDomain.GetAssemblies (); + } - public string GetMD5Hash (string input) - { - throw new NotImplementedException (); - } + public string GetMD5Hash (string input) + { + throw new NotImplementedException (); + } - public double GetNamedSize (NamedSize size, Type targetElementType, bool useOldSizes) - { - throw new NotImplementedException (); - } + public double GetNamedSize (NamedSize size, Type targetElementType, bool useOldSizes) + { + throw new NotImplementedException (); + } - public Task GetStreamAsync (Uri uri, CancellationToken cancellationToken) - { - throw new NotImplementedException (); - } + public Task GetStreamAsync (Uri uri, CancellationToken cancellationToken) + { + throw new NotImplementedException (); + } - public IIsolatedStorageFile GetUserStoreForApplication () - { - throw new NotImplementedException (); - } + public IIsolatedStorageFile GetUserStoreForApplication () + { + throw new NotImplementedException (); + } - public void OpenUriAction (Uri uri) - { - throw new NotImplementedException (); - } + public void OpenUriAction (Uri uri) + { + throw new NotImplementedException (); + } - public void StartTimer (TimeSpan interval, Func callback) - { - throw new NotImplementedException (); - } - } + public void StartTimer (TimeSpan interval, Func callback) + { + throw new NotImplementedException (); + } + } - public class ViewInitializedEventArgs - { - public VisualElement View { get; set; } - public Ooui.Element NativeView { get; set; } - } - } + public class ViewInitializedEventArgs + { + public VisualElement View { get; set; } + public Ooui.Element NativeView { get; set; } + } + } } diff --git a/Ooui.Forms/Ooui.Forms.csproj b/Ooui.Forms/Ooui.Forms.csproj index 6a5c90e..5c0c488 100644 --- a/Ooui.Forms/Ooui.Forms.csproj +++ b/Ooui.Forms/Ooui.Forms.csproj @@ -4,6 +4,13 @@ netstandard2.0 + + true + + + + true + diff --git a/Ooui.Forms/PageExtensions.cs b/Ooui.Forms/PageExtensions.cs index 8380447..8f60bd1 100644 --- a/Ooui.Forms/PageExtensions.cs +++ b/Ooui.Forms/PageExtensions.cs @@ -3,36 +3,36 @@ using Xamarin.Forms; namespace Xamarin.Forms { - public static class PageExtensions - { - public static void Publish (this Xamarin.Forms.Page page, string path) - { - Ooui.UI.Publish (path, () => page.CreateElement ()); - } + public static class PageExtensions + { + public static void Publish (this Xamarin.Forms.Page page, string path) + { + Ooui.UI.Publish (path, () => page.CreateElement ()); + } - public static void PublishShared (this Xamarin.Forms.Page page, string path) - { - var lazyPage = new Lazy ((() => page.CreateElement ()), true); - Ooui.UI.Publish (path, () => lazyPage.Value); - } + public static void PublishShared (this Xamarin.Forms.Page page, string path) + { + var lazyPage = new Lazy ((() => page.CreateElement ()), true); + Ooui.UI.Publish (path, () => lazyPage.Value); + } - public static Ooui.Element CreateElement (this Xamarin.Forms.Page page) - { - if (!Xamarin.Forms.Forms.IsInitialized) - throw new InvalidOperationException ("call Forms.Init() before this"); + public static Ooui.Element CreateElement (this Xamarin.Forms.Page page) + { + if (!Xamarin.Forms.Forms.IsInitialized) + throw new InvalidOperationException ("call Forms.Init() before this"); - if (!(page.RealParent is Application)) { - var app = new DefaultApplication (); - app.MainPage = page; - } + if (!(page.RealParent is Application)) { + var app = new DefaultApplication (); + app.MainPage = page; + } - var result = new Ooui.Forms.Platform (); - result.SetPage (page); - return result.Element; - } + var result = new Ooui.Forms.Platform (); + result.SetPage (page); + return result.Element; + } - class DefaultApplication : Application - { - } - } + class DefaultApplication : Application + { + } + } } diff --git a/Ooui.Forms/Platform.cs b/Ooui.Forms/Platform.cs index 1e1418f..f4235f9 100644 --- a/Ooui.Forms/Platform.cs +++ b/Ooui.Forms/Platform.cs @@ -7,167 +7,167 @@ using Xamarin.Forms.Internals; namespace Ooui.Forms { - public class Platform : BindableObject, IPlatform, INavigation, IDisposable - { - bool _disposed; + public class Platform : BindableObject, IPlatform, INavigation, IDisposable + { + bool _disposed; - readonly PlatformRenderer _renderer; - - public Ooui.Element Element => _renderer; - - public Page Page { get; private set; } + readonly PlatformRenderer _renderer; - IReadOnlyList INavigation.ModalStack => throw new NotImplementedException (); + public Ooui.Element Element => _renderer; - IReadOnlyList INavigation.NavigationStack => throw new NotImplementedException (); - - public static readonly BindableProperty RendererProperty = BindableProperty.CreateAttached ("Renderer", typeof (IVisualElementRenderer), typeof (Platform), default (IVisualElementRenderer), - propertyChanged: (bindable, oldvalue, newvalue) => { - var view = bindable as VisualElement; - if (view != null) - view.IsPlatformEnabled = newvalue != null; - }); - - public Platform () - { - _renderer = new PlatformRenderer (this); - } + public Page Page { get; private set; } - void IDisposable.Dispose() - { - if (_disposed) - return; - _disposed = true; - - MessagingCenter.Unsubscribe(this, Page.ActionSheetSignalName); - MessagingCenter.Unsubscribe(this, Page.AlertSignalName); - MessagingCenter.Unsubscribe(this, Page.BusySetSignalName); - } - - public static IVisualElementRenderer CreateRenderer (VisualElement element) - { - var renderer = Registrar.Registered.GetHandler (element.GetType ()) ?? new DefaultRenderer (); - renderer.SetElement (element); - return renderer; - } - - public static IVisualElementRenderer GetRenderer (VisualElement bindable) - { - return (IVisualElementRenderer)bindable.GetValue (RendererProperty); - } - - public static void SetRenderer (VisualElement bindable, IVisualElementRenderer value) - { - bindable.SetValue (RendererProperty, value); - } - - protected override void OnBindingContextChanged () - { - SetInheritedBindingContext (Page, BindingContext); - - base.OnBindingContextChanged (); - } + IReadOnlyList INavigation.ModalStack => throw new NotImplementedException (); - public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint) - { - return new SizeRequest(new Size(100, 100)); - } + IReadOnlyList INavigation.NavigationStack => throw new NotImplementedException (); - public void SetPage (Page newRoot) - { - if (newRoot == null) - return; - if (Page != null) - throw new NotImplementedException (); - Page = newRoot; - - Page.Platform = this; - AddChild (Page); - - Page.DescendantRemoved += HandleChildRemoved; - - Application.Current.NavigationProxy.Inner = this; - } + public static readonly BindableProperty RendererProperty = BindableProperty.CreateAttached ("Renderer", typeof (IVisualElementRenderer), typeof (Platform), default (IVisualElementRenderer), + propertyChanged: (bindable, oldvalue, newvalue) => { + var view = bindable as VisualElement; + if (view != null) + view.IsPlatformEnabled = newvalue != null; + }); - void HandleChildRemoved (object sender, ElementEventArgs e) - { - throw new NotImplementedException (); - } + public Platform () + { + _renderer = new PlatformRenderer (this); + } - void AddChild (VisualElement view) - { - if (!Application.IsApplicationOrNull (view.RealParent)) - Console.Error.WriteLine ("Tried to add parented view to canvas directly"); - - if (GetRenderer (view) == null) { - var viewRenderer = CreateRenderer (view); - SetRenderer (view, viewRenderer); - - _renderer.AppendChild (viewRenderer.NativeView); - viewRenderer.SetElementSize (new Size (640, 480)); - } - else - Console.Error.WriteLine ("Potential view double add"); - } + void IDisposable.Dispose () + { + if (_disposed) + return; + _disposed = true; - void INavigation.InsertPageBefore (Page page, Page before) - { - throw new NotImplementedException (); - } + MessagingCenter.Unsubscribe (this, Page.ActionSheetSignalName); + MessagingCenter.Unsubscribe (this, Page.AlertSignalName); + MessagingCenter.Unsubscribe (this, Page.BusySetSignalName); + } - Task INavigation.PopAsync () - { - throw new NotImplementedException (); - } + public static IVisualElementRenderer CreateRenderer (VisualElement element) + { + var renderer = Registrar.Registered.GetHandler (element.GetType ()) ?? new DefaultRenderer (); + renderer.SetElement (element); + return renderer; + } - Task INavigation.PopAsync (bool animated) - { - throw new NotImplementedException (); - } + public static IVisualElementRenderer GetRenderer (VisualElement bindable) + { + return (IVisualElementRenderer)bindable.GetValue (RendererProperty); + } - Task INavigation.PopModalAsync () - { - throw new NotImplementedException (); - } + public static void SetRenderer (VisualElement bindable, IVisualElementRenderer value) + { + bindable.SetValue (RendererProperty, value); + } - Task INavigation.PopModalAsync (bool animated) - { - throw new NotImplementedException (); - } + protected override void OnBindingContextChanged () + { + SetInheritedBindingContext (Page, BindingContext); - Task INavigation.PopToRootAsync () - { - throw new NotImplementedException (); - } + base.OnBindingContextChanged (); + } - Task INavigation.PopToRootAsync (bool animated) - { - throw new NotImplementedException (); - } + public SizeRequest GetNativeSize (VisualElement view, double widthConstraint, double heightConstraint) + { + return new SizeRequest (new Size (100, 100)); + } - Task INavigation.PushAsync (Page page) - { - throw new NotImplementedException (); - } + public void SetPage (Page newRoot) + { + if (newRoot == null) + return; + if (Page != null) + throw new NotImplementedException (); + Page = newRoot; - Task INavigation.PushAsync (Page page, bool animated) - { - throw new NotImplementedException (); - } + Page.Platform = this; + AddChild (Page); - Task INavigation.PushModalAsync (Page page) - { - throw new NotImplementedException (); - } + Page.DescendantRemoved += HandleChildRemoved; - Task INavigation.PushModalAsync (Page page, bool animated) - { - throw new NotImplementedException (); - } + Application.Current.NavigationProxy.Inner = this; + } - void INavigation.RemovePage (Page page) - { - throw new NotImplementedException (); - } - } + void HandleChildRemoved (object sender, ElementEventArgs e) + { + throw new NotImplementedException (); + } + + void AddChild (VisualElement view) + { + if (!Application.IsApplicationOrNull (view.RealParent)) + Console.Error.WriteLine ("Tried to add parented view to canvas directly"); + + if (GetRenderer (view) == null) { + var viewRenderer = CreateRenderer (view); + SetRenderer (view, viewRenderer); + + _renderer.AppendChild (viewRenderer.NativeView); + viewRenderer.SetElementSize (new Size (640, 480)); + } + else + Console.Error.WriteLine ("Potential view double add"); + } + + void INavigation.InsertPageBefore (Page page, Page before) + { + throw new NotImplementedException (); + } + + Task INavigation.PopAsync () + { + throw new NotImplementedException (); + } + + Task INavigation.PopAsync (bool animated) + { + throw new NotImplementedException (); + } + + Task INavigation.PopModalAsync () + { + throw new NotImplementedException (); + } + + Task INavigation.PopModalAsync (bool animated) + { + throw new NotImplementedException (); + } + + Task INavigation.PopToRootAsync () + { + throw new NotImplementedException (); + } + + Task INavigation.PopToRootAsync (bool animated) + { + throw new NotImplementedException (); + } + + Task INavigation.PushAsync (Page page) + { + throw new NotImplementedException (); + } + + Task INavigation.PushAsync (Page page, bool animated) + { + throw new NotImplementedException (); + } + + Task INavigation.PushModalAsync (Page page) + { + throw new NotImplementedException (); + } + + Task INavigation.PushModalAsync (Page page, bool animated) + { + throw new NotImplementedException (); + } + + void INavigation.RemovePage (Page page) + { + throw new NotImplementedException (); + } + } } diff --git a/Ooui.Forms/Renderers/ButtonRenderer.cs b/Ooui.Forms/Renderers/ButtonRenderer.cs index 542caf9..3ccfd95 100644 --- a/Ooui.Forms/Renderers/ButtonRenderer.cs +++ b/Ooui.Forms/Renderers/ButtonRenderer.cs @@ -3,10 +3,10 @@ using Xamarin.Forms; namespace Ooui.Forms.Renderers { - public class ButtonRenderer : ViewRenderer - { - public ButtonRenderer() - { - } - } + public class ButtonRenderer : ViewRenderer + { + public ButtonRenderer () + { + } + } } diff --git a/Ooui.Forms/Renderers/DefaultRenderer.cs b/Ooui.Forms/Renderers/DefaultRenderer.cs index 5e987d7..970ec87 100644 --- a/Ooui.Forms/Renderers/DefaultRenderer.cs +++ b/Ooui.Forms/Renderers/DefaultRenderer.cs @@ -3,10 +3,10 @@ using Xamarin.Forms; namespace Ooui.Forms.Renderers { - public class DefaultRenderer : VisualElementRenderer - { - public DefaultRenderer () - { - } - } + public class DefaultRenderer : VisualElementRenderer + { + public DefaultRenderer () + { + } + } } diff --git a/Ooui.Forms/Renderers/ViewRenderer.cs b/Ooui.Forms/Renderers/ViewRenderer.cs index 5009a94..1c2c7c6 100644 --- a/Ooui.Forms/Renderers/ViewRenderer.cs +++ b/Ooui.Forms/Renderers/ViewRenderer.cs @@ -103,7 +103,7 @@ namespace Ooui.Forms.Renderers if (Element == null || Control == null) return; - var uiControl = Control as Ooui.Element; + var uiControl = Control as Ooui.FormControl; if (uiControl == null) return; uiControl.IsDisabled = !Element.IsEnabled; diff --git a/Ooui.Forms/ResourcesProvider.cs b/Ooui.Forms/ResourcesProvider.cs index 824406f..c0c05a3 100644 --- a/Ooui.Forms/ResourcesProvider.cs +++ b/Ooui.Forms/ResourcesProvider.cs @@ -19,8 +19,9 @@ namespace Ooui.Forms { readonly ConcurrentDictionary values = new ConcurrentDictionary (); - +#pragma warning disable 67 public event EventHandler ValuesChanged; +#pragma warning restore 67 public bool TryGetValue (string key, out object value) { diff --git a/Ooui.Forms/VisualElementRenderer.cs b/Ooui.Forms/VisualElementRenderer.cs index 52a5d3d..88b7428 100644 --- a/Ooui.Forms/VisualElementRenderer.cs +++ b/Ooui.Forms/VisualElementRenderer.cs @@ -6,145 +6,145 @@ using Xamarin.Forms; namespace Ooui.Forms { - public class VisualElementRenderer : Ooui.Element, IVisualElementRenderer where TElement : VisualElement - { - bool disposedValue = false; // To detect redundant calls - VisualElementTracker _tracker; + public class VisualElementRenderer : Ooui.Element, IVisualElementRenderer where TElement : VisualElement + { + bool disposedValue = false; // To detect redundant calls + VisualElementTracker _tracker; - readonly Color _defaultColor = Color.Clear; + readonly Color _defaultColor = Color.Clear; - readonly PropertyChangedEventHandler _propertyChangedHandler; + readonly PropertyChangedEventHandler _propertyChangedHandler; - public TElement Element { get; private set; } + public TElement Element { get; private set; } - VisualElement IVisualElementRenderer.Element => Element; + VisualElement IVisualElementRenderer.Element => Element; - public Element NativeView => this; + public Element NativeView => this; - event EventHandler IVisualElementRenderer.ElementChanged { - add { _elementChangedHandlers.Add (value); } - remove { _elementChangedHandlers.Remove (value); } - } + event EventHandler IVisualElementRenderer.ElementChanged { + add { _elementChangedHandlers.Add (value); } + remove { _elementChangedHandlers.Remove (value); } + } - readonly List> _elementChangedHandlers = - new List> (); + readonly List> _elementChangedHandlers = + new List> (); - public VisualElementRenderer () : base ("div") - { - _propertyChangedHandler = OnElementPropertyChanged; - } + public VisualElementRenderer () : base ("div") + { + _propertyChangedHandler = OnElementPropertyChanged; + } - protected virtual void OnElementChanged (ElementChangedEventArgs e) - { - var args = new VisualElementChangedEventArgs (e.OldElement, e.NewElement); - for (int i = 0; i < _elementChangedHandlers.Count; i++) { - _elementChangedHandlers[i] (this, args); - } + protected virtual void OnElementChanged (ElementChangedEventArgs e) + { + var args = new VisualElementChangedEventArgs (e.OldElement, e.NewElement); + for (int i = 0; i < _elementChangedHandlers.Count; i++) { + _elementChangedHandlers[i] (this, args); + } - var changed = ElementChanged; - if (changed != null) - changed (this, e); - } + var changed = ElementChanged; + if (changed != null) + changed (this, e); + } - public event EventHandler> ElementChanged; + public event EventHandler> ElementChanged; - void IVisualElementRenderer.SetElement (VisualElement element) - { - SetElement ((TElement)element); - } + void IVisualElementRenderer.SetElement (VisualElement element) + { + SetElement ((TElement)element); + } - public void SetElement (TElement element) - { - var oldElement = Element; - Element = element; + public void SetElement (TElement element) + { + var oldElement = Element; + Element = element; - if (oldElement != null) - oldElement.PropertyChanged -= _propertyChangedHandler; + if (oldElement != null) + oldElement.PropertyChanged -= _propertyChangedHandler; - if (element != null) { - if (element.BackgroundColor != Xamarin.Forms.Color.Default || (oldElement != null && element.BackgroundColor != oldElement.BackgroundColor)) - SetBackgroundColor (element.BackgroundColor); + if (element != null) { + if (element.BackgroundColor != Xamarin.Forms.Color.Default || (oldElement != null && element.BackgroundColor != oldElement.BackgroundColor)) + SetBackgroundColor (element.BackgroundColor); - if (_tracker == null) { - _tracker = new VisualElementTracker (this); - _tracker.NativeControlUpdated += (sender, e) => UpdateNativeWidget (); - } + if (_tracker == null) { + _tracker = new VisualElementTracker (this); + _tracker.NativeControlUpdated += (sender, e) => UpdateNativeWidget (); + } - //if (AutoPackage && _packager == null) { - // _packager = new VisualElementPackager (this); - // _packager.Load (); - //} + //if (AutoPackage && _packager == null) { + // _packager = new VisualElementPackager (this); + // _packager.Load (); + //} - //if (AutoTrack && _events == null) { - // _events = new EventTracker (this); - // _events.LoadEvents (this); - //} + //if (AutoTrack && _events == null) { + // _events = new EventTracker (this); + // _events.LoadEvents (this); + //} - element.PropertyChanged += _propertyChangedHandler; - } + element.PropertyChanged += _propertyChangedHandler; + } - OnElementChanged (new ElementChangedEventArgs (oldElement, element)); + OnElementChanged (new ElementChangedEventArgs (oldElement, element)); - if (element != null) - SendVisualElementInitialized (element, this); + if (element != null) + SendVisualElementInitialized (element, this); - if (Element != null && !string.IsNullOrEmpty (Element.AutomationId)) - SetAutomationId (Element.AutomationId); - } + if (Element != null && !string.IsNullOrEmpty (Element.AutomationId)) + SetAutomationId (Element.AutomationId); + } - public void SetElementSize (Size size) - { - Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Element, new Rectangle (Element.X, Element.Y, size.Width, size.Height)); - } + public void SetElementSize (Size size) + { + Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Element, new Rectangle (Element.X, Element.Y, size.Width, size.Height)); + } - protected virtual void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e) - { - if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) { - SetBackgroundColor (Element.BackgroundColor); - } - else if (e.PropertyName == Layout.IsClippedToBoundsProperty.PropertyName) { - //UpdateClipToBounds (); - } - } + protected virtual void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) { + SetBackgroundColor (Element.BackgroundColor); + } + else if (e.PropertyName == Layout.IsClippedToBoundsProperty.PropertyName) { + //UpdateClipToBounds (); + } + } - protected virtual void OnRegisterEffect (PlatformEffect effect) - { - //effect.Container = this; - } + protected virtual void OnRegisterEffect (PlatformEffect effect) + { + //effect.Container = this; + } - protected virtual void SetAutomationId (string id) - { - } + protected virtual void SetAutomationId (string id) + { + } - protected virtual void SetBackgroundColor (Xamarin.Forms.Color color) - { - if (color == Xamarin.Forms.Color.Default) - Style.BackgroundColor = _defaultColor; - else - Style.BackgroundColor = color.ToOouiColor (); - } + protected virtual void SetBackgroundColor (Xamarin.Forms.Color color) + { + if (color == Xamarin.Forms.Color.Default) + Style.BackgroundColor = _defaultColor; + else + Style.BackgroundColor = color.ToOouiColor (); + } - protected virtual void UpdateNativeWidget () - { - } + protected virtual void UpdateNativeWidget () + { + } - protected virtual void SendVisualElementInitialized (VisualElement element, Element nativeView) - { - element.SendViewInitialized (nativeView); - } + protected virtual void SendVisualElementInitialized (VisualElement element, Element nativeView) + { + element.SendViewInitialized (nativeView); + } - protected virtual void Dispose (bool disposing) - { - if (!disposedValue) { - if (disposing) { - } - disposedValue = true; - } - } + protected virtual void Dispose (bool disposing) + { + if (!disposedValue) { + if (disposing) { + } + disposedValue = true; + } + } - public void Dispose () - { - Dispose (true); - } - } + public void Dispose () + { + Dispose (true); + } + } } diff --git a/Ooui.Forms/VisualElementTracker.cs b/Ooui.Forms/VisualElementTracker.cs index a8f2f8d..c92f360 100644 --- a/Ooui.Forms/VisualElementTracker.cs +++ b/Ooui.Forms/VisualElementTracker.cs @@ -6,213 +6,214 @@ using Xamarin.Forms.Internals; namespace Ooui.Forms { - public class VisualElementTracker - { - readonly EventHandler> _batchCommittedHandler; + public class VisualElementTracker + { + readonly EventHandler> _batchCommittedHandler; - readonly PropertyChangedEventHandler _propertyChangedHandler; - readonly EventHandler _sizeChangedEventHandler; - bool _disposed; - VisualElement _element; + readonly PropertyChangedEventHandler _propertyChangedHandler; + readonly EventHandler _sizeChangedEventHandler; + bool _disposed; + VisualElement _element; - // Track these by hand because the calls down into iOS are too expensive - bool _isInteractive; - Rectangle _lastBounds; + // Track these by hand because the calls down into iOS are too expensive + bool _isInteractive; + Rectangle _lastBounds; #if !__MOBILE__ - Rectangle _lastParentBounds; + Rectangle _lastParentBounds; #endif - int _updateCount; + int _updateCount; - public VisualElementTracker (IVisualElementRenderer renderer) - { - if (renderer == null) - throw new ArgumentNullException (nameof (renderer)); + public VisualElementTracker (IVisualElementRenderer renderer) + { + if (renderer == null) + throw new ArgumentNullException (nameof (renderer)); - _propertyChangedHandler = HandlePropertyChanged; - _sizeChangedEventHandler = HandleSizeChanged; - _batchCommittedHandler = HandleRedrawNeeded; + _propertyChangedHandler = HandlePropertyChanged; + _sizeChangedEventHandler = HandleSizeChanged; + _batchCommittedHandler = HandleRedrawNeeded; - Renderer = renderer; - renderer.ElementChanged += OnRendererElementChanged; - SetElement (null, renderer.Element); - } + Renderer = renderer; + renderer.ElementChanged += OnRendererElementChanged; + SetElement (null, renderer.Element); + } - IVisualElementRenderer Renderer { get; set; } + IVisualElementRenderer Renderer { get; set; } - public void Dispose () - { - Dispose (true); - } + public void Dispose () + { + Dispose (true); + } - public event EventHandler NativeControlUpdated; + public event EventHandler NativeControlUpdated; - protected virtual void Dispose (bool disposing) - { - if (_disposed) - return; + protected virtual void Dispose (bool disposing) + { + if (_disposed) + return; - _disposed = true; + _disposed = true; - if (disposing) { - SetElement (_element, null); + if (disposing) { + SetElement (_element, null); - Renderer.ElementChanged -= OnRendererElementChanged; - Renderer = null; - } - } + Renderer.ElementChanged -= OnRendererElementChanged; + Renderer = null; + } + } - void HandlePropertyChanged (object sender, PropertyChangedEventArgs e) - { - if (e.PropertyName == VisualElement.XProperty.PropertyName || e.PropertyName == VisualElement.YProperty.PropertyName || e.PropertyName == VisualElement.WidthProperty.PropertyName || - e.PropertyName == VisualElement.HeightProperty.PropertyName || e.PropertyName == VisualElement.AnchorXProperty.PropertyName || e.PropertyName == VisualElement.AnchorYProperty.PropertyName || - e.PropertyName == VisualElement.TranslationXProperty.PropertyName || e.PropertyName == VisualElement.TranslationYProperty.PropertyName || e.PropertyName == VisualElement.ScaleProperty.PropertyName || - e.PropertyName == VisualElement.RotationProperty.PropertyName || e.PropertyName == VisualElement.RotationXProperty.PropertyName || e.PropertyName == VisualElement.RotationYProperty.PropertyName || - e.PropertyName == VisualElement.IsVisibleProperty.PropertyName || e.PropertyName == VisualElement.IsEnabledProperty.PropertyName || - e.PropertyName == VisualElement.InputTransparentProperty.PropertyName || e.PropertyName == VisualElement.OpacityProperty.PropertyName) - UpdateNativeControl (); // poorly optimized - } + void HandlePropertyChanged (object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == VisualElement.XProperty.PropertyName || e.PropertyName == VisualElement.YProperty.PropertyName || e.PropertyName == VisualElement.WidthProperty.PropertyName || + e.PropertyName == VisualElement.HeightProperty.PropertyName || e.PropertyName == VisualElement.AnchorXProperty.PropertyName || e.PropertyName == VisualElement.AnchorYProperty.PropertyName || + e.PropertyName == VisualElement.TranslationXProperty.PropertyName || e.PropertyName == VisualElement.TranslationYProperty.PropertyName || e.PropertyName == VisualElement.ScaleProperty.PropertyName || + e.PropertyName == VisualElement.RotationProperty.PropertyName || e.PropertyName == VisualElement.RotationXProperty.PropertyName || e.PropertyName == VisualElement.RotationYProperty.PropertyName || + e.PropertyName == VisualElement.IsVisibleProperty.PropertyName || e.PropertyName == VisualElement.IsEnabledProperty.PropertyName || + e.PropertyName == VisualElement.InputTransparentProperty.PropertyName || e.PropertyName == VisualElement.OpacityProperty.PropertyName) + UpdateNativeControl (); // poorly optimized + } - void HandleRedrawNeeded (object sender, EventArgs e) - { - UpdateNativeControl (); - } + void HandleRedrawNeeded (object sender, EventArgs e) + { + UpdateNativeControl (); + } - void HandleSizeChanged (object sender, EventArgs e) - { - UpdateNativeControl (); - } + void HandleSizeChanged (object sender, EventArgs e) + { + UpdateNativeControl (); + } - void OnRendererElementChanged (object s, VisualElementChangedEventArgs e) - { - if (_element == e.NewElement) - return; + void OnRendererElementChanged (object s, VisualElementChangedEventArgs e) + { + if (_element == e.NewElement) + return; - SetElement (_element, e.NewElement); - } + SetElement (_element, e.NewElement); + } - void OnUpdateNativeControl () - { - var view = Renderer.Element; - var uiview = Renderer.NativeView; + void OnUpdateNativeControl () + { + var view = Renderer.Element; + var uiview = Renderer.NativeView; - if (view == null || view.Batched) - return; + if (view == null || view.Batched) + return; - var shouldInteract = !view.InputTransparent && view.IsEnabled; - if (_isInteractive != shouldInteract) { - _isInteractive = shouldInteract; - } + var shouldInteract = !view.InputTransparent && view.IsEnabled; + if (_isInteractive != shouldInteract) { + _isInteractive = shouldInteract; + } - var boundsChanged = _lastBounds != view.Bounds; - var viewParent = view.RealParent as VisualElement; - var parentBoundsChanged = _lastParentBounds != (viewParent == null ? Rectangle.Zero : viewParent.Bounds); - var thread = !boundsChanged; + var boundsChanged = _lastBounds != view.Bounds; + var viewParent = view.RealParent as VisualElement; + var parentBoundsChanged = _lastParentBounds != (viewParent == null ? Rectangle.Zero : viewParent.Bounds); + var thread = !boundsChanged; - var anchorX = (float)view.AnchorX; - var anchorY = (float)view.AnchorY; - var translationX = (float)view.TranslationX; - var translationY = (float)view.TranslationY; - var rotationX = (float)view.RotationX; - var rotationY = (float)view.RotationY; - var rotation = (float)view.Rotation; - var scale = (float)view.Scale; - var width = (float)view.Width; - var height = (float)view.Height; - var x = (float)view.X; - var y = (float)view.Y; - var opacity = (float)view.Opacity; - var isVisible = view.IsVisible; + var anchorX = (float)view.AnchorX; + var anchorY = (float)view.AnchorY; + var translationX = (float)view.TranslationX; + var translationY = (float)view.TranslationY; + var rotationX = (float)view.RotationX; + var rotationY = (float)view.RotationY; + var rotation = (float)view.Rotation; + var scale = (float)view.Scale; + var width = (float)view.Width; + var height = (float)view.Height; + var x = (float)view.X; + var y = (float)view.Y; + var opacity = (float)view.Opacity; + var isVisible = view.IsVisible; - var updateTarget = Interlocked.Increment (ref _updateCount); + var updateTarget = Interlocked.Increment (ref _updateCount); - if (updateTarget != _updateCount) - return; - var parent = view.RealParent; + if (updateTarget != _updateCount) + return; + var parent = view.RealParent; - if (isVisible && uiview.IsHidden) { - uiview.IsHidden = false; - } + if (isVisible && uiview.IsHidden) { + uiview.IsHidden = false; + } - if (!isVisible && !uiview.IsHidden) { - uiview.IsHidden = true; - } + if (!isVisible && !uiview.IsHidden) { + uiview.IsHidden = true; + } - parentBoundsChanged = true; - bool shouldUpdate = width > 0 && height > 0 && parent != null && (boundsChanged || parentBoundsChanged); - if (shouldUpdate) { - var visualParent = parent as VisualElement; - float newY = visualParent == null ? y : Math.Max (0, (float)(visualParent.Height - y - view.Height)); - var target = new Rectangle (x, newY, width, height); + parentBoundsChanged = true; + bool shouldUpdate = width > 0 && height > 0 && parent != null && (boundsChanged || parentBoundsChanged); + if (shouldUpdate) { + var visualParent = parent as VisualElement; + float newY = visualParent == null ? y : Math.Max (0, (float)(visualParent.Height - y - view.Height)); + var target = new Rectangle (x, newY, width, height); - uiview.Style.Left = x; - uiview.Style.Top = newY; - uiview.Style.Width = width; - uiview.Style.Height = height; - } - else if (width <= 0 || height <= 0) { - return; - } - uiview.Style.Opacity = opacity; + uiview.Style.Position = "absolute"; + uiview.Style.Left = x; + uiview.Style.Top = newY; + uiview.Style.Right = x + width; + uiview.Style.Bottom = newY + height; + } + else if (width <= 0 || height <= 0) { + return; + } + uiview.Style.Opacity = opacity; - //var transform = 0; - //const double epsilon = 0.001; - //caLayer.AnchorPoint = new PointF (anchorX - 0.5f, anchorY - 0.5f); + //var transform = 0; + //const double epsilon = 0.001; + //caLayer.AnchorPoint = new PointF (anchorX - 0.5f, anchorY - 0.5f); - //// position is relative to anchor point - //if (Math.Abs (anchorX - .5) > epsilon) - // transform = transform.Translate ((anchorX - .5f) * width, 0, 0); - //if (Math.Abs (anchorY - .5) > epsilon) - // transform = transform.Translate (0, (anchorY - .5f) * height, 0); + //// position is relative to anchor point + //if (Math.Abs (anchorX - .5) > epsilon) + // transform = transform.Translate ((anchorX - .5f) * width, 0, 0); + //if (Math.Abs (anchorY - .5) > epsilon) + // transform = transform.Translate (0, (anchorY - .5f) * height, 0); - //if (Math.Abs (translationX) > epsilon || Math.Abs (translationY) > epsilon) - // transform = transform.Translate (translationX, translationY, 0); + //if (Math.Abs (translationX) > epsilon || Math.Abs (translationY) > epsilon) + // transform = transform.Translate (translationX, translationY, 0); - //if (Math.Abs (scale - 1) > epsilon) - // transform = transform.Scale (scale); + //if (Math.Abs (scale - 1) > epsilon) + // transform = transform.Scale (scale); - //// not just an optimization, iOS will not "pixel align" a view which has m34 set - //if (Math.Abs (rotationY % 180) > epsilon || Math.Abs (rotationX % 180) > epsilon) - // transform.m34 = 1.0f / -400f; + //// not just an optimization, iOS will not "pixel align" a view which has m34 set + //if (Math.Abs (rotationY % 180) > epsilon || Math.Abs (rotationX % 180) > epsilon) + // transform.m34 = 1.0f / -400f; - //if (Math.Abs (rotationX % 360) > epsilon) - // transform = transform.Rotate (rotationX * (float)Math.PI / 180.0f, 1.0f, 0.0f, 0.0f); - //if (Math.Abs (rotationY % 360) > epsilon) - // transform = transform.Rotate (rotationY * (float)Math.PI / 180.0f, 0.0f, 1.0f, 0.0f); + //if (Math.Abs (rotationX % 360) > epsilon) + // transform = transform.Rotate (rotationX * (float)Math.PI / 180.0f, 1.0f, 0.0f, 0.0f); + //if (Math.Abs (rotationY % 360) > epsilon) + // transform = transform.Rotate (rotationY * (float)Math.PI / 180.0f, 0.0f, 1.0f, 0.0f); - //transform = transform.Rotate (rotation * (float)Math.PI / 180.0f, 0.0f, 0.0f, 1.0f); - //caLayer.Transform = transform; + //transform = transform.Rotate (rotation * (float)Math.PI / 180.0f, 0.0f, 0.0f, 1.0f); + //caLayer.Transform = transform; - _lastBounds = view.Bounds; - _lastParentBounds = viewParent?.Bounds ?? Rectangle.Zero; - } + _lastBounds = view.Bounds; + _lastParentBounds = viewParent?.Bounds ?? Rectangle.Zero; + } - void SetElement (VisualElement oldElement, VisualElement newElement) - { - if (oldElement != null) { - oldElement.PropertyChanged -= _propertyChangedHandler; - oldElement.SizeChanged -= _sizeChangedEventHandler; - oldElement.BatchCommitted -= _batchCommittedHandler; - } + void SetElement (VisualElement oldElement, VisualElement newElement) + { + if (oldElement != null) { + oldElement.PropertyChanged -= _propertyChangedHandler; + oldElement.SizeChanged -= _sizeChangedEventHandler; + oldElement.BatchCommitted -= _batchCommittedHandler; + } - _element = newElement; + _element = newElement; - if (newElement != null) { - newElement.BatchCommitted += _batchCommittedHandler; - newElement.SizeChanged += _sizeChangedEventHandler; - newElement.PropertyChanged += _propertyChangedHandler; + if (newElement != null) { + newElement.BatchCommitted += _batchCommittedHandler; + newElement.SizeChanged += _sizeChangedEventHandler; + newElement.PropertyChanged += _propertyChangedHandler; - UpdateNativeControl (); - } - } + UpdateNativeControl (); + } + } - void UpdateNativeControl () - { - if (_disposed) - return; + void UpdateNativeControl () + { + if (_disposed) + return; - OnUpdateNativeControl (); + OnUpdateNativeControl (); - NativeControlUpdated?.Invoke (this, EventArgs.Empty); - } - } + NativeControlUpdated?.Invoke (this, EventArgs.Empty); + } + } } diff --git a/Ooui.sln b/Ooui.sln index ad4420b..f2975cd 100644 --- a/Ooui.sln +++ b/Ooui.sln @@ -79,6 +79,7 @@ Global $1.FileWidth = 128 $1.NoTabsAfterNonTabs = True $1.scope = text/x-csharp + $1.TabsToSpaces = True $0.CSharpFormattingPolicy = $2 $2.scope = text/x-csharp $2.NewLinesForBracesInProperties = False diff --git a/Ooui/Element.cs b/Ooui/Element.cs index c6c1d90..253f57d 100644 --- a/Ooui/Element.cs +++ b/Ooui/Element.cs @@ -25,12 +25,6 @@ namespace Ooui set => SetProperty (ref hidden, value, "hidden"); } - bool disabled = false; - public bool IsDisabled { - get => disabled; - set => SetProperty (ref disabled, value, "disabled"); - } - public event TargetEventHandler Clicked { add => AddEventListener ("click", value); remove => RemoveEventListener ("click", value); diff --git a/Ooui/Style.cs b/Ooui/Style.cs index 4be8590..f19abf7 100644 --- a/Ooui/Style.cs +++ b/Ooui/Style.cs @@ -11,7 +11,7 @@ namespace Ooui readonly Dictionary properties = new Dictionary (); - + public Value AlignSelf { get => this["align-self"]; set => this["align-self"] = value; @@ -232,10 +232,10 @@ namespace Ooui } } - public Value Opacity { - get => this["opacity"]; - set => this["opacity"] = value; - } + public Value Opacity { + get => this["opacity"]; + set => this["opacity"] = value; + } public Value Order { get => this["order"]; @@ -272,6 +272,11 @@ namespace Ooui } } + public Value Position { + get => this["position"]; + set => this["position"] = value; + } + public Value Right { get => this["right"]; set => this["right"] = value; @@ -307,8 +312,7 @@ namespace Ooui set => this["width"] = value; } - public Value this [string propertyName] - { + public Value this[string propertyName] { get { lock (properties) { Value p;