void ApplyTranslation(EvasMap map, ERect geometry, ref bool changed) { var shiftX = Forms.ConvertToScaledPixel(Element.TranslationX); var shiftY = Forms.ConvertToScaledPixel(Element.TranslationY); // apply translation, i.e. move/shift the object a little if (shiftX != 0 || shiftY != 0) { if (changed) { // special care is taken to apply the translation last Point3D p; for (int i = 0; i < 4; i++) { p = map.GetPointCoordinate(i); p.X += shiftX; p.Y += shiftY; map.SetPointCoordinate(i, p); } } else { // in case when we only need translation, then construct the map in a simpler way geometry.X += shiftX; geometry.Y += shiftY; map.PopulatePoints(geometry, 0); changed = true; } } }
protected override EvasObject OnGetContent(Cell cell, string part) { if (part == MainContentPart) { var viewCell = (ViewCell)cell; var listView = viewCell?.RealParent as ListView; // It is a condition for reusable the cell if (listView != null && listView.HasUnevenRows == false && !(listView.ItemTemplate is DataTemplateSelector) && !GetCurrentItem().IsGroupItem) { return(CreateReusableContent(viewCell)); } Platform.GetRenderer(viewCell.View)?.Dispose(); var renderer = Platform.GetOrCreateRenderer(viewCell.View); double height = viewCell.RenderHeight; height = height > 0 ? height : FindCellContentHeight(viewCell); renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(height); (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); UpdatePropagateEvent(viewCell.View); return(renderer.NativeView); } return(null); }
public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) { if (null == NativeView) { return(new SizeRequest(new Size(0, 0))); } else { int availableWidth = Forms.ConvertToScaledPixel(widthConstraint); int availableHeight = Forms.ConvertToScaledPixel(heightConstraint); if (availableWidth < 0) { availableWidth = int.MaxValue; } if (availableHeight < 0) { availableHeight = int.MaxValue; } Size measured; var nativeViewMeasurable = NativeView as Native.IMeasurable; if (nativeViewMeasurable != null) { measured = nativeViewMeasurable.Measure(availableWidth, availableHeight).ToDP(); } else { measured = Measure(availableWidth, availableHeight).ToDP(); } return(new SizeRequest(measured, MinimumSize())); } }
void OnLayout() { if (Geometry.Width == 0 || Geometry.Height == 0) { return; } var bound = Geometry; int navBarHeight; if (_navBarIsVisible) { var navBound = bound; navBarHeight = Forms.ConvertToScaledPixel(_navBar.GetDefaultHeight()); navBound.Height = navBarHeight; _navBar.Show(); _navBar.Geometry = navBound; _navBar.RaiseTop(); } else { navBarHeight = 0; _navBar.Hide(); } bound.Y += navBarHeight; bound.Height -= navBarHeight; _viewStack.Geometry = bound; }
public static SKMatrix ToSkia(this Transform transform) { SKMatrix skMatrix = SKMatrix.CreateIdentity(); if (transform == null) { return(skMatrix); } Matrix matrix = transform.Value; skMatrix.Values = new float[] { (float)matrix.M11, (float)matrix.M21, Forms.ConvertToScaledPixel(matrix.OffsetX), (float)matrix.M12, (float)matrix.M22, Forms.ConvertToScaledPixel(matrix.OffsetY), 0, 0, 1 }; return(skMatrix); }
protected override EvasObject OnGetContent(Cell cell, string part) { if (part == ImagePart) { var imgCell = cell as ImageCell; int pixelSize = Forms.ConvertToScaledPixel(imgCell.RenderHeight); if (pixelSize <= 0) { pixelSize = this.GetDefaultHeightPixel(); } var image = new Native.Image(Forms.NativeParent) { MinimumWidth = pixelSize, MinimumHeight = pixelSize }; image.SetAlignment(-1.0, -1.0); // fill image.SetWeight(1.0, 1.0); // expand var task = image.LoadFromImageSourceAsync(imgCell.ImageSource); return(image); } else { return(null); } }
protected override ElmSharp.Size Measure(int availableWidth, int availableHeight) { var size = _image.Measure(availableHeight, availableHeight); size.Width += Forms.ConvertToScaledPixel(Element.Padding.HorizontalThickness); size.Height += Forms.ConvertToScaledPixel(Element.Padding.VerticalThickness); return(size); }
void Initialize(EvasObject parent) { _menu = new GenList(parent) { BackgroundColor = EColor.Transparent, Style = "solid/default", }; _menu.ItemSelected += (s, e) => { _flyoutMenu.TryGetValue(e.Item.Data as Item, out Element element); SelectedItemChanged?.Invoke(this, new SelectedItemChangedEventArgs(element, -1)); }; _menu.Show(); PackEnd(_menu); _defaultClass = new GenItemClass("double_label") { GetTextHandler = (obj, part) => { if (part == "elm.text") { return(((Item)obj).Title); } else { return(null); } }, GetContentHandler = (obj, part) => { if (part == "elm.swallow.icon") { var icon = ((Item)obj).Icon; if (icon != null) { var image = new Native.Image(parent) { MinimumWidth = Forms.ConvertToScaledPixel(24), MinimumHeight = Forms.ConvertToScaledPixel(24) }; var result = image.LoadFromImageSourceAsync(icon); return(image); } else { return(null); } } else { return(null); } } }; }
protected override EvasObject OnGetContent(Cell cell, string part) { if (part == MainContentPart) { var entryCell = cell as EntryCell; int pixelHeight = Forms.ConvertToScaledPixel(entryCell.RenderHeight); pixelHeight = pixelHeight > 0 ? pixelHeight : Forms.ConvertToPixel(s_defaultHeight); var label = new Label() { HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Center, VerticalTextAlignment = TextAlignment.Center, FontSize = -1 }; label.SetBinding(Label.TextProperty, new Binding(EntryCell.LabelProperty.PropertyName)); label.SetBinding(Label.TextColorProperty, new Binding(EntryCell.LabelColorProperty.PropertyName, converter: new DefaultColorConverter())); var entry = new Entry() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, FontSize = -1, }; entry.SetBinding(Entry.TextProperty, new Binding(EntryCell.TextProperty.PropertyName, BindingMode.TwoWay)); entry.SetBinding(Entry.PlaceholderProperty, new Binding(EntryCell.PlaceholderProperty.PropertyName)); entry.SetBinding(InputView.KeyboardProperty, new Binding(EntryCell.KeyboardProperty.PropertyName)); entry.SetBinding(Entry.HorizontalTextAlignmentProperty, new Binding(EntryCell.HorizontalTextAlignmentProperty.PropertyName)); var layout = new StackLayout() { Orientation = StackOrientation.Horizontal, Children = { label, entry } }; layout.Parent = cell; layout.BindingContext = entryCell; layout.MinimumHeightRequest = Forms.ConvertToScaledDP(pixelHeight); var renderer = Platform.GetOrCreateRenderer(layout); (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); var nativeView = renderer.NativeView; nativeView.PropagateEvents = false; nativeView.MinimumHeight = pixelHeight; _cacheCandidate[nativeView] = layout; nativeView.Deleted += (sender, e) => { _cacheCandidate.Remove(sender as EvasObject); }; return(nativeView); } return(null); }
void Initialize(EvasObject parent) { _menu = new GenList(parent) { BackgroundColor = EColor.Transparent, Style = "solid/default", }; _menu.ItemSelected += (s, e) => { MenuItemSelected?.Invoke(this, e); }; _menu.Show(); PackEnd(_menu); _defaultClass = new GenItemClass("double_label") { GetTextHandler = (obj, part) => { if (part == "elm.text") { return(((Item)obj).Title); } else { return(null); } }, GetContentHandler = (obj, part) => { if (part == "elm.swallow.icon") { var icon = ((Item)obj).Icon; if (icon != null) { var image = new ElmSharp.Image(parent) { MinimumWidth = Forms.ConvertToScaledPixel(24), MinimumHeight = Forms.ConvertToScaledPixel(24) }; var result = image.Load(ResourcePath.GetPath(icon)); return(image); } else { return(null); } } else { return(null); } } }; }
EvasObject GetContent(object data, string part) { ShellSection section = data as ShellSection; var box = new EBox(Forms.NativeParent); box.Show(); EImage icon = null; if (section.Icon != null) { icon = new EImage(Forms.NativeParent); icon.Show(); box.PackEnd(icon); _ = icon.LoadFromImageSourceAsync(section.Icon); } var title = new Native.Label(Forms.NativeParent) { Text = section.Title, FontSize = Forms.ConvertToEflFontPoint(14), HorizontalTextAlignment = Native.TextAlignment.Start, VerticalTextAlignment = Native.TextAlignment.Center, }; title.Show(); box.PackEnd(title); int iconPadding = Forms.ConvertToScaledPixel(this.GetIconPadding()); int iconSize = Forms.ConvertToScaledPixel(this.GetIconSize()); int cellHeight = iconPadding * 2 + iconSize; box.SetLayoutCallback(() => { var bound = box.Geometry; int leftMargin = iconPadding; if (icon != null) { var iconBound = bound; iconBound.X += iconPadding; iconBound.Y += iconPadding; iconBound.Width = iconSize; iconBound.Height = iconSize; icon.Geometry = iconBound; leftMargin = (2 * iconPadding + iconSize); } bound.X += leftMargin; bound.Width -= leftMargin; title.Geometry = bound; }); box.MinimumHeight = cellHeight; return(box); }
void UpdateHorizontalScrollStep(bool initialize) { var step = Specific.GetHorizontalScrollStep(Element); if (initialize && step == -1) { return; } Control.HorizontalStepSize = step != -1 ? Forms.ConvertToScaledPixel(step) : _defaultHorizontalStepSize; }
void OnRadiusUpdate(bool init) { int topLeft = Forms.ConvertToScaledPixel(Element.CornerRadius.TopLeft); int topRight = Forms.ConvertToScaledPixel(Element.CornerRadius.TopRight); int bottomLeft = Forms.ConvertToScaledPixel(Element.CornerRadius.BottomLeft); int bottomRight = Forms.ConvertToScaledPixel(Element.CornerRadius.BottomRight); Control.SetRadius(topLeft, topRight, bottomLeft, bottomRight); if (!init) { Control.Draw(); } }
static SKPath MakePath(EllipseGeometry ellipseGeometry) { var path = new SKPath(); path.AddOval(new SKRect( Forms.ConvertToScaledPixel(ellipseGeometry.Center.X - ellipseGeometry.RadiusX), Forms.ConvertToScaledPixel(ellipseGeometry.Center.Y - ellipseGeometry.RadiusY), Forms.ConvertToScaledPixel(ellipseGeometry.Center.X + ellipseGeometry.RadiusX), Forms.ConvertToScaledPixel(ellipseGeometry.Center.Y + ellipseGeometry.RadiusY)), SKPathDirection.Clockwise); return(path); }
static SKPath MakePath(LineGeometry lineGeometry) { var path = new SKPath(); path.MoveTo( Forms.ConvertToScaledPixel(lineGeometry.StartPoint.X), Forms.ConvertToScaledPixel(lineGeometry.StartPoint.Y)); path.LineTo( Forms.ConvertToScaledPixel(lineGeometry.EndPoint.X), Forms.ConvertToScaledPixel(lineGeometry.EndPoint.Y)); return(path); }
static SKPath MakePath(RectangleGeometry rectangleGeometry) { var path = new SKPath(); FormsRectangle rect = rectangleGeometry.Rect; path.AddRect(new SKRect( Forms.ConvertToScaledPixel(rect.Left), Forms.ConvertToScaledPixel(rect.Top), Forms.ConvertToScaledPixel(rect.Right), Forms.ConvertToScaledPixel(rect.Bottom)), SKPathDirection.Clockwise); return(path); }
void OnLayout() { var outter = Control.Geometry; var width = outter.Width - Forms.ConvertToScaledPixel(Element.Padding.HorizontalThickness); var height = outter.Height - Forms.ConvertToScaledPixel(Element.Padding.VerticalThickness); var left = outter.Left + Forms.ConvertToScaledPixel(Element.Padding.Left); var top = outter.Top + Forms.ConvertToScaledPixel(Element.Padding.Top); var imageBound = new Rect(left, top, width, height); _image.Geometry = imageBound; _button.Geometry = outter; _round.Draw(outter); _border.Draw(outter); }
void UpdateContentSize() { _scrollCanvas.MinimumWidth = Forms.ConvertToScaledPixel(Element.ContentSize.Width + Element.Padding.HorizontalThickness); _scrollCanvas.MinimumHeight = Forms.ConvertToScaledPixel(Element.ContentSize.Height + Element.Padding.VerticalThickness); // elm-scroller updates the CurrentRegion after render Device.BeginInvokeOnMainThread(() => { if (Control != null) { OnScrolled(Control, EventArgs.Empty); } }); }
void UpdateBorderWidth(bool init) { if (Element.BorderWidth > 0) { _border.BorderWidth = Forms.ConvertToScaledPixel(Element.BorderWidth); } else { _border.BorderWidth = 0; } if (!init) { _border.Draw(); } }
protected override EvasObject OnReusableContent(Cell cell, string part, EvasObject old) { if (!_cacheCandidate.ContainsKey(old)) { return(null); } var layout = _cacheCandidate[old]; layout.BindingContext = cell; int height = Forms.ConvertToScaledPixel(cell.RenderHeight); height = height > 0 ? height : Forms.ConvertToPixel(s_defaultHeight); old.MinimumHeight = height; return(old); }
void UpdateRadius(bool init) { if (Element.CornerRadius > 0) { _round.SetRadius(Forms.ConvertToScaledPixel(Element.CornerRadius)); _border.SetRadius(Forms.ConvertToScaledPixel(Element.CornerRadius)); } else { _round.SetRadius(0); _border.SetRadius(0); } if (!init) { _round.Draw(); _border.Draw(); } }
void UpdateContentSize() { if (_content == null) { return; } _content.MinimumWidth = Forms.ConvertToScaledPixel(Element.ContentSize.Width); _content.MinimumHeight = Forms.ConvertToScaledPixel(Element.ContentSize.Height); // elm-scroller updates the CurrentRegion after render Device.BeginInvokeOnMainThread(() => { if (Control != null) { OnScrolled(Control, EventArgs.Empty); } }); }
public static ICollectionViewLayoutManager ToLayoutManager(this IItemsLayout layout, ItemSizingStrategy sizing = ItemSizingStrategy.MeasureFirstItem) { switch (layout) { case LinearItemsLayout listItemsLayout: return(new LinearLayoutManager(listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal, sizing, Forms.ConvertToScaledPixel(listItemsLayout.ItemSpacing))); case GridItemsLayout gridItemsLayout: return(new GridLayoutManager(gridItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal, gridItemsLayout.Span, sizing, Forms.ConvertToScaledPixel(gridItemsLayout.VerticalItemSpacing), Forms.ConvertToScaledPixel(gridItemsLayout.HorizontalItemSpacing))); default: break; } return(new LinearLayoutManager(false)); }
void InitializeFlyout() { ((IShellController)Element).StructureChanged += OnShellStructureChanged; View flyoutHeader = ((IShellController)Element).FlyoutHeader; if (flyoutHeader != null) { var headerView = Platform.GetOrCreateRenderer(flyoutHeader); (headerView as LayoutRenderer)?.RegisterOnLayoutUpdated(); Size request = flyoutHeader.Measure(Forms.ConvertToScaledDP(_native.NavigationView.MinimumWidth), Forms.ConvertToScaledDP(_native.NavigationView.MinimumHeight)).Request; headerView.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(request.Height); _native.NavigationView.Header = headerView.NativeView; } BuildMenu(); _native.NavigationView.MenuItemSelected += OnItemSelected; }
EvasObject GetContent(object data, string part) { ShellSection section = data as ShellSection; var box = new Native.Box(Forms.NativeParent); box.Show(); var icon = new Native.Image(Forms.NativeParent) { MinimumWidth = Forms.ConvertToScaledPixel(44), MinimumHeight = Forms.ConvertToScaledPixel(27) }; var task = icon.LoadFromImageSourceAsync(section.Icon); icon.Show(); var title = new Native.Label(Forms.NativeParent) { Text = section.Title, FontSize = Forms.ConvertToEflFontPoint(14), HorizontalTextAlignment = Native.TextAlignment.Start, VerticalTextAlignment = Native.TextAlignment.Center }; title.Show(); box.PackEnd(icon); box.PackEnd(title); box.LayoutUpdated += (object sender, LayoutEventArgs e) => { icon.Move(e.Geometry.X + _iconPadding, e.Geometry.Y + _iconPadding); icon.Resize(_iconSize, _iconSize); title.Move(e.Geometry.X + 2 * _iconPadding + _iconSize, e.Geometry.Y); title.Resize(e.Geometry.Width - (2 * _iconPadding + _iconSize), e.Geometry.Height); }; box.MinimumHeight = _cellHeight; return(box); }
EvasObject CreateReusableContent(ViewCell viewCell) { var listView = viewCell.RealParent as ListView; ViewCell duplicatedCell = (ViewCell)listView.ItemTemplate.CreateContent(); duplicatedCell.BindingContext = viewCell.BindingContext; duplicatedCell.Parent = listView; var renderer = Platform.GetOrCreateRenderer(duplicatedCell.View); double height = duplicatedCell.RenderHeight; height = height > 0 ? height : FindCellContentHeight(duplicatedCell); renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(height); _cacheCandidate[renderer.NativeView] = duplicatedCell; renderer.NativeView.Deleted += (sender, e) => { _cacheCandidate.Remove((EvasObject)sender); }; (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); return(renderer.NativeView); }
public static ESize ToPixel(this Size size) { return(new ESize(Forms.ConvertToScaledPixel(size.Width), Forms.ConvertToScaledPixel(size.Height))); }
public static int GetDefaultHeightPixel(this ImageCellRenderer imageCell) { return(Forms.ConvertToScaledPixel(ThemeConstants.ImageCell.Resources.DefaultHeight)); }
void OnPromptRequested(Page sender, PromptArguments args) { // Verify that the page making the request is child of this platform if (!_platform.PageIsChildOfPlatform(sender)) { return; } var prompt = Native.Dialog.CreateDialog(Forms.NativeParent, (args.Accept != null)); prompt.Title = args.Title; var entry = new Entry { MinimumWidthRequest = 200, HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.FromRgb(250, 250, 250), TextColor = Color.Black, Keyboard = args.Keyboard, }; if (!string.IsNullOrEmpty(args.Placeholder)) { entry.Placeholder = args.Placeholder; } if (args.MaxLength > 0) { entry.MaxLength = args.MaxLength; } var layout = new StackLayout { Spacing = 10, Children = { new Label { LineBreakMode = LineBreakMode.CharacterWrap, TextColor = Device.Idiom == TargetIdiom.Watch ? Color.White : Color.Accent, Text = args.Message, HorizontalOptions = LayoutOptions.FillAndExpand, HorizontalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Subtitle, typeof(Label)), }, entry, } }; layout.Parent = sender; var layoutrenderer = Platform.GetOrCreateRenderer(layout); var request = layout.Measure(Device.Idiom == TargetIdiom.Watch ? sender.Width * 0.7 : sender.Width, sender.Height); (layoutrenderer as LayoutRenderer).RegisterOnLayoutUpdated(); layoutrenderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(request.Request.Height); layoutrenderer.NativeView.MinimumWidth = Forms.ConvertToScaledPixel(request.Request.Width); prompt.Content = layoutrenderer.NativeView; var cancel = new EButton(prompt) { Text = args.Cancel }; prompt.NegativeButton = cancel; cancel.Clicked += (s, evt) => { args.SetResult(null); prompt.Dismiss(); }; if (args.Accept != null) { var ok = new EButton(prompt) { Text = args.Accept }; prompt.NeutralButton = ok; ok.Clicked += (s, evt) => { args.SetResult(entry.Text); prompt.Dismiss(); }; } entry.Completed += (s, e) => { args.SetResult(entry.Text); prompt.Dismiss(); }; prompt.BackButtonPressed += (s, evt) => { prompt.Dismiss(); }; prompt.Show(); _alerts.Add(prompt); prompt.Dismissed += (s, e) => _alerts.Remove(prompt); }
void UpdateItems() { CurrentItems = GetSwipedItems(); var itemsLayout = new StackLayout { Spacing = 0, Orientation = IsHorizontalSwipe ? StackOrientation.Horizontal : StackOrientation.Vertical, FlowDirection = SwipeDirection == SwipeDirection.Left ? FlowDirection.RightToLeft : FlowDirection.LeftToRight }; foreach (var item in CurrentItems) { View itemView = null; if (item is SwipeItem switem) { itemView = CreateItemView(switem, !IsHorizontalSwipe); } else if (item is SwipeItemView customItem) { itemView = CreateItemView(customItem); } else { continue; } var tap = new TapGestureRecognizer(); tap.Command = item.Command; tap.CommandParameter = item.CommandParameter; tap.Tapped += (s, e) => { if (item is SwipeItem swipeItem) { swipeItem.OnInvoked(); } if (item is SwipeItemView customSwipeItem) { customSwipeItem.OnInvoked(); } if (CurrentItems.SwipeBehaviorOnInvoked != SwipeBehaviorOnInvoked.RemainOpen) { Device.BeginInvokeOnMainThread(() => { _ = SwipeCloseAsync(); }); } }; itemView.GestureRecognizers.Add(tap); if (IsHorizontalSwipe) { itemView.HorizontalOptions = LayoutOptions.Start; itemView.VerticalOptions = LayoutOptions.FillAndExpand; } else { itemView.VerticalOptions = LayoutOptions.Start; itemView.HorizontalOptions = LayoutOptions.FillAndExpand; } itemsLayout.Children.Add(itemView); } var itemsRenderer = Platform.GetOrCreateRenderer(itemsLayout); (itemsRenderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); var measured = itemsLayout.Measure(Element.Width, Element.Height); MaximumSwipeSize = Forms.ConvertToScaledPixel( IsHorizontalSwipe ? Math.Min(measured.Request.Width, Element.Width) : Math.Min(measured.Request.Height, Element.Height)); Control.Children.Add(itemsRenderer.NativeView); var itemsGeometry = NativeView.Geometry; if (SwipeDirection == SwipeDirection.Up) { itemsGeometry.Y += (itemsGeometry.Height - MaximumSwipeSize); } itemsRenderer.NativeView.Geometry = itemsGeometry; itemsRenderer.NativeView.StackBelow(Platform.GetRenderer(SwipeView.Content).NativeView); _itemsRenderer = itemsRenderer; }