public GraphicIconButton() { HeightRequest = 44; WidthRequest = 44; icon = new NControlView { DrawingFunction = DrawIcon, }; circle = new NControlView { DrawingFunction = DrawCircle, }; Content = new Grid { Children = { circle, icon, }, }; OnInvalidate += (sender, e) => { circle.Invalidate(); icon.Invalidate(); }; }
public CardPageDemo() { Title = "CardPage"; var raiseExceptionButton = new NControlView { BackgroundColor = Color.Red, HeightRequest = 300, Content = new Label { Text = "Click to raise exception" }, }; raiseExceptionButton.OnTouchesBegan += (s, e) => { throw new InvalidOperationException("Whoopps"); }; Content = new StackLayout{ Padding = 24, Children = { new Button { BackgroundColor = Color.Transparent, Text = "Show", Command = ShowCardPageCommand }, new Button { Text = "Show from Modal Page", Command = new Command(async () => { await Application.Current.MainPage.Navigation.PushModalAsync( new NavigationPage( new ContentPage{ Title = "Navigation", Content = new StackLayout{ Children = { new Button{ VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, HeightRequest = 44, Text = "Show Card", Command = ShowCardPageCommand }, new Button{ VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, HeightRequest = 44, Text = "Close", Command = new Command(async () => { await Application.Current.MainPage.Navigation.PopModalAsync(); }) } } } }) ); }) }, raiseExceptionButton } }; }
/// <summary> /// Initializes a new instance of the <see cref="NControl.iOS.UITouchesGestureRecognizer"/> class. /// </summary> /// <param name="element">Element.</param> /// <param name="nativeView">Native view.</param> public UITouchesGestureRecognizer(NControlView element, UIView nativeView) { if (null == element) { throw new ArgumentNullException("element"); } if (null == nativeView) { throw new ArgumentNullException("nativeView"); } _element = element; _nativeView = nativeView; }
/// <summary> /// Initializes a new instance of the <see cref="NControl.Controls.CardPage"/> class. /// </summary> public CardPage() { // Get helper _platformHelper = DependencyService.Get<ICardPageHelper> (); if(_platformHelper == null) throw new InvalidOperationException("Error loading NControls - did you remember to call " + "NControls.Init() in your platform startup code?"); CardPadding = new Thickness (40, 100, 40, 200); BackgroundColor = Color.Transparent; NavigationPage.SetHasNavigationBar (this, false); NavigationPage.SetHasBackButton (this, false); _layout = new RelativeLayout (); base.Content = _layout; // Card _contentView = new RoundCornerView { BackgroundColor = Color.White, CornerRadius = 4, }; _overlay = new BoxView { BackgroundColor = Color.Black, Opacity = 0.0F, }; _layout.Children.Add (_overlay, () => _layout.Bounds); _layout.Children.Add(_contentView, ()=> new Rectangle ( (_platformHelper.ControlAnimatesItself ? CardPadding.Left : 0), (_platformHelper.ControlAnimatesItself ? CardPadding.Top :0), _layout.Width - (_platformHelper.ControlAnimatesItself ? (CardPadding.Right + CardPadding.Left) : 0), _layout.Height - (_platformHelper.ControlAnimatesItself ? (CardPadding.Bottom + CardPadding.Top) : 0))); if(_platformHelper.ControlAnimatesItself) _contentView.TranslationY = _platformHelper.GetScreenSize().Height - (CardPadding.Top); // Add tap _overlay.GestureRecognizers.Add (new TapGestureRecognizer { Command = new Command(async () => await CloseAsync()) }); }
/// <summary> /// Initializes a new instance of the /// <see cref="NControlDemo.Forms.Xamarin.Plugins.FormsApp.Controls.CircularButtonControl"/> class. /// </summary> public CircularButtonControl() { HeightRequest = 44; WidthRequest = 44; _label = new FontAwesomeLabel { Text = FontAwesomeLabel.FAAdjust, TextColor = Xamarin.Forms.Color.White, FontSize = 17, BackgroundColor = Xamarin.Forms.Color.Transparent, XAlign = Xamarin.Forms.TextAlignment.Center, YAlign = Xamarin.Forms.TextAlignment.Center, }; _circles = new NControlView { DrawingFunction = (canvas1, rect) => { var fillColor = new NGraphics.Color(FillColor.R, FillColor.G, FillColor.B, FillColor.A); canvas1.FillEllipse(rect, fillColor); rect.Inflate(new NGraphics.Size(-2, -2)); canvas1.FillEllipse(rect, Colors.White); rect.Inflate(new NGraphics.Size(-4, -4)); canvas1.FillEllipse(rect, fillColor); } }; Content = new Grid{ Children = { _circles, _label, } }; }
/// <summary> /// Initializes a new instance of the <see cref="Unizite.FormsApp.Controls.CalendarView"/> class. /// </summary> public CalendarView() { _currentMonth = GetFirstDayInMonth(DateTime.Now); // Layout var layout = new StackLayout { Spacing = 0 , VerticalOptions = LayoutOptions.FillAndExpand}; // Header _monthYearLabel = new Label { FontAttributes = FontAttributes.Bold, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, HeightRequest = TopHeight, }; // Prev month var prevMonthBtn = new RippleButton { BackgroundColor = Color.Transparent, FontFamily = FontAwesomeLabel.FontAwesomeName, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.CenterAndExpand, HeightRequest = TopHeight, WidthRequest = 34, TextColor = Color.FromHex("#AAAAAA"), Text = FontAwesomeLabel.FAChevronLeft, }; prevMonthBtn.Command = new Command( (obj) => { _currentMonth = _currentMonth.AddMonths(-1); UpdateCalendar(); }, (obj) => _currentMonth > MinDate - MinDate.TimeOfDay); // Next month var nextMonthBtn = new RippleButton{ BackgroundColor = Color.Transparent, FontFamily = FontAwesomeLabel.FontAwesomeName, HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.CenterAndExpand, HeightRequest = TopHeight, WidthRequest = 34, TextColor = Color.FromHex("#AAAAAAA"), Text = FontAwesomeLabel.FAChevronRight, }; nextMonthBtn.Command = new Command( (obj) => { _currentMonth = _currentMonth.AddMonths(1); UpdateCalendar(); }, (obj) => _currentMonth.AddMonths(1) <= MaxDate); var headerLayout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { prevMonthBtn, _monthYearLabel, nextMonthBtn } }; layout.Children.Add(headerLayout); // Day names var dayNames = CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedDayNames; var firstDayOfWeek = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek; var dayGrid = new Grid { HeightRequest = DayNamesHeight, }; var currentWeekDay = firstDayOfWeek; for (var d = 0; d < 7; d++) { var label = new Label{ BackgroundColor= Color.Transparent, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, Text = dayNames[(int)currentWeekDay] }; _dayNameLabels [d] = label; currentWeekDay++; if((int)currentWeekDay == 7) currentWeekDay = 0; dayGrid.Children.Add (label, d, 0); } layout.Children.Add(dayGrid); // Calendar _calendar = new NControlView{ DrawingFunction = DrawCalendar }; var calendarLayout = new AbsoluteLayout { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand}; calendarLayout.Children.Add(_calendar); AbsoluteLayout.SetLayoutBounds(_calendar, new Rectangle(0f, 0f, 1f, 1f)); AbsoluteLayout.SetLayoutFlags(_calendar, AbsoluteLayoutFlags.All); var dayNumberGrid = CreateDayNumberGrid(); calendarLayout.Children.Add(dayNumberGrid); AbsoluteLayout.SetLayoutBounds(dayNumberGrid, new Rectangle(0f, 0f, 1f, 1f)); AbsoluteLayout.SetLayoutFlags(dayNumberGrid, AbsoluteLayoutFlags.All); // Ellipse _ellipse = new NControlView { BackgroundColor = Color.Transparent, DrawingFunction = (canvas, rect) =>{ var h = Math.Min(rect.Width, rect.Height); var dx = (rect.Width - h)/2; var dy = (rect.Height - h)/2; var r = new NGraphics.Rect(dx, dy, h, h); canvas.DrawEllipse(r, null, new NGraphics.SolidBrush(Color.FromHex("#DDDDDD").ToNColor())); }, Scale = 0.0, }; calendarLayout.Children.Add(_ellipse); AbsoluteLayout.SetLayoutBounds(_ellipse, new Rectangle(0f, 0f, 1/7f, 1/6f)); AbsoluteLayout.SetLayoutFlags(_ellipse, AbsoluteLayoutFlags.All); layout.Children.Add(calendarLayout); Content = layout; }
/// <summary> /// Initializes a new instance of the <see cref="NControl.Controls.RippleButton"/> class. /// </summary> public RippleControl () { HeightRequest = 44; var layout = new RelativeLayout (); Content = layout; IsClippedToBounds = true; _ellipse = new NControlView { BackgroundColor = Color.Transparent, DrawingFunction = (canvas, rect) =>{ canvas.DrawEllipse(rect, null, new NGraphics.SolidBrush(RippleColor.ToNColor())); }, Scale = 0.0, }; layout.Children.Add (_ellipse, () => new Rectangle ( (layout.Width / 2) - (Math.Max(layout.Width, layout.Height) / 2), (layout.Height / 2) - (Math.Max(layout.Width, layout.Height) / 2), Math.Max(layout.Width, layout.Height), Math.Max(layout.Width, layout.Height))); }
/// <summary> /// Initializes a new instance of the <see cref="Unizite.FormsApp.Controls.CalendarView"/> class. /// </summary> public CalendarView() { // Layout var layout = new RelativeLayout (); // Header _monthYearLabel = new Label { FontAttributes = FontAttributes.Bold, HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, HeightRequest = TopHeight, }; _monthYearLabel.SetBinding (Label.TextProperty, MonthYearStringProperty.PropertyName); // Prev month var prevMonthBtn = new RippleButton { BackgroundColor = Color.Transparent, FontFamily = FontAwesomeLabel.FontAwesomeName, HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.CenterAndExpand, HeightRequest = TopHeight, WidthRequest = 34, TextColor = Color.FromHex("#AAAAAA"), Text = FontAwesomeLabel.FAChevronLeft, }; prevMonthBtn.Command = new Command((obj) => this.SelectedDate = this.SelectedDate.AddMonths (-1)); // Next month var nextMonthBtn = new RippleButton{ BackgroundColor = Color.Transparent, FontFamily = FontAwesomeLabel.FontAwesomeName, HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.CenterAndExpand, HeightRequest = TopHeight, WidthRequest = 34, TextColor = Color.FromHex("#AAAAAAA"), Text = FontAwesomeLabel.FAChevronRight, }; nextMonthBtn.Command = new Command((obj) => this.SelectedDate = this.SelectedDate.AddMonths (1)); var headerLayout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { prevMonthBtn, _monthYearLabel, nextMonthBtn } }; layout.Children.Add (headerLayout, ()=> new Rectangle(0, 0, layout.Width, TopHeight)); // Day names var dayNames = CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedDayNames; var firstDayOfWeek = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek; var dayGrid = new Grid { HeightRequest = DayNamesHeight, }; var currentWeekDay = firstDayOfWeek; for (var d = 0; d < 7; d++) { var label = new Label{ BackgroundColor= Color.Transparent, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, Text = dayNames[(int)currentWeekDay] }; _dayNameLabels [d] = label; currentWeekDay++; if((int)currentWeekDay == 7) currentWeekDay = 0; dayGrid.Children.Add (label, d, 0); } layout.Children.Add(dayGrid, ()=> new Rectangle (0, TopHeight, layout.Width, DayNamesHeight)); // Calendar _calendar = new NControlView{ DrawingFunction = DrawCalendar, }; layout.Children.Add (_calendar, ()=> new Rectangle ( 0, TopHeight+DayNamesHeight, layout.Width, layout.Height - (TopHeight + DayNamesHeight))); // Day Number Labels var lc = 0; var dayNumberGrid = new Grid { ColumnSpacing = 0, RowSpacing = 0, Padding = 0, ColumnDefinitions = { new ColumnDefinition{Width = new GridLength(100.0/7.0, GridUnitType.Star) }, new ColumnDefinition{Width = new GridLength(100.0/7.0, GridUnitType.Star) }, new ColumnDefinition{Width = new GridLength(100.0/7.0, GridUnitType.Star) }, new ColumnDefinition{Width = new GridLength(100.0/7.0, GridUnitType.Star) }, new ColumnDefinition{Width = new GridLength(100.0/7.0, GridUnitType.Star) }, new ColumnDefinition{Width = new GridLength(100.0/7.0, GridUnitType.Star) }, new ColumnDefinition{Width = new GridLength(100.0/7.0, GridUnitType.Star) }, }, RowDefinitions = { new RowDefinition{ Height = new GridLength(100.0/5.0, GridUnitType.Star) }, new RowDefinition{ Height = new GridLength(100.0/5.0, GridUnitType.Star) }, new RowDefinition{ Height = new GridLength(100.0/5.0, GridUnitType.Star) }, new RowDefinition{ Height = new GridLength(100.0/5.0, GridUnitType.Star) }, new RowDefinition{ Height = new GridLength(100.0/5.0, GridUnitType.Star) }, new RowDefinition{ Height = new GridLength(100.0/5.0, GridUnitType.Star) }, } }; layout.Children.Add (dayNumberGrid, ()=> new Rectangle ( 0, TopHeight+DayNamesHeight, layout.Width, layout.Height - (TopHeight + DayNamesHeight))); for (var r = 0; r < 6; r++) { for (var c = 0; c < 7; c++) { var dayLabel = new Label{ XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = Color.Black, BackgroundColor = Color.Transparent, Text = "A" + lc.ToString(), }; dayNumberGrid.Children.Add (dayLabel, c, r); _dayNumberLabels [lc++] = dayLabel; } } // Ellipse _ellipse = new NControlView { BackgroundColor = Color.Transparent, DrawingFunction = (canvas, rect) =>{ canvas.DrawEllipse(rect, null, new NGraphics.SolidBrush(Color.FromHex("#DDDDDD").ToNColor())); }, Scale = 0.0, }; layout.Children.Add (_ellipse, () => new Rectangle ( 0, TopHeight + DayNamesHeight, Math.Min(_calendar.Width / 7, _calendar.Height/7), Math.Min(_calendar.Width / 7, _calendar.Height/7) ) ); Content = layout; }
/// <summary> /// Initializes a new instance of the <see cref="NControl.Controls.TabStripControl"/> class. /// </summary> public TabStripControl () { _mainLayout = new RelativeLayout (); Content = _mainLayout; // Create tab control _buttonStack = new StackLayoutEx { Orientation = StackOrientation.Horizontal, Padding = 0, Spacing = 0, HorizontalOptions = LayoutOptions.Start, VerticalOptions= LayoutOptions.FillAndExpand, }; _indicator = new TabBarIndicator { VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.Start, BackgroundColor = (Color)TabIndicatorColorProperty.DefaultValue, HeightRequest = 6, WidthRequest = 0, }; _tabControl = new NControlView{ BackgroundColor = TabBackColor, Content = new Grid{ Padding = 0, ColumnSpacing = 0, RowSpacing=0, Children = { _buttonStack, _indicator, } } }; _mainLayout.Children.Add (_tabControl, () => new Rectangle ( 0, 0, _mainLayout.Width, TabHeight) ); // Create content control _contentView = new Grid { ColumnSpacing = 0, RowSpacing = 0, Padding = 0, BackgroundColor = Color.Transparent, }; _mainLayout.Children.Add (_contentView, () => new Rectangle ( 0, TabHeight, _mainLayout.Width, _mainLayout.Height-TabHeight) ); _children.CollectionChanged += (sender, e) => { _contentView.Children.Clear(); _buttonStack.Children.Clear(); foreach(var tabChild in Children) { var tabItemControl = new TabBarButton(tabChild.Title); if(FontFamily != null) tabItemControl.FontFamily = FontFamily; tabItemControl.FontSize = FontSize; tabItemControl.SelectedColor = TabIndicatorColor; _buttonStack.Children.Add(tabItemControl); } if(Children.Any()) Activate(Children.First(), false); }; // Border var border = new NControlView { DrawingFunction = (canvas, rect) => { canvas.DrawPath (new NGraphics.PathOp[]{ new NGraphics.MoveTo(0, 0), new NGraphics.LineTo(rect.Width, 0) }, NGraphics.Pens.Gray, null); }, }; _mainLayout.Children.Add (border, () => new Rectangle( 0, TabHeight, _mainLayout.Width, 1)); // Shadow _shadow = new NControlView { DrawingFunction = (canvas, rect)=> { canvas.DrawRectangle(rect, null, new NGraphics.LinearGradientBrush( new NGraphics.Point(0.5, 0.0), new NGraphics.Point(0.5, 1.0), Color.Black.MultiplyAlpha(0.3).ToNColor(), NGraphics.Colors.Clear, NGraphics.Colors.Clear)); } }; _mainLayout.Children.Add (_shadow, () => new Rectangle( 0, TabHeight, _mainLayout.Width, 6)); _shadow.IsVisible = false; SizeChanged += (object sender, EventArgs e) => { _buttonStack.ForceLayout(); ForceLayout(); }; }
/// <summary> /// Initializes a new instance of the <see cref="NControl.Controls.ActionButton"/> class. /// </summary> public ActionButton() { var layout = new Grid{Padding = 0, ColumnSpacing = 0, RowSpacing = 0}; ButtonShadowElement = new NControlView{ DrawingFunction = (canvas, rect) => { // Draw shadow rect.Inflate(new NGraphics.Size(-4)); rect.Y += 4; Device.OnPlatform( //iOS () => canvas.DrawEllipse (rect, null, new NGraphics.RadialGradientBrush ( new NGraphics.Color(0, 0, 0, 200), NGraphics.Colors.Clear)), // Android () => canvas.DrawEllipse (rect, null, new NGraphics.RadialGradientBrush ( new NGraphics.Point(rect.Width/2, (rect.Height/2)+2), new NGraphics.Size(rect.Width, rect.Height), new NGraphics.Color(0, 0, 0, 200), NGraphics.Colors.Clear)), // WP () => canvas.DrawEllipse (rect, null, new NGraphics.RadialGradientBrush ( new NGraphics.Color(0, 0, 0, 200), NGraphics.Colors.Clear)), null ); }, }; ButtonElement = new NControlView{ DrawingFunction = (canvas, rect) => { // Draw button circle rect.Inflate (new NGraphics.Size (-8)); canvas.DrawEllipse (rect, null, new NGraphics.SolidBrush(ButtonColor.ToNColor())); } }; ButtonIconLabel = new FontAwesomeLabel{ XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, TextColor = Color.White, Text = FontAwesomeLabel.FAPlus, FontSize = 14, }; layout.Children.Add (ButtonShadowElement); layout.Children.Add (ButtonElement); layout.Children.Add (ButtonIconLabel); Content = layout; }
/// <summary> /// Initializes a new instance of the /// <see cref="AvatarButton"/> class. /// </summary> public AvatarButton() { HeightRequest = 44; WidthRequest = 44; _label = new Label { Text = "+", TextColor = Xamarin.Forms.Color.White, FontSize = 17, BackgroundColor = Xamarin.Forms.Color.Transparent, XAlign = Xamarin.Forms.TextAlignment.Center, YAlign = Xamarin.Forms.TextAlignment.Center, }; _circle = new NControlView { DrawingFunction = (canvas1, rect) => { var fillColor = new NGraphics.Color(FillColor.R, FillColor.G, FillColor.B, FillColor.A); canvas1.FillEllipse(rect, fillColor); } }; Content = new Grid { Children = { _circle, _label, } }; }