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> /// Startup animations /// </summary> protected override async void OnAppearing() { base.OnAppearing(); // Start the progress control _progress.Start(); // Lets pretend we're doing something await Task.Delay(1500); // Introduce the navigation bar and toolbar await ShowChromeAsync(); // Hide the background and remove progressbar await Task.WhenAll(new[] { _topBackgroundView.TranslateTo(0, -Height / 2, 465, Easing.CubicIn), _bottomBackgroundView.TranslateTo(0, Height, 465, Easing.CubicIn), _progress.FadeTo(0, 365, Easing.CubicIn) }); // Add map var map = new Map(); var mapOverlay = new NControlView { BackgroundColor = Xamarin.Forms.Color.Transparent, }; mapOverlay.OnTouchesBegan += async(sender, e) => await ToggleChromeAsync(); _mapContainer.Children.Add(map, () => _mapContainer.Bounds); _mapContainer.Children.Add(mapOverlay, () => _mapContainer.Bounds); }
/// <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()); } }; 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="T:ExpenseClaimApp.Controls.ImageActionButton"/> class. /// </summary> public ImageActionButton() { 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; if (Device.RuntimePlatform == Device.iOS) { //iOS canvas.DrawEllipse(rect, null, new NGraphics.RadialGradientBrush(new NGraphics.Color(0, 0, 0, 200), NGraphics.Colors.Clear)); } else if (Device.RuntimePlatform == Device.Android) { // 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)); } } }; ButtonElement = new NControlView { DrawingFunction = (canvas, rect) => { // Draw button circle rect.Inflate(new NGraphics.Size(-8)); canvas.DrawEllipse(rect, null, new NGraphics.SolidBrush(ButtonColor.ToNColor())); } }; ButtonIconImage = new Image { Scale = 0.4 }; var imageWrapper = new Grid { Padding = 5 }; imageWrapper.Children.Add(ButtonIconImage); layout.Children.Add(ButtonShadowElement); layout.Children.Add(ButtonElement); layout.Children.Add(imageWrapper); Content = layout; }
public CircleButtonView() { _labelDuration = new Label { Text = DurationText(), TextColor = Xamarin.Forms.Color.Blue, FontSize = 35, BackgroundColor = Xamarin.Forms.Color.Transparent, HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Center, VerticalTextAlignment = Xamarin.Forms.TextAlignment.Center, }; _labelTimeLeft = new Label { Text = TimeLeftText(), FontSize = 15, TextColor = Xamarin.Forms.Color.Green, BackgroundColor = Xamarin.Forms.Color.Transparent, HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Center, }; _circle = new NControlView { DrawingFunction = DrawCircle }; var layout = new RelativeLayout(); layout.Children.Add(_circle, Constraint.RelativeToParent((parent) => { return(0); }), Constraint.RelativeToParent((parent) => { return(0); }), Constraint.RelativeToParent((parent) => { return(parent.Width); }), Constraint.RelativeToParent((parent) => { return(parent.Height); })); layout.Children.Add(_labelDuration, Constraint.RelativeToParent((parent) => { return(0); }), Constraint.RelativeToParent((parent) => { return(60); }), Constraint.RelativeToParent((parent) => { return(parent.Width); })); layout.Children.Add(_labelTimeLeft, Constraint.RelativeToParent((parent) => { return(0); }), Constraint.RelativeToParent((parent) => { return(120); }), Constraint.RelativeToParent((parent) => { return(parent.Width); })); Content = layout; }
/// <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()) }); }
private void GetView() { Content = new NControlView((ICanvas canvas, Rect rect) => { if (CheckThickness <= 0) { CheckThickness = WidthRequest / 10; } canvas.DrawRectangle(rect, new NGraphics.Size(-5), pen: new Pen(BorderColor.ToNColor(), BorderThickness), brush: new SolidBrush(FillColor.ToNColor())); if (IsChecked) { canvas.DrawLine(new NGraphics.Point(rect.Width.PerctPoint(20), rect.Height.PerctPoint(50d)), new NGraphics.Point(rect.Width.PerctPoint(40), rect.Height.PerctPoint(80)), new Pen(CheckColor.ToNColor(), CheckThickness)); canvas.DrawLine(new NGraphics.Point(rect.Width.PerctPoint(35), rect.Height.PerctPoint(80)), new NGraphics.Point(rect.Width.PerctPoint(80), rect.Height.PerctPoint(30)), new Pen(CheckColor.ToNColor(), CheckThickness)); } }); }
/// <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 Label { Text = "+", TextColor = Xamarin.Forms.Color.White, FontSize = 17, BackgroundColor = Xamarin.Forms.Color.Transparent, HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Center, VerticalTextAlignment = 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="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() { _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.Start, VerticalOptions = LayoutOptions.CenterAndExpand, HeightRequest = TopHeight, WidthRequest = 34, TextColor = Color.FromHex("#AAAAAA"), 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); layout.Children.Add(new BoxView { HeightRequest = 8 }); // 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; }
public GraphCell() : base() { StackLayout dateLayout; Label dateLabel; /* Used when drawing. */ var points = new List <NPoint>(); var pointSize = new NSize(CaptionSize * 5 / 6); var halfPoint = pointSize / 2; View = dataView = new NControlView { Content = new StackLayout { //BackgroundColor = MainApp.RandomColor(), Orientation = StackOrientation.Horizontal, Children = { (dateLayout = new StackLayout { HorizontalOptions = LayoutOptions.EndAndExpand, //Padding = new Thickness(7, 0), WidthRequest = SpaceUnderGraph, Children = { (dateLabel = new Label { HorizontalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.CenterAndExpand, Rotation = -90, Style = StyleKit.AutoDarkLabelStyles.Caption, //FontSize = 12, BindingContext = this }) } }) } }, DrawingFunction = (canvas, rect) => { /* Transforms for natural drawing - as in the end, the whole graph is rotated 90 degrees! */ canvas.Rotate(-90); canvas.Translate(-rect.Height, halfPoint.Height); rect = new NRect(NPoint.Zero, new NSize(rect.Size.Height, rect.Size.Width - dateLayout.Width - pointSize.Height)); //canvas.DrawLine(rect.BottomLeft, rect.BottomRight, Colors.Black, 2); if (Data == null) { return; } points.Clear(); /* Add past points */ var yesterday = Data.Yesterday; if (yesterday?.Events?.Count == 1) { var beforeYesterday = yesterday?.Yesterday; points.AddRange(CalculateEventPoints(beforeYesterday?.Events, rect, -2)); } points.AddRange(CalculateEventPoints(yesterday?.Events, rect, -1)); /* Add today's points */ points.AddRange(CalculateEventPoints(Data.Events, rect)); /* Add future points */ var tomorrow = Data.Tomorrow; points.AddRange(CalculateEventPoints(tomorrow?.Events, rect, 1)); if (tomorrow?.Events?.Count == 1) { var afterTomorrow = tomorrow?.Tomorrow; points.AddRange(CalculateEventPoints(afterTomorrow?.Events, rect, 2)); } if (Data.Events.Count > 0) { var path = new Path(pen: new Pen(Colors.Black, pointSize.Width / 4)); path.MoveTo(points[0]); for (int i = 1; i < points.Count; i++) { path.Operations.Add(SplineTo( from: points[i - 1], to: points[i], beforeFrom: i >= 2 ? points[i - 2] : points[i - 1] - (points[i] - points[i - 1]).WithY(0), afterTo: i <= points.Count - 2 ? points[i + 1] : points[i] + (points[i] - points[i - 1]).WithY(0) )); } path.Draw(canvas); } foreach (var p in points) { if (p.X >= -halfPoint.Width && p.X <= rect.Width + halfPoint.Width) { canvas.FillEllipse(p - halfPoint, pointSize, Colors.Black); canvas.FillEllipse(p - halfPoint * 4 / 5, pointSize * 4 / 5, Colors.White); } } /* canvas.DrawText(Math.Round(data.Value * 5 + 1, 1).ToString("F1"), * rect.Center, new NFont(), Colors.Black); */ } }; View.SizeChanged += (sender, e) => dataView.Invalidate(); dateLabel.SetBinding <GraphCell, DateTime, string>(Label.TextProperty, cell => cell.Data.Day, dt => dt.ToString("ddd\ndd/MM")); dateLabel.SizeChanged += (sender, e) => dataView.Invalidate(); }
public GraphPage(Coach coach, Monitor monitor, string name, string explanation, Action <DayFragment> onTap = null) { this.coach = coach; Title = name; list = new GraphList() { HorizontalOptions = LayoutOptions.CenterAndExpand, BackgroundColor = Color.Transparent }; list.ItemTapped += (sender, e) => onTap?.Invoke(e.Item as DayFragment); yearLabel = new Label { HorizontalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.EndAndExpand, Style = StyleKit.AutoDarkLabelStyles.Body, BindingContext = list }; explanationLabel = new Label { Text = explanation, HorizontalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.StartAndExpand, Style = StyleKit.AutoDarkLabelStyles.Caption }; Content = new ScrollView { Content = container = new AbsoluteLayout { Children = { (layout = new StackLayout { Padding = StyleKit.AutoPaddingLight, Spacing = StyleKit.AutoSpacing.Small, Children = { yearLabel, (listContainer = new NControlView { Content = new StackLayout { //BackgroundColor = MainApp.RandomColor(), Orientation = StackOrientation.Horizontal, VerticalOptions = LayoutOptions.Center, Padding = new Thickness(imageSize + 2, 0, 0, 0), Children = { /* (axis = new StackLayout { * Orientation = StackOrientation.Vertical, * Children = { * new Image { * Source = ImageSource.FromFile("face-smile.png"), * VerticalOptions = LayoutOptions.StartAndExpand * }, * new Image { * Source = ImageSource.FromFile("face-sad.png") * } * } * }), */ list } }, DrawingFunction = (canvas, rect) => { var left = imageSize; var top = listHeightShrunkAfterTranslation; var bottom = rect.Height - listHeightShrunkAfterTranslation - GraphCell.SpaceUnderGraph - 5; var right = rect.Width; canvas.DrawLine(left, top, left, bottom, Colors.Black, 2.0); canvas.DrawLine(left, bottom, right, bottom, Colors.Black, 2.0); if (images != null) { var padding = imageSize * 0.2; //TODO: Find solution to images missing canvas.DrawImage(images[0], 0, top, imageSize - padding,imageSize - padding); canvas.DrawImage(images[1], 0, bottom - imageSize + padding, imageSize - padding,imageSize - padding); } } }), explanationLabel } }) } } }; listContainer.Invalidate(); AbsoluteLayout.SetLayoutFlags(layout, AbsoluteLayoutFlags.WidthProportional | AbsoluteLayoutFlags.YProportional); AbsoluteLayout.SetLayoutBounds(layout, new Rectangle(0, 0.5, 1, AbsoluteLayout.AutoSize)); SizeChanged += (sender, e) => SetListSize(); SetListSize(); list.ItemsSource = new DayFragmentCollection(monitor.GetEvents()); yearLabel.SetBinding(Label.TextProperty, (GraphList gl) => gl.MedianDay, (DateTime day) => day.ToString("MMMM yyy")); GetImages(); }
public GradientButton() { HeightRequest = 44; WidthRequest = 100; _label = new Label { Text = Text, TextColor = TextColor, FontSize = 17, BackgroundColor = Color.Transparent, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }; _background = new NControlView { DrawingFunction = (canvas, rect) => { var brush = new LinearGradientBrush( Point.Zero, Point.OneX, StartColor.ToNColor(), EndColor.ToNColor()); var curveSize = BorderRadius; var width = rect.Width; var height = rect.Height; canvas.DrawPath(new PathOp[] { new MoveTo(curveSize, 0), // Top Right corner new LineTo(width - curveSize, 0), new CurveTo( new Point(width - curveSize, 0), new Point(width, 0), new Point(width, curveSize) ), new LineTo(width, height - curveSize), // Bottom right corner new CurveTo( new Point(width, height - curveSize), new Point(width, height), new Point(width - curveSize, height) ), new LineTo(curveSize, height), // Bottom left corner new CurveTo( new Point(curveSize, height), new Point(0, height), new Point(0, height - curveSize) ), new LineTo(0, curveSize), new CurveTo( new Point(0, curveSize), new Point(0, 0), new Point(curveSize, 0) ), new ClosePath() }, null, brush); } }; Content = new Grid { Children = { _background, _label } }; }
/// <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> /// Implement to create the layout on the page /// </summary> /// <returns>The layout.</returns> protected override View CreateContents() { _topBackgroundView = new NControlView { DrawingFunction = (canvas, rect) => canvas.FillRectangle(rect, new SolidBrush(new NGraphics.Color("#3498DB"))) }; _bottomBackgroundView = new NControlView { DrawingFunction = (canvas, rect) => canvas.FillRectangle(rect, new SolidBrush(new NGraphics.Color("#3498DB"))) }; var grid = new Grid(); grid.Children.Add(new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.CenterAndExpand, Padding = 11, Children = { new CircularButtonControl { FAIcon = FontAwesomeLabel.FAPlay }, new CircularButtonControl { FAIcon = FontAwesomeLabel.FAPlus }, new CircularButtonControl { FAIcon = FontAwesomeLabel.FATerminal }, new Button { Text = "Hello" }, } }, 0, 0); var buttonOverlay = new NControlView { DrawingFunction = (canvas, rect) => { rect.Inflate(-10, -10); canvas.DrawRectangle(rect, Pens.Blue, null); }, }; buttonOverlay.InputTransparent = true; grid.Children.Add(buttonOverlay, 0, 0); _bottomBar = new NControlView { BackgroundColor = Xamarin.Forms.Color.FromHex("#EEEEEE"), DrawingFunction = (ICanvas canvas, Rect rect) => canvas.DrawLine(0, 0, rect.Width, 0, NGraphics.Colors.Gray, 0.5) , Content = grid }; // Navigation bar _navigationBar = new NavigationBarEx { Title = Strings.AppName }; // Progress controll _progress = new ProgressControl(); // Map _mapContainer = new RelativeLayout(); // Layout var layout = new RelativeLayout(); layout.Children.Add(_mapContainer, () => layout.Bounds); layout.Children.Add(_topBackgroundView, () => new Xamarin.Forms.Rectangle(0, 0, layout.Width, 1 + (layout.Height / 2))); layout.Children.Add(_bottomBackgroundView, () => new Xamarin.Forms.Rectangle(0, layout.Height / 2, layout.Width, layout.Height / 2)); layout.Children.Add(_bottomBar, () => new Xamarin.Forms.Rectangle(0, layout.Height, layout.Width, 65)); layout.Children.Add(_navigationBar, () => new Xamarin.Forms.Rectangle(0, -80, layout.Width, 80)); layout.Children.Add(_progress, () => new Xamarin.Forms.Rectangle((layout.Width / 2) - (25), (layout.Height / 2) - 25, 50, 50)); return(layout); }
/// <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; }