| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- namespace PRS.Mobile
- {
-
- public class DigitalFormHeader : MobileCard, IDigitalFormControl<DFLayoutHeader>
- {
- private readonly Image _image;
- private readonly Label _label;
-
- private DFLayoutHeader _definition;
- public DFLayoutHeader Definition
- {
- get => _definition;
- set
- {
- _definition = value;
- Initialize(value ?? new DFLayoutHeader());
- }
- }
- private bool _collapsed;
- public bool Collapsed
- {
- get => _collapsed;
- set
- {
- _collapsed = value;
- _image.Source = value
- ? ImageSource.FromFile("arrow_white_up")
- : ImageSource.FromFile("arrow_white_down");
- }
- }
- public event EventHandler CollapsedChanged;
-
- public DigitalFormHeader()
- {
- HeightRequest = 40;
- Padding = 5;
- BorderColor = Color.Gray;
- BackgroundColor = Color.Silver;
- Grid grid = new Grid()
- {
- ColumnSpacing = 0,
- RowSpacing = 0
- };
- grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto});
- grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star});
- grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto});
- grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Star });
- _image = new Image()
- {
- HeightRequest = 20,
- WidthRequest = 20,
- VerticalOptions = LayoutOptions.Center,
- HorizontalOptions = LayoutOptions.Center
- };
- _image.GestureRecognizers.Add(new TapGestureRecognizer() { Command = new Command(OnTap)});
- grid.Children.Add(_image);
- _label = new Label()
- {
- Margin = new Thickness(5,0,5,0),
- VerticalOptions = LayoutOptions.Fill,
- VerticalTextAlignment = TextAlignment.Center,
- HorizontalOptions = LayoutOptions.Fill,
- };
- _label.GestureRecognizers.Add(new TapGestureRecognizer() { Command = new Command(OnTap)});
- _label.SetValue(Grid.ColumnProperty,1);
- grid.Children.Add(_label);
- Content = grid;
- }
- private void OnTap()
- {
- Collapsed = !Collapsed;
- CollapsedChanged?.Invoke(this, EventArgs.Empty);
- }
-
- private void Initialize(DFLayoutHeader definition)
- {
- Collapsed = definition.Collapsed;
-
- _image.SetValue(Grid.ColumnProperty, definition.Alignment == DFLayoutHeaderAlignment.Left ? 0 : 2);
-
- _image.Source = definition.Collapsed
- ? ImageSource.FromFile("arrow_white_up")
- : ImageSource.FromFile("arrow_white_down");
- _label.Text = definition.Header?.Trim();
-
- _label.LineBreakMode = definition.Style.TextWrapping ? LineBreakMode.WordWrap : LineBreakMode.NoWrap;
-
- _label.BackgroundColor = definition.Style.BackgroundColour.IsEmpty ? Color.Transparent : definition.Style.BackgroundColour;
-
- _label.FontAttributes = definition.Style.IsBold ? FontAttributes.Bold
- : definition.Style.IsItalic ? FontAttributes.Italic
- : FontAttributes.None;
-
- _label.TextDecorations = definition.Style.Underline == UnderlineType.Single || definition.Style.Underline == UnderlineType.Double ?
- TextDecorations.Underline : TextDecorations.None;
-
- _label.FontSize = definition.Style.FontSize > 5 && definition.Style.FontSize < 37 ? definition.Style.FontSize
- : Device.GetNamedSize(NamedSize.Small, _label);
-
- _label.TextColor = definition.Style.ForegroundColour.IsEmpty ? Color.Black : definition.Style.ForegroundColour;
- _label.HorizontalTextAlignment = definition.Style.HorizontalTextAlignment == DFLayoutAlignment.Start
- ? TextAlignment.Start
- : definition.Style.HorizontalTextAlignment == DFLayoutAlignment.Middle
- ? TextAlignment.Center
- : TextAlignment.End;
-
- _label.VerticalTextAlignment = definition.Style.VerticalTextAlignment == DFLayoutAlignment.Start
- ? TextAlignment.Start
- : definition.Style.HorizontalTextAlignment == DFLayoutAlignment.Middle
- ? TextAlignment.Center
- : TextAlignment.End;
- }
-
- }
- }
|