public static void BindShapeProperties(this IMountLocation self, object obj, Brush fill, Stroke stroke) { var control = obj as dynamic; control.Stroke = _reflection.Instantiate("Fuse.Drawing.Stroke") as dynamic; self.BindNativeProperty(fill, f => control.Color = new Float4(f.R, f.G, f.B, f.A)); self.BindNativeProperty(stroke.Brush.CombineLatest(stroke.DashArray), t => { var s = t.Item1; var dashArray = t.Item2; //Reflection.CallStatic("Fuse.Diagnostics","UserWarning", "Setting stroke of " + obj.GetHashCode() + " to " + s, obj, null, 0, null); if (dashArray == StrokeDashArray.Solid) { control.Stroke.Color = new Float4(s.R, s.G, s.B, s.A); } else { if (!_reflection.IsSubtype(control.Stroke.Brush, "DashedSolidColor")) control.Stroke.Brush = _reflection.Instantiate("DashedSolidColor", new Float4(s.R, s.G, s.B, s.A)) as dynamic; else control.Stroke.Brush.Color = new Float4(s.R, s.G, s.B, s.A); control.Stroke.Brush.DashSize = (float)dashArray.Data[0]; } }); self.BindNativeProperty(stroke.Thickness, s => control.Stroke.Width = (float)s); }
public static void BindShapeProperties(this IMountLocation self, System.Windows.Shapes.Shape control, Dispatcher dispatcher, Brush fill, Stroke stroke) { self.BindNativeProperty(dispatcher, "fill.Color", fill, f => control.Fill = new SolidColorBrush(f.ToColor())); self.BindNativeProperty(dispatcher, "stroke.Brush.Color", stroke.Brush, s => control.Stroke = new SolidColorBrush(s.ToColor())); self.BindNativeProperty(dispatcher, "stroke.Thickness", stroke.Thickness, s => control.StrokeThickness = s); self.BindNativeProperty(dispatcher, "stroke.DashArray", stroke.DashArray, s => control.StrokeDashArray = s.ToDashArray()); }
public static void BindShapeProperties(this IMountLocation self, NSShape control, IScheduler dispatcher, Brush fill, Stroke stroke) { self.BindNativeProperty(dispatcher, "fill.Color", fill, f => control.FillColor = f.ToNSColor()); self.BindNativeProperty(dispatcher, "stroke.Brush.Color", stroke.Brush, s => control.StrokeColor = s.ToNSColor()); self.BindNativeProperty(dispatcher, "stroke.Thickness", stroke.Thickness, s => control.LineThickness = (float)s); self.BindNativeProperty(dispatcher, "stroke.DashArray", stroke.DashArray, s => control.LineDash = s.ToLineDash()); }
/// <summary> /// Logs activity of observables contained in <paramref name="source"/> to stdout. /// </summary> /// <param name="source">The <see cref="Rectangle"/> to trace</param> /// <param name="name">Optional name prefix for observables, to make it easier to locate in trace</param> public static IMountLocation ConsoleTrace(this IMountLocation source, string name = "(anonymous mount location)") { return(new MountLocation.Mutable { IsRooted = source.IsRooted.ConsoleTrace(name + ".IsRooted"), AvailableSize = source.AvailableSize.ConsoleTrace(name + ".AvailableSize"), NativeFrame = source.NativeFrame.ConsoleTrace(name + ".NativeFrame") }); }
public static void BindNativeProperty <TValue>( this IMountLocation control, IScheduler dispatcher, string name, Optional <IObservable <TValue> > value, Action <TValue> update) { value.Do(v => BindNativeProperty(control.IsRooted, dispatcher, name, v, update)); }
public static void BindNativeProperty<TValue>( this IMountLocation control, IObservable<TValue> value, Action<TValue> update) { value .ConnectWhile(control.IsRooted) .DistinctUntilChanged() .Subscribe(update); }
public static void BindNativeProperty <TValue, TSome>( this IMountLocation fusionControl, NSControl nativeControl, Expression <Func <NSControl, TValue> > propertyExpression, IObservable <TSome> onChange, IProperty <TValue> sourceProperty) { var memberExpression = propertyExpression.Body as MemberExpression; PropertyInfo nativeProperty = null; if (memberExpression != null) { nativeProperty = memberExpression.Member as PropertyInfo; } if (nativeProperty == null) { throw new ArgumentException("Unable to extract property name from expression"); } sourceProperty = sourceProperty .ConnectWhile(fusionControl.IsRooted) .DistinctUntilChangedOrSet(); var propertyGetter = propertyExpression.Compile(); var setByUser = false; onChange .Select(_ => propertyGetter(nativeControl)) .Where(_ => setByUser) .Subscribe(sourceProperty); sourceProperty .Select( v => (Action)(() => { setByUser = false; try { nativeProperty.SetValue(nativeControl, v); } finally { setByUser = true; } })) .Subscribe(action => { Fusion.Application.MainThread.Schedule(action); }); }
public static void BindNativeDefaults(this IMountLocation self, object obj) { var element = obj as dynamic; var frame = self.NativeFrame; self.BindNativeProperty(frame.Left(), left => element.X = _reflection.CallStatic("Uno.UX.Size", "Points", (float)left) as dynamic); self.BindNativeProperty(frame.Top(), top => element.Y = _reflection.CallStatic("Uno.UX.Size", "Points", (float)top) as dynamic); self.BindNativeProperty(frame.Height, height => element.Height = _reflection.CallStatic("Uno.UX.Size", "Points", (float)height) as dynamic); self.BindNativeProperty(frame.Width, width => element.Width = _reflection.CallStatic("Uno.UX.Size", "Points", (float)width) as dynamic); }
public static void BindNativeDefaults(this IMountLocation self, NSView element, IScheduler dispatcher) { var frame = self.NativeFrame; self.BindNativeProperty(dispatcher, "position", frame.Position.Transpose(), position => { element.SetFrameOrigin(position.ToPoint()); element.NeedsDisplay = true; }); self.BindNativeProperty(dispatcher, "size", frame.Size.Transpose(), size => { element.SetFrameSize(size.Max(0, 0).ToSize()); element.NeedsDisplay = true; }); }
public static void BindNativeProperty <TWpfControl, TValue>( this IMountLocation fusionControl, TWpfControl wpfControl, Expression <Func <TWpfControl, TValue> > propertyExpression, IProperty <TValue> sourceProperty, string eventName = null) where TWpfControl : System.Windows.Controls.Control { var memberExpression = propertyExpression.Body as MemberExpression; PropertyInfo wpfProperty = null; if (memberExpression != null) { wpfProperty = memberExpression.Member as PropertyInfo; } if (wpfProperty == null) { throw new ArgumentException("Unable to extract property name from expression"); } if (wpfProperty.SetMethod == null || !wpfProperty.SetMethod.IsPublic) { throw new ArgumentException("Property does not have a public setter"); } sourceProperty = sourceProperty .ConnectWhile(fusionControl.IsRooted) .DistinctUntilChangedOrSet(); var propertyGetter = propertyExpression.Compile(); bool valueSetByUser = true; ObservableFromNativeEvent <EventArgs>(wpfControl, eventName ?? (wpfProperty.Name + "Changed")) .Select(_ => propertyGetter(wpfControl)) .Where(v => valueSetByUser) .Subscribe(sourceProperty); sourceProperty .Select(v => new Action(() => { valueSetByUser = false; try { wpfProperty.SetValue(wpfControl, v); } finally { valueSetByUser = true; } })) .Subscribe(action => Fusion.Application.MainThread.Schedule(action)); }
static FrameworkElement Rectangle( IMountLocation model, IObservable <ImageBrush> imgStream, Size <Pixels> totalSize, IObservable <Color> overlayColor, IScheduler dispatcher) { var rect = new System.Windows.Shapes.Rectangle { MaxWidth = totalSize.Width.Value, MaxHeight = totalSize.Height.Value }; if (overlayColor != null) { imgStream .CombineLatest(overlayColor.DistinctUntilChanged()) .ConnectWhile(model.IsRooted) .Subscribe( t => { dispatcher.Schedule(() => { rect.OpacityMask = t.Item1; rect.Fill = new SolidColorBrush(t.Item2.ToColor()); }); }); } else { imgStream .ConnectWhile(model.IsRooted) .Subscribe( img => { dispatcher.Schedule(() => { rect.OpacityMask = img; }); }); } return(rect); }
static FrameworkElement Rectangle( IMountLocation model, IObservable <BitmapImage> imageStream, Optional <IObservable <Color> > overlayColor, Dispatcher dispatcher) { return(overlayColor.Select( color => { var rect = new System.Windows.Shapes.Rectangle(); model.BindNativeProperty(dispatcher, "image", imageStream, bitmap => { var imgBrush = new ImageBrush(bitmap) { Stretch = Stretch.Uniform, ImageSource = bitmap, }; rect.OpacityMask = imgBrush; rect.MaxWidth = imgBrush.ImageSource.Width; rect.MaxHeight = imgBrush.ImageSource.Height; }); model.BindNativeProperty(dispatcher, "overlayColor", color, c => rect.Fill = new SolidColorBrush(c.ToColor())); return (FrameworkElement)rect; }).Or( () => { var imageControl = new System.Windows.Controls.Image() { StretchDirection = StretchDirection.DownOnly }; model.BindNativeProperty(dispatcher, "image", imageStream, bitmap => { imageControl.Source = bitmap; }); RenderOptions.SetBitmapScalingMode(imageControl, BitmapScalingMode.HighQuality); return (FrameworkElement)imageControl; })); }
public static void BindNativeDefaults(this IMountLocation self, FrameworkElement element, IScheduler dispatcher) { var frame = self.NativeFrame; self.BindNativeProperty( dispatcher, "left", frame.Left(), position => { if (!double.IsInfinity(position)) { Canvas.SetLeft(element, position); } }); self.BindNativeProperty( dispatcher, "top", frame.Top(), position => { if (!double.IsInfinity(position)) { Canvas.SetTop(element, position); } }); self.BindNativeProperty( dispatcher, "height", frame.Height, height => { if (!double.IsInfinity(height)) { element.Height = Math.Max(0, (height)); } }); self.BindNativeProperty( dispatcher, "width", frame.Width, width => { if (!double.IsInfinity(width)) { element.Width = Math.Max(0, (width)); } }); }
public static void BindList<T>( this IMountLocation self, IObservable<IEnumerable<T>> list, Action<T> add, Action<T> remove) { list // IMPORTANT: ConnectWhile has to be done first since else we'll lose all changes done to the children list while the ctrl is unrooted. // which breaks diffing, and we get dangling views (views that aren't removed). .ConnectWhile(self.IsRooted) .DiffSequence() .Subscribe(children => { foreach (var child in children.Removed) { remove(child); } foreach (var child in children.Added) { add(child); } }); }
public NativeControl(Func <IMountLocation, object> factory) { _factory = factory; _currentMountLocation = _mountLocation.Switch(); }