protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (Control == null) { return; } if (Element != null) { _dowButton = (DayOfWeekButton)Element; } if (Control.Width > Control.Height) { Control.SetHeight(Control.Width); } else { Control.SetWidth(Control.Height); } _dowButton.Clicked += Element_Clicked; Control.StateListAnimator = null; Control.SetPaddingRelative(0, 0, 0, 0); Control.TextSize = 20; Control.Background = ResourcesCompat.GetDrawable(Resources, Resource.Drawable.circle_background, null); SetPadding(0, 0, 0, 0); ButtonDeselected(); Control.Elevation = 0; }
/// <summary> /// Called when [element changed]. /// </summary> /// <param name="e">The e.</param> protected override void OnElementChanged(ElementChangedEventArgs <Checkbox> e) { base.OnElementChanged(e); if (this.Control == null) { var checkBox = new Android.Widget.CheckBox(this.Context); if (Element.WidthRequest >= 0) { checkBox.SetWidth((int)Element.WidthRequest); checkBox.SetHeight((int)Element.WidthRequest); } checkBox.CheckedChange += CheckBoxCheckedChange; SetNativeControl(checkBox); } Control.Text = e.NewElement.Text; Control.SetSingleLine(false); if (e.NewElement != null) { if (e.NewElement.WidthRequest >= 0) { Control.SetHeight((int)e.NewElement.WidthRequest); Control.SetWidth((int)e.NewElement.WidthRequest); } Control.Checked = e.NewElement.Checked; Control.Enabled = e.NewElement.IsEnabled; } }
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { base.OnMeasure(widthMeasureSpec, heightMeasureSpec); currentWidth = MeasureSpec.GetSize(widthMeasureSpec); if (currentWidth != Control.Width) { Control.SetWidth(currentWidth); } }
protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs <DatePicker> e) { base.OnElementChanged(e); if (Control != null) { Control.SetBackgroundColor(Android.Graphics.Color.Transparent); Control.Gravity = GravityFlags.CenterVertical; Control.SetTextColor(Android.Graphics.Color.Black); Control.SetWidth(300); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control != null) { Control.SetBackgroundColor(global::Android.Graphics.Color.Transparent); Control.SetTextSize(global::Android.Util.ComplexUnitType.Dip, 20); Control.SetHighlightColor(global::Android.Graphics.Color.ParseColor("#FFE88F")); // amber color Control.SetWidth(230); Control.SetHeight(50); Control.SetTextColor(global::Android.Graphics.Color.White); } }
protected override void OnInitialize() { m_generator = new UFormsCodeGenerator(); title = "Control Designer"; m_menu = new DesignerTopMenu(); m_menu.SetSize(100.0f, CONTROL_DISPLAY_HEIGHT, Control.MetricsUnits.Percentage, Control.MetricsUnits.Pixel); m_menu.MenuOptionSelected += HandleMenuOptionSelected; AddChild(m_menu); m_inspectorFields = new Dictionary <object, PropertyInfo>(); m_hierarchyItems = new Dictionary <Control, HierarchyItem>(); m_inspector = new Control(); m_inspector.SetPosition(position.width - INSPECTOR_WIDTH, CONTROL_DISPLAY_HEIGHT + TOP_MENU_SPACING); m_inspector.SetWidth(INSPECTOR_WIDTH); m_inspector.SetMargin(0.0f, 0.0f, SIDE_MARGIN, 0.0f); m_inspector.AddDecorator(new StackContent(StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow)); AddChild(m_inspector); m_hierarchy = new Control(); m_hierarchy.SetPosition(0.0f, CONTROL_DISPLAY_HEIGHT + TOP_MENU_SPACING); m_hierarchy.SetWidth(HIERARCHY_WIDTH); m_hierarchy.SetMargin(SIDE_MARGIN, 0.0f, 0.0f, 0.0f); m_hierarchy.AddDecorator(new StackContent(StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow)); AddChild(m_hierarchy); m_workarea = new Control(); m_workarea.SetPosition(m_viewportOffset); m_workarea.AddDecorator(new ClipContent()); AddChild(m_workarea); m_resizeHandle = new Control(); m_resizeHandle.SetSize(RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE); m_resizeHandle.AddDecorator(new BackgroundColor(Color.blue)); m_resizeHandle.Visibility = Control.VisibilityMode.Hidden; AddChild(m_resizeHandle); SetSelectedControl(null); SetInspectorTarget(null); ShowToolbox(); }
public FoldoutList( string title, float indentation, bool unfolded ) : base() { m_indentationAmount = indentation; m_foldout = new Foldout( title, unfolded ); m_foldout.SetWidth( 100.0f, MetricsUnits.Percentage ); m_content = new Control(); m_content.SetWidth( 100.0f, MetricsUnits.Percentage ); m_content.AddDecorator( new StackContent( StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow ) ); m_content.AddDecorator( new FitContent( false, true, false, true ) ); AddChild( m_foldout ); AddChild( m_content ); AddDecorator( new StackContent( StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow ) ); AddDecorator( new FitContent( false, true, false, true ) ); m_foldout.ValueChange += FoldoutValueChange; SetFoldState( unfolded ); }
public FoldoutList(string title, float indentation, bool unfolded) : base() { m_indentationAmount = indentation; m_foldout = new Foldout(title, unfolded); m_foldout.SetWidth(100.0f, MetricsUnits.Percentage); m_content = new Control(); m_content.SetWidth(100.0f, MetricsUnits.Percentage); m_content.AddDecorator(new StackContent(StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow)); m_content.AddDecorator(new FitContent(false, true, false, true)); AddChild(m_foldout); AddChild(m_content); AddDecorator(new StackContent(StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow)); AddDecorator(new FitContent(false, true, false, true)); m_foldout.ValueChange += FoldoutValueChange; SetFoldState(unfolded); }
/// <summary> /// Gets the size of the desired. /// </summary> /// <returns>The desired size.</returns> /// <param name="widthConstraint">Width constraint.</param> /// <param name="heightConstraint">Height constraint.</param> public override SizeRequest GetDesiredSize(int widthConstraint, int heightConstraint) { if (_currentControlState.IsNullOrEmpty || Control == null) { return(new SizeRequest(Xamarin.Forms.Size.Zero)); } _currentControlState.AvailWidth = MeasureSpec.GetSize(widthConstraint); if (MeasureSpec.GetMode(widthConstraint) == Android.Views.MeasureSpecMode.Unspecified) { _currentControlState.AvailWidth = int.MaxValue / 2; } _currentControlState.AvailHeight = MeasureSpec.GetSize(heightConstraint); if (MeasureSpec.GetMode(heightConstraint) == Android.Views.MeasureSpecMode.Unspecified) { _currentControlState.AvailHeight = int.MaxValue / 2; } if (_currentControlState.AvailWidth <= 0 || _currentControlState.AvailHeight <= 0) { return(new SizeRequest(Xamarin.Forms.Size.Zero)); } if (_currentControlState == _lastControlState && _lastSizeRequest.HasValue) { return(_lastSizeRequest.Value); } ICharSequence text = _currentControlState.JavaText; var tmpFontSize = BoundTextSize(Element.FontSize); Control.TextSize = tmpFontSize; Control.SetSingleLine(false); Control.SetMaxLines(int.MaxValue / 2); Control.SetIncludeFontPadding(false); Control.Ellipsize = null; int tmpHt = -1; int tmpWd = -1; var fontMetrics = Control.Paint.GetFontMetrics(); var fontLineHeight = fontMetrics.Descent - fontMetrics.Ascent; var fontLeading = System.Math.Abs(fontMetrics.Bottom - fontMetrics.Descent); if (DebugCondition) { System.Diagnostics.Debug.WriteLine(""); } if (_currentControlState.Lines == 0) { if (_currentControlState.AvailHeight < int.MaxValue / 3) { tmpFontSize = F9PTextView.ZeroLinesFit(_currentControlState.JavaText, new TextPaint(Control.Paint), ModelMinFontSize, tmpFontSize, _currentControlState.AvailWidth, _currentControlState.AvailHeight); } } else { if (_currentControlState.AutoFit == AutoFit.Lines) { if (_currentControlState.AvailHeight > int.MaxValue / 3) { tmpHt = (int)System.Math.Round(_currentControlState.Lines * fontLineHeight + (_currentControlState.Lines - 1) * fontLeading); } else { var fontPointSize = tmpFontSize; var lineHeightRatio = fontLineHeight / fontPointSize; var leadingRatio = fontLeading / fontPointSize; tmpFontSize = ((_currentControlState.AvailHeight / (_currentControlState.Lines + leadingRatio * (_currentControlState.Lines - 1))) / lineHeightRatio - 0.1f); } } else if (_currentControlState.AutoFit == AutoFit.Width) { tmpFontSize = F9PTextView.WidthFit(_currentControlState.JavaText, new TextPaint(Control.Paint), _currentControlState.Lines, ModelMinFontSize, tmpFontSize, _currentControlState.AvailWidth, _currentControlState.AvailHeight); } } /* * if (_currentControlState.Lines == 0) // && _currentControlState.AutoFit != AutoFit.None) * tmpFontSize = F9PTextView.ZeroLinesFit(_currentControlState.JavaText, new TextPaint(Control.Paint), ModelMinFontSize, tmpFontSize, _currentControlState.AvailWidth, _currentControlState.AvailHeight); * else if (_currentControlState.AutoFit == AutoFit.Lines) * { * * if (_currentControlState.AvailHeight > int.MaxValue / 3) * tmpHt = (int)System.Math.Round(_currentControlState.Lines * fontLineHeight + (_currentControlState.Lines - 1) * fontLeading); * else * { * var fontPointSize = tmpFontSize; * var lineHeightRatio = fontLineHeight / fontPointSize; * var leadingRatio = fontLeading / fontPointSize; * tmpFontSize = ((_currentControlState.AvailHeight / (_currentControlState.Lines + leadingRatio * (_currentControlState.Lines - 1))) / lineHeightRatio - 0.1f); * } * } * else if (_currentControlState.AutoFit == AutoFit.Width) * tmpFontSize = F9PTextView.WidthFit(_currentControlState.JavaText, new TextPaint(Control.Paint), _currentControlState.Lines, ModelMinFontSize, tmpFontSize, _currentControlState.AvailWidth, _currentControlState.AvailHeight); */ tmpFontSize = BoundTextSize(tmpFontSize); // this is the optimal font size. Let it be known! if (tmpFontSize != Element.FittedFontSize) { //Device.StartTimer(TimeSpan.FromMilliseconds(50), () => //{ if (Element != null && Control != null) // multipicker test was getting here with Element and Control both null { if (tmpFontSize == Element.FontSize || (Element.FontSize == -1 && tmpFontSize == F9PTextView.DefaultTextSize)) { Element.FittedFontSize = -1; } else { Element.FittedFontSize = tmpFontSize; } } // return false; //}); } var syncFontSize = (float)((ILabel)Element).SynchronizedFontSize; if (syncFontSize >= 0 && tmpFontSize != syncFontSize) { tmpFontSize = syncFontSize; } Control.TextSize = tmpFontSize; var layout = new StaticLayout(_currentControlState.JavaText, new TextPaint(Control.Paint), _currentControlState.AvailWidth, Android.Text.Layout.Alignment.AlignNormal, 1.0f, 0.0f, true); int lines = _currentControlState.Lines; if (lines == 0 && _currentControlState.AutoFit == AutoFit.None) { for (int i = 0; i < layout.LineCount; i++) { if (layout.GetLineBottom(i) <= _currentControlState.AvailHeight - layout.TopPadding - layout.BottomPadding) { lines++; } else { break; } } } if (layout.Height > _currentControlState.AvailHeight || (lines > 0 && layout.LineCount > lines)) { if (_currentControlState.Lines == 1) { Control.SetSingleLine(true); Control.SetMaxLines(1); Control.Ellipsize = _currentControlState.LineBreakMode.ToEllipsize(); } else { layout = F9PTextView.Truncate(_currentControlState.Text, Element.F9PFormattedString, new TextPaint(Control.Paint), _currentControlState.AvailWidth, _currentControlState.AvailHeight, Element.AutoFit, Element.LineBreakMode, ref lines, ref text); } } lines = lines > 0 ? System.Math.Min(lines, layout.LineCount) : layout.LineCount; for (int i = 0; i < lines; i++) { tmpHt = layout.GetLineBottom(i); var width = layout.GetLineWidth(i); //System.Diagnostics.Debug.WriteLine("\t\tright=["+right+"]"); if (width > tmpWd) { tmpWd = (int)System.Math.Ceiling(width); } } if (_currentControlState.AutoFit == AutoFit.None && _currentControlState.Lines > 0) { Control.SetMaxLines(_currentControlState.Lines); } //System.Diagnostics.Debug.WriteLine("\tLabelRenderer.GetDesiredSize\ttmp.size=[" + tmpWd + ", " + tmpHt + "]"); if (Element.IsDynamicallySized && _currentControlState.Lines > 0 && _currentControlState.AutoFit == AutoFit.Lines) { fontMetrics = Control.Paint.GetFontMetrics(); fontLineHeight = fontMetrics.Descent - fontMetrics.Ascent; fontLeading = System.Math.Abs(fontMetrics.Bottom - fontMetrics.Descent); tmpHt = (int)(fontLineHeight * _currentControlState.Lines + fontLeading * (_currentControlState.Lines - 1)); } Control.Gravity = Element.HorizontalTextAlignment.ToHorizontalGravityFlags() | Element.VerticalTextAlignment.ToVerticalGravityFlags(); if (Element.Text != null) { Control.Text = text.ToString(); } else { Control.TextFormatted = text; } _lastSizeRequest = new SizeRequest(new Xamarin.Forms.Size(tmpWd, tmpHt), new Xamarin.Forms.Size(10, tmpHt)); if (showDebugMsg) { Control.SetWidth((int)_lastSizeRequest.Value.Request.Width); Control.SetHeight((int)_lastSizeRequest.Value.Request.Height); System.Diagnostics.Debug.WriteLine("\t[" + elementText + "] LabelRenderer.GetDesiredSize(" + (_currentControlState.AvailWidth > int.MaxValue / 3 ? "infinity" : _currentControlState.AvailWidth.ToString()) + "," + (_currentControlState.AvailHeight > int.MaxValue / 3 ? "infinity" : _currentControlState.AvailHeight.ToString()) + ") exit (" + _lastSizeRequest.Value + ")"); System.Diagnostics.Debug.WriteLine("\t\tControl.Visibility=[" + Control.Visibility + "]"); System.Diagnostics.Debug.WriteLine("\t\tControl.TextFormatted=[" + Control.TextFormatted + "]"); System.Diagnostics.Debug.WriteLine("\t\tControl.TextSize=[" + Control.TextSize + "]"); //System.Diagnostics.Debug.WriteLine("\t\tControl.ClipBounds=["+Control.ClipBounds.Width()+","+Control.ClipBounds.Height()+"]"); System.Diagnostics.Debug.WriteLine("\t\tControl.Width[" + Control.Width + "] .Height=[" + Control.Height + "]"); System.Diagnostics.Debug.WriteLine("\t\tControl.GetX[" + Control.GetX() + "] .GetY[" + Control.GetY() + "]"); System.Diagnostics.Debug.WriteLine("\t\tControl.Alpha[" + Control.Alpha + "]"); System.Diagnostics.Debug.WriteLine("\t\tControl.Background[" + Control.Background + "]"); //System.Diagnostics.Debug.WriteLine("\t\tControl.Elevation["+Control.Elevation+"]"); System.Diagnostics.Debug.WriteLine("\t\tControl.Enabled[" + Control.Enabled + "]"); System.Diagnostics.Debug.WriteLine("\t\tControl.Error[" + Control.Error + "]"); System.Diagnostics.Debug.WriteLine("\t\tControl.IsOpaque[" + Control.IsOpaque + "]"); System.Diagnostics.Debug.WriteLine("\t\tControl.IsShown[" + Control.IsShown + "]"); //Control.BringToFront(); System.Diagnostics.Debug.WriteLine("\t\t"); } if (Element.LineBreakMode == LineBreakMode.NoWrap) { Control.SetSingleLine(true); } _lastControlState = new ControlState(_currentControlState); return(_lastSizeRequest.Value); }
public void AddItem( Control item ) { item.SetMargin( m_indentationAmount, 0.0f, 0.0f, 0.0f, MetricsUnits.Pixel ); item.SetWidth( 100.0f, MetricsUnits.Percentage ); m_content.AddChild( item ); }
protected override void OnInitialize() { m_generator = new UFormsCodeGenerator(); title = "Control Designer"; m_menu = new DesignerTopMenu(); m_menu.SetSize( 100.0f, CONTROL_DISPLAY_HEIGHT, Control.MetricsUnits.Percentage, Control.MetricsUnits.Pixel ); m_menu.MenuOptionSelected += HandleMenuOptionSelected; AddChild( m_menu ); m_inspectorFields = new Dictionary<object, PropertyInfo>(); m_hierarchyItems = new Dictionary<Control, HierarchyItem>(); m_inspector = new Control(); m_inspector.SetPosition( position.width - INSPECTOR_WIDTH , CONTROL_DISPLAY_HEIGHT + TOP_MENU_SPACING ); m_inspector.SetWidth( INSPECTOR_WIDTH ); m_inspector.SetMargin( 0.0f, 0.0f, SIDE_MARGIN, 0.0f ); m_inspector.AddDecorator( new StackContent( StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow ) ); AddChild( m_inspector ); m_hierarchy = new Control(); m_hierarchy.SetPosition( 0.0f, CONTROL_DISPLAY_HEIGHT + TOP_MENU_SPACING ); m_hierarchy.SetWidth( HIERARCHY_WIDTH ); m_hierarchy.SetMargin( SIDE_MARGIN, 0.0f, 0.0f, 0.0f ); m_hierarchy.AddDecorator( new StackContent( StackContent.StackMode.Vertical, StackContent.OverflowMode.Flow ) ); AddChild( m_hierarchy ); m_workarea = new Control(); m_workarea.SetPosition( m_viewportOffset ); m_workarea.AddDecorator( new ClipContent() ); AddChild( m_workarea ); m_resizeHandle = new Control(); m_resizeHandle.SetSize( RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE ); m_resizeHandle.AddDecorator( new BackgroundColor( Color.blue ) ); m_resizeHandle.Visibility = Control.VisibilityMode.Hidden; AddChild( m_resizeHandle ); SetSelectedControl( null ); SetInspectorTarget( null ); ShowToolbox(); }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (e.OldElement != null || e.NewElement == null) { return; } var buttonControl = (RoundedButton)Element; gradientDrawable = new StateListDrawable(); SetCorners(); Control.Focusable = false; buttonControl.PropertyChanged += (s, ev) => { if (Control == null || Element == null) { return; } var element = (RoundedButton)s; switch (ev.PropertyName) { case "IsEnabled": Control.SetTextColor(element.TextColor.ToAndroid()); // for samsung s4 and note5 break; case "Text": Control.Text = element.Text; var width = Control.Width; Control.SetWidth(width); break; case "HoverColor": SetHoverColor(); Control.Background = gradientDrawable; break; case "PressedColor": SetPressedColor(); Control.Background = gradientDrawable; break; case "GradientColor": UpdateStateDrawable(); break; case "DisableColor": SetDisabledColor(); Control.Background = gradientDrawable; break; case "BorderColor": UpdateStateDrawable(); break; //case "Width": // SetImages(buttonControl); // break; case "DisabledTextColor": SetDisabledTextColor(); break; } }; //SetTypeface(buttonControl); //SetBackground(buttonControl); //SetImages(buttonControl); //SetPadding(buttonControl); //SetTitlePadding(buttonControl); //SetTextAlignment(buttonControl); currentWidth = Control.Width; if (buttonControl.WidthRequest > 0) { Control.SetWidth(BaseUIHelper.ConvertDPToPixels(buttonControl.WidthRequest)); } if (buttonControl.HeightRequest > 0) { Control.SetHeight(BaseUIHelper.ConvertDPToPixels(buttonControl.HeightRequest)); } SetPressedColor(); SetHoverColor(); SetDisabledColor(); SetGradientColor(); SetDisabledTextColor(); SetTextAlignment(); Control.Background = gradientDrawable; var thisButton = Control as Android.Widget.Button; thisButton.Touch += async(object sender, TouchEventArgs args) => { if (args.Event.Action == MotionEventActions.Down) { await buttonControl.ScaleTo(0.9, 100); } else if (args.Event.Action == MotionEventActions.Up) { await buttonControl.ScaleTo(1, 100); Control.CallOnClick(); } }; this.SetWillNotDraw(false); }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (e.OldElement != null || e.NewElement == null) { return; } var buttonControl = (MvvmAspire.Controls.Button)Element; buttonControl.PropertyChanged += (s, ev) => { if (Control == null) { return; } var element = (MvvmAspire.Controls.Button)s; switch (ev.PropertyName) { case "Text": Control.Text = element.Text; Control.SetWidth(currentWidth); break; case "Renderer": if (element.Height > 0 && element.Width > 0) { SetImages(element); } break; case "Font": SetTypeface(element); break; case "BackgroundColor": CreateShapeDrawable(buttonControl); break; case "BackgroundImage": SetBackground(element); SetPadding(element); break; case "ImageLeft": case "ImageRight": case "ImageTop": case "ImageBottom": SetImages(element); SetPadding(element); break; case "Padding": SetPadding(element); SetTextAlignment(buttonControl); break; case "AccesibilitySetName": SetAccesibilitySetName(buttonControl); break; case "TitlePadding": SetTitlePadding(element); break; case "XAlign": case "YAlign": SetTextAlignment(buttonControl); break; //case "BorderColor": // UpdateBorderColor(); // break; case "Width": SetImages(buttonControl); break; case "IsEnabled": SetDisabledTextColor(); break; } }; SetTypeface(buttonControl); SetBackground(buttonControl); SetPadding(buttonControl); SetTitlePadding(buttonControl); SetTextAlignment(buttonControl); SetAccesibilitySetName(buttonControl); if (buttonControl.RefitTextEnabled) { var mTestPaint = new Paint(); mTestPaint.Set(this.Control.Paint); base.Control.Text = base.Element.Text; //minSize = convertFromDp(Resources.GetDimension(UIHelper.GetDimensionResource("text_size"))); //This line causes crash in balut project base.Control.SetSingleLine(false); base.Control.SetMaxLines(2); base.Control.Ellipsize = TextUtils.TruncateAt.End; base.Control.SetPadding(0, 0, 0, 0); base.Control.CompoundDrawablePadding = 0; base.Control.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); //if (base.Control.LineCount > 1 && (mTestPaint.MeasureText(base.Control.Text) * 2) > base.Control.MeasuredWidth) // base.Control.SetTextSize(ComplexUnitType.Px, minSize); } base.Control.SetAllCaps(false); CreateShapeDrawable(buttonControl); this.Control.LongClick += Control_LongClick; SetDisabledTextColor(); this.SetWillNotDraw(false); }
public override void ChildDrawableStateChanged(Android.Views.View child) { base.ChildDrawableStateChanged(child); Control.Text = Control.Text; Control.SetWidth(currentWidth); }
public void AddItem(Control item) { item.SetMargin(m_indentationAmount, 0.0f, 0.0f, 0.0f, MetricsUnits.Pixel); item.SetWidth(100.0f, MetricsUnits.Percentage); m_content.AddChild(item); }