Ejemplo n.º 1
0
        public static void ApplyTheme(this UIButton button, ButtonTheme theme)
        {
            if (theme.BackgroundColor != null)
            {
                var defaultBackground = theme.BackgroundColor.CreateImageFromColor();
                button.SetBackgroundImage(defaultBackground, UIControlState.Normal);
            }

            if (theme.TextColor != null)
            {
                button.SetTitleColor(theme.TextColor, UIControlState.Normal);
            }

            if (theme.Font != null)
            {
                button.Font = theme.Font;
            }

            if (theme.DisabledBackgroundColor != null)
            {
                var disabledBackground = theme.DisabledBackgroundColor.CreateImageFromColor();
                button.SetBackgroundImage(disabledBackground, UIControlState.Disabled);
            }

            button.Layer.CornerRadius = theme.CornerRadius;
            button.ClipsToBounds      = true;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Applies a theme to the specified button.
 /// </summary>
 /// <param name="button">A button to apply the theme to.</param>
 /// <param name="theme">The theme to apply to the button.</param>
 /// <param name="fontSize">The size of the font for the button text.</param>
 public static void ApplyTheme(this UIButton button, ButtonTheme theme, int fontSize)
 {
     button.ApplyTheme(
         theme,
         null,
         default(UIEdgeInsets),
         false,
         fontSize);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Applies a theme to the specified button.
        /// </summary>
        /// <param name="button">A button to apply the theme to.</param>
        /// <param name="theme">The theme to apply to the button.</param>
        /// <param name="image">An image for the button.</param>
        /// <param name="imageInsets">Optional inset or outset margins for the rectangle around the button’s image.</param>
        /// <param name="imageLeft">Optional flag to identify if the image for the button should be shown to the left of the text, otherwise to the right; the default is true.</param>
        /// <param name="fontSize">The size of the font for the button text.</param>
        public static void ApplyTheme(
            this UIButton button,
            ButtonTheme theme,
            UIImage image,
            UIEdgeInsets imageInsets,
            bool imageLeft,
            int fontSize)
        {
            if (theme.BorderColor.Alpha > 0)
            {
                button.Layer.BorderColor =
                    button.Enabled
                    ? theme.BorderColor.ToCGColor()
                    : theme.DisabledColor.ToCGColor();

                button.Layer.BorderWidth = Constants.ButtonBorderWidth;

                button.Layer.CornerRadius = button.Frame.Height / 2;
            }

            if (image != null)
            {
                UIImage updatedImage = image;
                if (theme.ImageTintColor.Alpha > 0)
                {
                    if (updatedImage.RenderingMode != UIImageRenderingMode.AlwaysTemplate)
                    {
                        updatedImage = updatedImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                    }

                    button.TintColor = theme.ImageTintColor.ToUIColor();
                }

                button.SetImage(updatedImage, UIControlState.Normal);
                button.ImageEdgeInsets = imageInsets;

                if (!imageLeft)
                {
                    button.Transform            = CGAffineTransform.MakeScale(-1.0f, 1.0f);
                    button.TitleLabel.Transform = CGAffineTransform.MakeScale(-1.0f, 1.0f);
                    button.ImageView.Transform  = CGAffineTransform.MakeScale(-1.0f, 1.0f);
                }
            }

            button.BackgroundColor =
                button.Enabled || theme.BackgroundColor.Alpha == 0
                ? theme.BackgroundColor.ToUIColor()
                : theme.DisabledColor.ToUIColor();

            button.SetTitleColor(theme.FontColor.ToUIColor(), UIControlState.Normal);
            button.SetTitleColor(theme.DisabledColor.ToUIColor(), UIControlState.Disabled);

            button.Font = ViewThemeExtensions.GetFont(theme.FontName, fontSize);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Applies a theme to the specified button.
 /// </summary>
 /// <param name="button">A button to apply the theme to.</param>
 /// <param name="theme">The theme to apply to the button.</param>
 /// <param name="image">An image for the button.</param>
 /// <param name="imageInsets">Optional inset or outset margins for the rectangle around the button’s image.</param>
 /// <param name="imageLeft">Optional flag to identify if the image for the button should be shown to the left of the text, otherwise to the right; the default is true.</param>
 public static void ApplyTheme(
     this UIButton button,
     ButtonTheme theme,
     UIImage image,
     UIEdgeInsets imageInsets = default(UIEdgeInsets),
     bool imageLeft           = true)
 {
     button.ApplyTheme(
         theme,
         image,
         imageInsets,
         imageLeft,
         ViewFontSizes.StandardFontSize);
 }
Ejemplo n.º 5
0
        private ButtonTheme GetButtonTheme()
        {
            ButtonTheme theme               = new ButtonTheme();
            var         foreground          = Resources.Palette.Twine;
            var         foregroundHighlight = Resources.Palette.GoldenFizz;
            var         background          = Resources.Palette.Rope;

            theme.Normal        = new Cell(foreground, background);
            theme.Focused       = new Cell(background, foreground);
            theme.MouseOver     = new Cell(foregroundHighlight, foreground);
            theme.MouseClicking = new Cell(foregroundHighlight, background);

            return(theme);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="width">The startup width of the menu. Ideally set to the size of the parent to start out.</param>
        /// <param name="height">The startup height of the menu. Ideally set to the size of the parent to start out.</param>
        /// <param name="menuItems">An optional list of strings that will become the text displayed on a series of buttons.</param>
        public MenuConsole(int width, int height, List <MenuButtonMetadataItem> menuItems = null) : base(width, height)
        {
            if (_elements == null)
            {
                _elements = new List <MenuButtonMetadataItem>();
            }
            else
            {
                _elements = menuItems;
            }
            menuFade = GameState.DefaultFade;

            _buttonTheme          = new ButtonTheme();
            _buttonTheme.ShowEnds = false; // don't show the < > on the sides of buttons in this "menu" screen.
            _alignElementsLeft    = false;
        }
Ejemplo n.º 7
0
        private Template SelectTemplate(ButtonTheme theme)
        {
            switch (theme)
            {
            case ButtonTheme.Default:
                return(null);

            case ButtonTheme.Aero:
                return(new AeroTemplate());

            case ButtonTheme.Metro:
                return(new MetroTemplate());

            default:
                return(AutoSelectTemplate());
            }
        }
Ejemplo n.º 8
0
        protected void CreateButtonTheme( )
        {
            switch (ButtonStyle)
            {
            case ButtonStyles.Thinlines:
                ButtonTheme = new ButtonLinesTheme
                {
                    BottomRightLineColors = Appearance_ControlDisabled,
                    TopLeftLineColors     = Appearance_ControlFocused,
                    Normal    = new Cell(TextDark, (ControlBackLight * 1.3f).FillAlpha()),
                    Disabled  = Appearance_ControlDisabled,
                    MouseOver = new Cell(TextBright, (ControlBackLight * 1.6f).FillAlpha()),
                    Focused   = new Cell(TextDark, (ControlBackLight * 1.3f).FillAlpha()),
                    MouseDown = Appearance_ControlMouseDown,
                };
                break;

            case ButtonStyles.Normal:
                ButtonTheme = new ButtonTheme
                {
                    Normal    = new Cell(TextDark, (ControlBackLight * 1.3f).FillAlpha()),
                    Disabled  = Appearance_ControlDisabled,
                    MouseOver = new Cell(TextBright, (ControlBackLight * 1.6f).FillAlpha()),
                    Focused   = new Cell(TextDark, (ControlBackLight * 1.3f).FillAlpha()),
                    MouseDown = Appearance_ControlMouseDown,
                    ShowEnds  = false,
                };
                break;

            default:
                ButtonTheme = new ButtonTheme
                {
                    Normal    = new Cell(TextDark, (ControlBackLight * 1.3f).FillAlpha()),
                    Disabled  = Appearance_ControlDisabled,
                    MouseOver = new Cell(TextBright, (ControlBackLight * 1.6f).FillAlpha()),
                    Focused   = new Cell(TextDark, (ControlBackLight * 1.3f).FillAlpha()),
                    MouseDown = Appearance_ControlMouseDown,
                    ShowEnds  = true,
                };
                break;
            }
        }
Ejemplo n.º 9
0
        public override Widget build(BuildContext context)
        {
            ButtonThemeData buttonTheme = ButtonTheme.of(context).copyWith(
                shape: this._buttonShape
                );

            List <ComponentDemoTabData> demos = new List <ComponentDemoTabData> {
                new ComponentDemoTabData(
                    tabName: "RAISED",
                    description: _raisedText,
                    demoWidget: ButtonTheme.fromButtonThemeData(
                        data: buttonTheme,
                        child: this.buildRaisedButton()
                        ),
                    exampleCodeTag: _raisedCode,
                    documentationUrl: "https://docs.flutter.io/flutter/material/RaisedButton-class.html"
                    ),
                new ComponentDemoTabData(
                    tabName: "FLAT",
                    description: _flatText,
                    demoWidget: ButtonTheme.fromButtonThemeData(
                        data: buttonTheme,
                        child: this.buildFlatButton()
                        ),
                    exampleCodeTag: _flatCode,
                    documentationUrl: "https://docs.flutter.io/flutter/material/FlatButton-class.html"
                    ),
                new ComponentDemoTabData(
                    tabName: "OUTLINE",
                    description: _outlineText,
                    demoWidget: ButtonTheme.fromButtonThemeData(
                        data: buttonTheme,
                        child: this.buildOutlineButton()
                        ),
                    exampleCodeTag: _outlineCode,
                    documentationUrl: "https://docs.flutter.io/flutter/material/OutlineButton-class.html"
                    ),
                new ComponentDemoTabData(
                    tabName: "DROPDOWN",
                    description: _dropdownText,
                    demoWidget: this.buildDropdownButton(),
                    exampleCodeTag: _dropdownCode,
                    documentationUrl: "https://docs.flutter.io/flutter/material/DropdownButton-class.html"
                    ),
                new ComponentDemoTabData(
                    tabName: "ICON",
                    description: _iconText,
                    demoWidget: this.buildIconButton(),
                    exampleCodeTag: _iconCode,
                    documentationUrl: "https://docs.flutter.io/flutter/material/IconButton-class.html"
                    ),
                new ComponentDemoTabData(
                    tabName: "ACTION",
                    description: _actionText,
                    demoWidget: this.buildActionButton(),
                    exampleCodeTag: _actionCode,
                    documentationUrl: "https://docs.flutter.io/flutter/material/FloatingActionButton-class.html"
                    )
            };

            return(new TabbedComponentDemoScaffold(
                       title: "Buttons",
                       demos: demos,
                       actions: new List <Widget> {
                new IconButton(
                    icon: new Icon(Icons.sentiment_very_satisfied),
                    onPressed: () => {
                    this.setState(() => {
                        this._buttonShape = this._buttonShape == null ? new StadiumBorder() : null;
                    });
                }
                    )
            }
                       ));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Applies a theme to the specified button.
 /// </summary>
 /// <param name="button">A button to apply the theme to.</param>
 /// <param name="theme">The theme to apply to the button.</param>
 public static void ApplyTheme(this UIButton button, ButtonTheme theme)
 {
     button.ApplyTheme(theme, ViewFontSizes.StandardFontSize);
 }
Ejemplo n.º 11
0
        public TestHealthConsole(int width, int height, HealthProgressBar hpBar) : base(width, height)
        {
            // Just for testing.
            testEvents = new[] {
                new HealthBarTimelineEvent(0.5f, TimeSpan.FromSeconds(0.80)),
                new HealthBarTimelineEvent(0.15f, TimeSpan.FromSeconds(1.75)),
                new HealthBarTimelineEvent(0.17f, TimeSpan.FromSeconds(2.25)),
                new HealthBarTimelineEvent(0.30f, TimeSpan.FromSeconds(2.75)),
            };

            IncrementButtons = new List <Button>()
            {
                new Button(7, 3)
                {
                    Text = "+1%", Name = "PlusOnePercent"
                },
                new Button(8, 3)
                {
                    Text = "+10%", Name = "PlusTenPercent"
                },
                new Button(8, 3)
                {
                    Text = "+25%", Name = "PlusTwentyFivePercent"
                }
            };

            MinusButtons = new List <Button>()
            {
                new Button(7, 3)
                {
                    Text = "-1%", Name = "MinusOnePercent"
                },
                new Button(8, 3)
                {
                    Text = "-10%", Name = "MinusTenPercent"
                },
                new Button(8, 3)
                {
                    Text = "-25%", Name = "MinusTwentyFivePercent"
                }
            };

            List <Button>[] lsOfBtnListe = new[] { IncrementButtons, MinusButtons };
            List <Button>   currentBtnList;
            Button          currentButton;

            int   baseTopPadding        = 2;
            Point offset                = Point.Zero;
            int   biggestHeightForRow   = 0;
            int   lastLineBiggestHeight = 0;

            Add(dmgLabel = new Label(80)
            {
                Position = new Point(0, 0),
            });

            this.hpBar = hpBar;
            ClickAny  += (sender, e) => e.Item2.Progress = SadConsole.MathHelper.Clamp(e.Item2.Progress + e.Item1, 0.0f, 1.0f);

            buttonTheme = new ButtonLinesTheme();

            for (var i = 0; i < lsOfBtnListe.Length; i++)
            {
                currentBtnList      = lsOfBtnListe[i];
                biggestHeightForRow = 0;

                for (var j = 0; j < currentBtnList.Count; j++)
                {
                    currentButton = currentBtnList[j];

                    currentButton.Theme         = buttonTheme;
                    currentButton.TextAlignment = HorizontalAlignment.Center;

                    currentButton.Position = Cursor.Position;
                    Cursor.Position       += new Point(currentButton.Width, 0);

                    // I don't care about good UX tbh, so align rows based on biggest height in last row.
                    biggestHeightForRow = Math.Max(biggestHeightForRow, currentButton.Height);

                    // Bind click event.
                    currentButton.Click += CurrentButton_Click;

                    Add(currentButton);
                }

                Cursor.Position = new Point(0, Cursor.Position.Y + biggestHeightForRow);
            }
        }
Ejemplo n.º 12
0
        public override Widget build(BuildContext context)
        {
            ThemeData theme            = Theme.of(context);
            TextStyle titleStyle       = theme.textTheme.headline.copyWith(color: Colors.white);
            TextStyle descriptionStyle = theme.textTheme.subhead;

            return(new SafeArea(
                       top: false,
                       bottom: false,
                       child: new Container(
                           padding: EdgeInsets.all(8.0f),
                           height: height,
                           child: new Card(
                               shape: this.shape,
                               child: new Column(
                                   crossAxisAlignment: CrossAxisAlignment.start,
                                   children: new List <Widget> {
                new SizedBox(
                    height: 184.0f,
                    child: new Stack(
                        children: new List <Widget> {
                    Positioned.fill(
                        child: Image.asset(this.destination.assetName,
                                           fit: BoxFit.cover
                                           )
                        ),
                    new Positioned(
                        bottom: 16.0f,
                        left: 16.0f,
                        right: 16.0f,
                        child: new FittedBox(
                            fit: BoxFit.scaleDown,
                            alignment: Alignment.centerLeft,
                            child: new Text(this.destination.title,
                                            style: titleStyle
                                            )
                            )
                        )
                }
                        )
                    ),
                new Expanded(
                    child: new Padding(
                        padding: EdgeInsets.fromLTRB(16.0f, 16.0f, 16.0f, 0.0f),
                        child: new DefaultTextStyle(
                            softWrap: false,
                            overflow: TextOverflow.ellipsis,
                            style: descriptionStyle,
                            child: new Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: new List <Widget> {
                    new Padding(
                        padding: EdgeInsets.only(bottom: 8.0f),
                        child: new Text(this.destination.description[0],
                                        style: descriptionStyle.copyWith(color: Colors.black54)
                                        )
                        ),
                    new Text(this.destination.description[1]),
                    new Text(this.destination.description[2])
                }
                                )
                            )
                        )
                    ),
                ButtonTheme.bar(
                    child: new ButtonBar(
                        alignment: MainAxisAlignment.start,
                        children: new List <Widget> {
                    new FlatButton(
                        child: new Text("SHARE"),
                        textColor: Colors.amber.shade500,
                        onPressed: () => {
                        /* do nothing */
                    }
                        ),
                    new FlatButton(
                        child: new Text("EXPLORE"),
                        textColor: Colors.amber.shade500,
                        onPressed: () => {
                        /* do nothing */
                    }
                        )
                }
                        )
                    ),
            }
                                   )
                               )
                           )
                       ));
        }
Ejemplo n.º 13
0
 public void SetButtonTheme(ButtonTheme theme)
 {
     _buttonTheme = theme;
 }
Ejemplo n.º 14
0
 private Template SelectTemplate(ButtonTheme theme)
 {
     switch (theme)
     {
         case ButtonTheme.Default:
             return null;
         case ButtonTheme.Aero:
             return new AeroTemplate();
         case ButtonTheme.Metro:
             return new MetroTemplate();
         default:
             return AutoSelectTemplate();
     }
 }