public override void Draw(Canvas canvas) { RoundedBoxView rbv = (RoundedBoxView)this.Element; Rect rc = new Rect(); GetDrawingRect(rc); Rect interior = rc; interior.Inset((int)rbv.StrokeThickness, (int)rbv.StrokeThickness); Paint p = new Paint() { Color = rbv.Color.ToAndroid(), AntiAlias = true, }; canvas.DrawRoundRect(new RectF(interior), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p); p.Color = rbv.Stroke.ToAndroid(); p.StrokeWidth = (float)rbv.StrokeThickness; p.SetStyle(Paint.Style.Stroke); canvas.DrawRoundRect(new RectF(rc), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p); }
public override void Draw(Canvas canvas) { RoundedBoxView rbv = (RoundedBoxView)this.Element; Rect rc = new Rect(); GetDrawingRect(rc); Rect interior = rc; //interior.Inset((int)rbv.StrokeThickness, (int)rbv.StrokeThickness); Paint p = new Paint() { Color = rbv.Stroke.ToAndroid(), AntiAlias = true, Dither = true }; RectF drawRect = new RectF(interior); if (rbv.IsCircle) { var size = Math.Min(drawRect.Width(), drawRect.Height()); var x = (drawRect.Width() - size) / 2; var y = (drawRect.Height() - size) / 2; drawRect = new RectF(x, y, x + size, y + size); } float radius = (float)(rbv.IsCircle ? Math.Min(drawRect.Width(), drawRect.Height()) / 2 : rbv.CornerRadius); canvas.DrawRoundRect(drawRect, radius, radius, p); }
public Joystick() { this.Children.Add(BackgroundView = new RoundedBoxView { WidthRequest = 100, BackgroundColor = Color.Gray.MultiplyAlpha(.1), BorderColor = Color.Black, BorderWidth = 1, }); this.Children.Add(Thumb = new RoundedBoxView { WidthRequest = 50, BackgroundColor = Color.Black.MultiplyAlpha(.3), BorderColor = Color.Black.MultiplyAlpha(.5), BorderWidth = 1, }); this.Children.Add(Descriptor = new Label { HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }); var panGesture = new PanGestureRecognizer(); panGesture.PanUpdated += OnPanUpdated; GestureRecognizers.Add(panGesture); }
public static void UpdateFrom(this View nativeControl, RoundedBoxView formsControl, string propertyChanged) { if (nativeControl == null || formsControl == null) { return; } if (propertyChanged == RoundedBoxView.CornerRadiusProperty.PropertyName) { nativeControl.UpdateCornerRadius(formsControl.CornerRadius); } if (propertyChanged == VisualElement.BackgroundColorProperty.PropertyName) { var background = nativeControl.Background as GradientDrawable; if (background != null) { background.SetColor(formsControl.BackgroundColor.ToAndroid()); } } if (propertyChanged == RoundedBoxView.BorderColorProperty.PropertyName) { nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness); } if (propertyChanged == RoundedBoxView.BorderThicknessProperty.PropertyName) { nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness); } }
public static void UpdateFrom(this Border nativeControl, RoundedBoxView formsControl, string propertyChanged) { if (nativeControl == null || formsControl == null) { return; } if (propertyChanged == RoundedBoxView.CornerRadiusProperty.PropertyName) { nativeControl.UpdateCornerRadius(formsControl.CornerRadius); var rect = nativeControl.Child as Rectangle; if (rect != null) { rect.UpdateCornerRadius(formsControl.CornerRadius); } } if (propertyChanged == RoundedBoxView.RoundedBackgroudColorProperty.PropertyName) { nativeControl.Background = formsControl.RoundedBackgroudColor.ToBrush(); } if (propertyChanged == RoundedBoxView.BorderThicknessProperty.PropertyName) { var rect = nativeControl.Child as Rectangle; if (rect != null) { rect.UpdateBorderThickness(formsControl.BorderThickness, formsControl.HeightRequest, formsControl.WidthRequest); } } }
public Joystick() { Children.Add(BackgroundView = new RoundedBoxView { WidthRequest = 100, BorderColor = Color.Red, BorderWidth = 8, }); Children.Add(Thumb = new RoundedBoxView { WidthRequest = 50, BackgroundColor = Color.Red, }); Children.Add(Descriptor = new Label { HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, }); var panGesture = new PanGestureRecognizer(); panGesture.PanUpdated += OnPanUpdated; GestureRecognizers.Add(panGesture); }
void HandleTouch(object sender, TouchEventArgs e) { RoundedBoxView view = this.Element as RoundedBoxView; if (view != null) { if (view.IsInteractable == false) { e.Handled = false; } else { if (e.Event.Action == MotionEventActions.Up) { _tapEnded = true; Rect rc = new Rect(); GetDrawingRect(rc); int x = (int)e.Event.GetX(), y = (int)e.Event.GetY(); view.RaiseTapEnded((DateTime.Now - this._timeCalc).TotalMilliseconds, rc.Contains(x, y) == false); view.RaiseTapUp((DateTime.Now - this._timeCalc).TotalMilliseconds, rc.Contains(x, y) == false); } _detector.OnTouchEvent(e.Event); } } }
public override void Draw(Canvas canvas) { RoundedBoxView rbv = (RoundedBoxView)this.Element; Rect rc = new Rect(); GetDrawingRect(rc); Rect interior = rc; interior.Inset((int)rbv.BorderThickness, (int)rbv.BorderThickness); Paint p = new Paint() { Color = rbv.BackgroundColor.ToAndroid(), AntiAlias = true, }; var radius = (float)(rc.Width() / rbv.Width * rbv.CornerRadius); //canvas.DrawRoundRect(new RectF(interior), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p); canvas.DrawRoundRect(new RectF(interior), radius, radius, p); // Draw border if (rbv.BorderThickness > 0) { p.Color = rbv.BorderColor.ToAndroid(); p.StrokeWidth = (float)rbv.BorderThickness; p.SetStyle(Paint.Style.Stroke); //canvas.DrawRoundRect(new RectF(rc), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p); canvas.DrawRoundRect(new RectF(rc), radius, radius, p); } }
void UpdateCornerRadius(RoundedBoxView box) { Layer.CornerRadius = (nfloat)(box.CornerRadius); CGRect bounds = new CGRect(0, 0, box.Width, box.Width); Layer.Bounds = bounds; Layer.Frame = bounds; }
public static void InitializeFrom(this Rectangle nativeControl, RoundedBoxView formsControl) { if (nativeControl == null || formsControl == null) { return; } nativeControl.UpdateCornerRadius(formsControl.CornerRadius); nativeControl.UpdateBorderThickness(formsControl.BorderThickness, formsControl.HeightRequest, formsControl.WidthRequest); }
public SettingsNotificationPage() { var layout = new RelativeLayout() { Margin = 20 }; var listView = new ListView(); var roundedBoxView = new RoundedBoxView() { Color = Color.White, CornerRadius = 18, OutlineColor = Color.Black }; var referenceBoxView = new RoundedBoxView() { Color = Color.Transparent, CornerRadius = 10, OutlineColor = Color.Black, Opacity = 0 }; listView.ItemTemplate = new DataTemplate(typeof(CheckmarkViewCell)); listView.ItemsSource = SettingsNotificationRepo.GetData(); listView.ItemSelected += (sender, args) => { foreach (Setting tone in listView.ItemsSource) { tone.Checked = false; } (args.SelectedItem as Setting).Checked = true; }; // constraints setup var centerX = Constraint.RelativeToParent(parent => parent.Width / 2); var centerY = Constraint.RelativeToParent(parent => parent.Height / 2); var widthBox = Constraint.RelativeToParent(p => p.Width + 6); var heightBox = Constraint.RelativeToParent(p => p.Height + 6); var widthList = Constraint.RelativeToParent(p => p.Width); var heightList = Constraint.RelativeToParent(p => p.Height); // add invisible reference-view to center-position layout.Children.Add(referenceBoxView, centerX, centerY, widthBox, heightBox); // position rounded background to reference-view and move to center by subtracting halve of its bounds layout.Children.Add(roundedBoxView, Constraint.RelativeToView(referenceBoxView, (parent, sibling) => sibling.X - sibling.Width / 2), Constraint.RelativeToView(referenceBoxView, (parent, sibling) => sibling.Y - sibling.Height / 2), widthBox, heightBox); // position rounded list to reference-view and move to center by subtracting halve of its bounds layout.Children.Add(listView, Constraint.RelativeToView(referenceBoxView, (parent, sibling) => sibling.X + 3 - sibling.Width / 2), Constraint.RelativeToView(referenceBoxView, (parent, sibling) => sibling.Y + 3 - sibling.Height / 2), widthList, heightList); Content = layout; }
public static void InitializeFrom(this UIView nativeControl, RoundedBoxView formsControl) { if (nativeControl == null || formsControl == null) { return; } nativeControl.Layer.MasksToBounds = true; nativeControl.Layer.CornerRadius = (float)formsControl.CornerRadius; nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness); }
void UpdateBackgroundColor(RoundedBoxView box) { var stackLayout = Element as StackLayout; if (stackLayout == null) { return; } Layer.BackgroundColor = stackLayout.BackgroundColor.ToCGColor(); }
void HandleTouch(object sender, TouchEventArgs e) { _detector.OnTouchEvent(e.Event); if (e.Event.Action == MotionEventActions.Up) { RoundedBoxView view = this.Element as RoundedBoxView; if (view != null) { view.RaiseTapEnded(); } } }
void HandleGenericMotion(object sender, GenericMotionEventArgs e) { RoundedBoxView view = this.Element as RoundedBoxView; if (view != null && view.IsInteractable == false) { e.Handled = false; } else { _detector.OnTouchEvent(e.Event); } }
public static void InitializeFrom(this View nativeControl, RoundedBoxView formsControl) { if (nativeControl == null || formsControl == null) { return; } var background = new GradientDrawable(); background.SetColor(formsControl.BackgroundColor.ToAndroid()); nativeControl.Background = background; nativeControl.UpdateCornerRadius(formsControl.CornerRadius.TopLeft); nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness); }
public static void InitializeFrom(this UIView nativeControl, RoundedBoxView formsControl) { if (nativeControl == null || formsControl == null) { return; } float size = (float)formsControl.WidthRequest; nativeControl.Bounds = new CoreGraphics.CGRect(0, 0, size, size); nativeControl.Layer.CornerRadius = size / 2; nativeControl.Layer.MasksToBounds = true; nativeControl.UpdateColor(formsControl.RoundedBackgroudColor, formsControl.BorderThickness); }
public override void Draw(Canvas canvas) { RoundedBoxView rbv = (RoundedBoxView)this.Element; Rect rc = new Rect(); GetDrawingRect(rc); Rect interior = rc; interior.Inset((int)rbv.StrokeThickness, (int)rbv.StrokeThickness); // The shadow is fairly pointless on Android as the bounds are clipped. You can add support // if you need to, but it is best to not do something like that on the Native interface #region Drawing the Shadow // if (rbv.HasShadow) { // Paint shadowPaint = new Paint () { // Color = Xamarin.Forms.Color.FromRgba(0.0, 0.0, 0.0, 0.5).ToAndroid (), // AntiAlias = true // }; // // var shadowOffset = 5.0; // // var shadowRect = new Rect (rc); // shadowRect.Offset ((int)shadowOffset, (int)shadowOffset); // // canvas.DrawRoundRect( // new RectF(shadowRect), (float)rbv.CornerRadius, (float)rbv.CornerRadius, shadowPaint); // } #endregion Paint p = new Paint() { Color = rbv.Color.ToAndroid(), AntiAlias = true, }; canvas.DrawRoundRect(new RectF(interior), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p); p.Color = rbv.Stroke.ToAndroid(); p.StrokeWidth = (float)rbv.StrokeThickness; p.SetStyle(Paint.Style.Stroke); canvas.DrawRoundRect(new RectF(rc), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p); }
public override void Draw(CGRect rect) { RoundedBoxView rbv = (RoundedBoxView)this.Element; using (var context = UIGraphics.GetCurrentContext()) { context.SetFillColor(rbv.BackgroundColor.ToCGColor()); context.SetStrokeColor(rbv.BorderColor.ToCGColor()); context.SetLineWidth((float)rbv.BorderSize); var rc = this.Bounds.Inset((int)rbv.BorderSize, (int)rbv.BorderSize); nfloat radius = (nfloat)rbv.CornerRadius; radius = (nfloat)Math.Max(0, Math.Min(radius, Math.Max(rc.Height / 2, rc.Width / 2))); var path = CGPath.FromRoundedRect(rc, radius, radius); context.AddPath(path); context.DrawPath(CGPathDrawingMode.EOFillStroke); } }
public static void InitializeFrom(this Border nativeControl, RoundedBoxView formsControl) { if (nativeControl == null || formsControl == null) { return; } nativeControl.Height = formsControl.HeightRequest; nativeControl.Width = formsControl.WidthRequest; nativeControl.UpdateCornerRadius(formsControl.CornerRadius); nativeControl.UpdateBorderColor(formsControl.RoundedBackgroudColor); var rectangle = new Rectangle(); rectangle.InitializeFrom(formsControl); nativeControl.Child = rectangle; }
public override void Draw(System.Drawing.RectangleF rect) { RoundedBoxView rbv = (RoundedBoxView)this.Element; using (var context = UIGraphics.GetCurrentContext()) { context.SetFillColor(rbv.Color.ToCGColor()); context.SetStrokeColor(rbv.Stroke.ToCGColor()); context.SetLineWidth((float)rbv.StrokeThickness); var rc = this.Bounds.Inset((int)rbv.StrokeThickness, (int)rbv.StrokeThickness); float radius = (float)rbv.CornerRadius; radius = Math.Max(0, Math.Min(radius, Math.Max(rc.Height / 2, rc.Width / 2))); var path = CGPath.FromRoundedRect(rc, radius, radius); context.AddPath(path); context.DrawPath(CGPathDrawingMode.FillStroke); } }
public static void InitializeFrom(this View nativeControl, RoundedBoxView formsControl) { if (nativeControl == null || formsControl == null) { return; } var background = new GradientDrawable(); background.SetColor(formsControl.BackgroundColor.ToAndroid()); if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean) { nativeControl.Background = background; } nativeControl.UpdateCornerRadius(formsControl.CornerRadius); nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness); }
public RoundedBoxViewRenderer(Context context) : base(context) { _listener = new GeneralGestureListener(); _detector = new GestureDetector(context, _listener); this.SetWillNotDraw(false); _listener.TapStarted += (s, e) => { _tapEnded = false; this._timeCalc = DateTime.Now; RoundedBoxView view = this.Element as RoundedBoxView; if (view != null) { view.RaiseTapStarted(); } }; _listener.Tapped += (s, e) => { RoundedBoxView view = this.Element as RoundedBoxView; if (view != null) { view.RaiseTapped(); } }; _listener.LongPressed += (s, e) => { RoundedBoxView view = this.Element as RoundedBoxView; if (view != null) { view.RaiseLongPress((DateTime.Now - this._timeCalc).TotalMilliseconds); } if (!_tapEnded) { _tapEnded = true; view.RaiseTapEnded((DateTime.Now - this._timeCalc).TotalMilliseconds); } }; //_listener.TapEnded += (s, e) => {RoundedBoxView view = this.Element as RoundedBoxView; if (view != null) view.RaiseTapEnded((DateTime.Now - this._timeCalc).TotalMilliseconds); }; }
public RoundedBoxViewRenderer() { _listener = new GeneralGestureListener(); _detector = new GestureDetector(_listener); this.SetWillNotDraw(false); _listener.TapStarted += (s, e) => { RoundedBoxView view = this.Element as RoundedBoxView; if (view != null) { view.RaiseTapStarted(); } }; _listener.Tapped += (s, e) => { RoundedBoxView view = this.Element as RoundedBoxView; if (view != null) { view.RaiseTapped(); } }; _listener.TapEnded += (s, e) => { RoundedBoxView view = this.Element as RoundedBoxView; if (view != null) { view.RaiseTapEnded(); } }; }
public Joystick() { this.Children.Add(BackgroundView = new RoundedBoxView { WidthRequest = 100, BackgroundColor = Color.Gray.MultiplyAlpha(.1), BorderColor = Color.Black, BorderWidth = 1, }); this.Children.Add(Thumb = new RoundedBoxView { WidthRequest = 50, BackgroundColor = Color.Black.MultiplyAlpha(.3), BorderColor = Color.Black.MultiplyAlpha(.5), BorderWidth = 1, }); var panGesture = new PanGestureRecognizer(); panGesture.PanUpdated += OnPanUpdated; GestureRecognizers.Add(panGesture); }
public static void UpdateFrom(this UIView nativeControl, RoundedBoxView formsControl, string propertyChanged) { if (nativeControl == null || formsControl == null) { return; } if (propertyChanged == RoundedBoxView.CornerRadiusProperty.PropertyName) { nativeControl.Layer.CornerRadius = (float)formsControl.CornerRadius; } if (propertyChanged == RoundedBoxView.RoundedBackgroudColorProperty.PropertyName) { nativeControl.UpdateColor(formsControl.RoundedBackgroudColor, formsControl.BorderThickness); } if (propertyChanged == RoundedBoxView.BorderThicknessProperty.PropertyName) { nativeControl.UpdateColor(formsControl.RoundedBackgroudColor, formsControl.BorderThickness); } }
public static void InitializeFrom(this Android.Views.View nativeControl, RoundedBoxView formsControl) { if (nativeControl == null || formsControl == null) { return; } var background = new GradientDrawable(); background.SetColor(formsControl.RoundedBackgroudColor.ToAndroid()); if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean) { nativeControl.Background = background; } else { nativeControl.SetBackgroundDrawable(background); } nativeControl.UpdateCornerRadius(formsControl.CornerRadius); nativeControl.UpdateBorder(formsControl.RoundedBackgroudColor, formsControl.BorderThickness); nativeControl.UpdateSize(Convert.ToInt32(formsControl.WidthRequest), Convert.ToInt32(formsControl.HeightRequest)); }
public RoundedBoxViewGesureRecognizer(RoundedBoxView view) { _view = view; }
/** Creates the inner grid that holds the label grid and profile picture. * Post: Grid - the inner grid. **/ public Grid createInnerGrid(string name, DateTime date) { string profileImageLoc = "profile_filler.png"; // Setup the inner grid that holds profile picture + label grid Grid innerGrid = new Grid { Padding = 0, ColumnSpacing = 5 }; ColumnDefinition c = new ColumnDefinition(); ColumnDefinition c1 = new ColumnDefinition(); ColumnDefinition c2 = new ColumnDefinition(); c.Width = new GridLength(2, GridUnitType.Star); innerGrid.ColumnDefinitions.Insert(0, c); c1.Width = new GridLength(2, GridUnitType.Star);; innerGrid.ColumnDefinitions.Insert(1, c1); c2.Width = new GridLength(2, GridUnitType.Star);; innerGrid.ColumnDefinitions.Insert(2, c2); // Create the profile image RoundedBoxView profileImage = new RoundedBoxView { Source = profileImageLoc, HeightRequest = 100, WidthRequest = 100 }; innerGrid.Children.Add (profileImage, 0 ,0); innerGrid.Children.Add (createLabelGrid(name, date), 1, 10, 0, 1); return innerGrid; }
private void SetRadius(RoundedBoxView rbc) { Layer.MasksToBounds = (rbc.CornerRadius > 0); Layer.CornerRadius = rbc.CornerRadius; }
public override void Draw(CGRect rect) { RoundedBoxView rbv = (RoundedBoxView)this.Element; }