コード例 #1
0
ファイル: TextblockLayout.cs プロジェクト: emmauss/VisiPlacer
        private void Initialize(Label textBlock, double fontsize, bool allowCropping, bool allowSplittingWords)
        {
            Effect effect = Effect.Resolve("VisiPlacement.TextItemEffect");

            textBlock.Effects.Add(effect);
            textBlock.Margin    = new Thickness(0);
            textBlock.TextColor = Color.LightGray;
            this.textBlock      = textBlock;

            this.layouts = new List <LayoutChoice_Set>();
            if (fontsize > 0)
            {
                if (allowCropping || allowSplittingWords)
                {
                    layouts.Add(this.makeLayout(fontsize, allowCropping, allowSplittingWords));
                }
                layouts.Add(this.makeLayout(fontsize, false, false));
            }
            else
            {
                layouts.Add(this.makeLayout(30, false, false));
                layouts.Add(this.makeLayout(16, false, false));
                layouts.Add(this.makeLayout(10, false, false));
                if (allowCropping || allowSplittingWords)
                {
                    layouts.Add(this.makeLayout(10, allowCropping, allowSplittingWords));
                }
            }

            this.SubLayout = LayoutUnion.New(layouts);
        }
コード例 #2
0
        private void initialize(Editor textBox, IEnumerable <double> fontSizes)
        {
            if (fontSizes == null)
            {
                fontSizes = new List <double>()
                {
                    30, 16
                }
            }
            ;
            Effect effect = Effect.Resolve("VisiPlacement.TextItemEffect");

            textBox.Effects.Add(effect);

            textBox.Margin = new Thickness();

            this.TextBox            = textBox;
            textBox.BackgroundColor = Color.LightGray;
            this.TextBox.Margin     = new Thickness();

            TextBox_Configurer configurer  = new TextBox_Configurer(textBox);
            double             minFontSize = -1;

            foreach (double fontSize in fontSizes)
            {
                if (minFontSize < 0 || fontSize < minFontSize)
                {
                    minFontSize = fontSize;
                }
                this.layouts.Add(new TextLayout(configurer, fontSize));
            }
            if (minFontSize > 0)
            {
                this.layouts.Add(new TextLayout(configurer, minFontSize, true));
            }

            this.SubLayout = LayoutUnion.New(layouts);
        }
コード例 #3
0
        private LayoutChoice_Set build()
        {
            GridLayout_Builder mainBuilder = new Vertical_GridLayout_Builder().Uniform();

            this.buttons            = new List <Button>();
            this.subtitles          = new List <TextblockLayout>();
            this.buttonDestinations = new Dictionary <Button, ValueProvider <StackEntry> >();
            for (int i = 0; i < this.buttonNameProviders.Count; i++)
            {
                Button button = new Button();
                button.Clicked += Button_Clicked;
                this.buttons.Add(button);

                ButtonLayout    buttonLayout   = new ButtonLayout(button);
                TextblockLayout subtitleLayout = new TextblockLayout();
                subtitleLayout.AlignHorizontally(TextAlignment.Center);
                subtitleLayout.AlignVertically(TextAlignment.Center);
                subtitleLayout.ScoreIfEmpty = false;
                this.subtitles.Add(subtitleLayout);

                BoundProperty_List columnWidths = new BoundProperty_List(2);
                columnWidths.SetPropertyScale(0, 2);
                columnWidths.SetPropertyScale(1, 1);
                columnWidths.BindIndices(0, 1);
                GridLayout entryGrid = GridLayout.New(new BoundProperty_List(1), columnWidths, LayoutScore.Get_UnCentered_LayoutScore(1));
                entryGrid.AddLayout(buttonLayout);
                entryGrid.AddLayout(subtitleLayout);

                LayoutUnion content = new LayoutUnion(entryGrid, buttonLayout);
                mainBuilder.AddLayout(content);

                ValueProvider <StackEntry> destinationProvider = destinationProviders[i];
                this.buttonDestinations[button] = destinationProvider;
            }
            return(LayoutCache.For(mainBuilder.BuildAnyLayout()));
        }
コード例 #4
0
        private void Initialize(Button button, double fontSize = -1, bool includeBevel = true, bool allowCropping = false, bool scoreIfEmpty = false, bool allowSplittingWords = false)
        {
            bool             isButtonColorSet = button.BackgroundColor.A > 0;
            LayoutChoice_Set sublayout;

            this.buttonBackground = new ContentView();
            ButtonConfigurer buttonConfigurer = new ButtonConfigurer(button, this.buttonBackground);

            if (fontSize > 0)
            {
                if (allowCropping)
                {
                    sublayout = TextLayout.New_Croppable(buttonConfigurer, fontSize, scoreIfEmpty);
                }
                else
                {
                    sublayout = new TextLayout(buttonConfigurer, fontSize, allowSplittingWords, scoreIfEmpty);
                }
            }
            else
            {
                List <LayoutChoice_Set> sublayoutOptions = new List <LayoutChoice_Set>(3);
                if (allowCropping)
                {
                    sublayoutOptions.Add(TextLayout.New_Croppable(buttonConfigurer, 30, scoreIfEmpty));
                    sublayoutOptions.Add(TextLayout.New_Croppable(buttonConfigurer, 16, scoreIfEmpty));
                    sublayoutOptions.Add(TextLayout.New_Croppable(buttonConfigurer, 12, scoreIfEmpty));
                }
                else
                {
                    sublayoutOptions.Add(new TextLayout(buttonConfigurer, 30, allowSplittingWords, scoreIfEmpty));
                    sublayoutOptions.Add(new TextLayout(buttonConfigurer, 16, allowSplittingWords, scoreIfEmpty));
                    sublayoutOptions.Add(new TextLayout(buttonConfigurer, 12, allowSplittingWords, scoreIfEmpty));
                }
                LayoutUnion layoutUnion = new LayoutUnion(sublayoutOptions);
                sublayout = layoutUnion;
            }

            // add a view behind the button to change its normal background color without changing its color when selected
            ContainerLayout backgroundLayout = new ContainerLayout(buttonBackground, sublayout, false);

            if (includeBevel)
            {
                buttonBackground.BackgroundColor = Color.Black;
                // add a small border, so that it's easy to see where the buttons end
                Thickness   innerBevelThickness = new Thickness(1);
                ContentView insideBevel         = new ContentView();
                insideBevel.Padding = innerBevelThickness;
                //insideBevel.BackgroundColor = Color.DarkGray;// Color.FromRgb(0.4, 0.4, 0.4);
                buttonConfigurer.InnerBevel = insideBevel;
                ContainerLayout middleLayout = new MustBorderLayout(insideBevel, backgroundLayout, innerBevelThickness, false);

                // add a bevel to the border
                Thickness   outerBevelThickness = new Thickness(1);
                ContentView outsideBevel        = new ContentView();
                outsideBevel.Padding = outerBevelThickness;
                //outsideBevel.BackgroundColor = Color.LightGray;// Color.FromRgb(0.63, 0.63, 0.63);
                buttonConfigurer.OuterBevel = outsideBevel;
                ContainerLayout outsideLayout = new MustBorderLayout(outsideBevel, middleLayout, outerBevelThickness, false);

                // add some extra space around it
                Thickness   spacingThickness = new Thickness(1);
                ContentView spacing          = new ContentView();
                spacing.Padding         = spacingThickness;
                spacing.BackgroundColor = Color.FromRgba(0, 0, 0, 0);
                ContainerLayout spacingLayout = new MustBorderLayout(spacing, outsideLayout, spacingThickness, false);

                this.Set_LayoutChoices(new List <LayoutChoice_Set>()
                {
                    spacingLayout, new ScoreShifted_Layout(null, LayoutScore.Get_CutOff_LayoutScore(1))
                });

                button.TextColor = Color.LightGray;
            }
            else
            {
                if (!isButtonColorSet)
                {
                    buttonBackground.BackgroundColor = Color.White;
                    button.TextColor = Color.Black;
                }
                this.Set_LayoutChoices(new List <LayoutChoice_Set>()
                {
                    backgroundLayout
                });
            }
            Effect effect = Effect.Resolve("VisiPlacement.ButtonEffect");

            button.Effects.Add(effect);

            this.buttonConfigurer = buttonConfigurer;
        }