Ejemplo n.º 1
0
        public void SetContainer(ILibraryContainer currentContainer)
        {
            var linkButtonFactory = ApplicationController.Instance.Theme.LinkButtonFactory;
            var theme             = ApplicationController.Instance.Theme;

            this.CloseAllChildren();

            var upbutton = new IconButton(AggContext.StaticData.LoadIcon(Path.Combine("FileDialog", "up_folder_20.png"), theme.InvertIcons), theme)
            {
                VAnchor     = VAnchor.Fit | VAnchor.Center,
                Enabled     = currentContainer.Parent != null,
                Name        = "Library Up Button",
                Margin      = theme.ButtonSpacing,
                MinimumSize = new Vector2(theme.ButtonHeight, theme.ButtonHeight)
            };

            upbutton.Click += (s, e) =>
            {
                if (listView.ActiveContainer.Parent != null)
                {
                    UiThread.RunOnIdle(() => listView.SetActiveContainer(listView.ActiveContainer.Parent));
                }
            };
            this.AddChild(upbutton);

            bool firstItem = true;

            if (this.Width < 250)
            {
                Button containerButton = linkButtonFactory.Generate(listView.ActiveContainer.Name == null ? "?" : listView.ActiveContainer.Name);
                containerButton.Name    = "Bread Crumb Button " + listView.ActiveContainer.Name;
                containerButton.VAnchor = VAnchor.Center;
                containerButton.Margin  = theme.ButtonSpacing;

                this.AddChild(containerButton);
            }
            else
            {
                var extraSpacing = (theme.ButtonSpacing).Clone(left: theme.ButtonSpacing.Right * .4);

                foreach (var container in currentContainer.AncestorsAndSelf().Reverse())
                {
                    if (!firstItem)
                    {
                        // Add path separator
                        var textContainer = new GuiWidget()                         // HACK: Workaround for VAlign.Center failure in this specific case. Remove wrapper(with padding) once fixed and directly add TextWidget child
                        {
                            HAnchor = HAnchor.Fit,
                            VAnchor = VAnchor.Fit | VAnchor.Center,
                            Padding = new BorderDouble(top: 4),
                            Margin  = extraSpacing,
                        };
                        textContainer.AddChild(new TextWidget("/", pointSize: theme.DefaultFontSize + 2, textColor: ActiveTheme.Instance.PrimaryTextColor));
                        this.AddChild(textContainer);
                    }

                    // Create a button for each container
                    Button containerButton = linkButtonFactory.Generate(container.Name);
                    containerButton.Name    = "Bread Crumb Button " + container.Name;
                    containerButton.VAnchor = VAnchor.Center;
                    containerButton.Margin  = theme.ButtonSpacing;
                    containerButton.Click  += (s, e) =>
                    {
                        UiThread.RunOnIdle(() => listView.SetActiveContainer(container));
                    };
                    this.AddChild(containerButton);

                    firstItem = false;
                }

                // while all the buttons don't fit in the control
                if (this.Parent != null &&
                    this.Width > 0 &&
                    this.Children.Count > 4 &&
                    this.GetChildrenBoundsIncludingMargins().Width > (this.Width - 20))
                {
                    // lets take out the > and put in a ...
                    this.RemoveChild(1);

                    var separator = new TextWidget("...", textColor: ActiveTheme.Instance.PrimaryTextColor)
                    {
                        VAnchor = VAnchor.Center,
                        Margin  = new BorderDouble(right:  5)
                    };
                    this.AddChild(separator, 1);

                    while (this.GetChildrenBoundsIncludingMargins().Width > this.Width - 20 &&
                           this.Children.Count > 4)
                    {
                        this.RemoveChild(3);
                        this.RemoveChild(2);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void SetContainer(ILibraryContainer currentContainer)
        {
            this.CloseAllChildren();

            var upbutton = new IconButton(AggContext.StaticData.LoadIcon(Path.Combine("Library", "upfolder_20.png"), theme.InvertIcons), theme)
            {
                VAnchor     = VAnchor.Fit | VAnchor.Center,
                Enabled     = currentContainer.Parent != null,
                Name        = "Library Up Button",
                ToolTipText = "Up one folder".Localize(),
                Margin      = theme.ButtonSpacing,
                MinimumSize = new Vector2(theme.ButtonHeight, theme.ButtonHeight)
            };

            upbutton.Click += (s, e) =>
            {
                if (listView.ActiveContainer.Parent != null)
                {
                    UiThread.RunOnIdle(() => listView.SetActiveContainer(listView.ActiveContainer.Parent));
                }
            };
            this.AddChild(upbutton);

            bool firstItem = true;

            if (this.Width < 250)
            {
                var containerButton = new LinkLabel((listView.ActiveContainer.Name == null ? "?" : listView.ActiveContainer.Name), theme)
                {
                    Name      = "Bread Crumb Button " + listView.ActiveContainer.Name,
                    VAnchor   = VAnchor.Center,
                    Margin    = theme.ButtonSpacing,
                    TextColor = theme.Colors.PrimaryTextColor
                };
                this.AddChild(containerButton);
            }
            else
            {
                var extraSpacing = (theme.ButtonSpacing).Clone(left: theme.ButtonSpacing.Right * .4);

                foreach (var container in currentContainer.AncestorsAndSelf().Reverse())
                {
                    if (!firstItem)
                    {
                        // Add path separator
                        this.AddChild(new TextWidget("/", pointSize: theme.DefaultFontSize + 1, textColor: ActiveTheme.Instance.PrimaryTextColor)
                        {
                            VAnchor = VAnchor.Center,
                            Margin  = extraSpacing.Clone(top: 2)
                        });
                    }

                    // Create a button for each container
                    var containerButton = new LinkLabel(container.Name, theme)
                    {
                        Name      = "Bread Crumb Button " + container.Name,
                        VAnchor   = VAnchor.Center,
                        Margin    = theme.ButtonSpacing.Clone(top: 1),
                        TextColor = theme.Colors.PrimaryTextColor
                    };
                    containerButton.Click += (s, e) =>
                    {
                        UiThread.RunOnIdle(() => listView.SetActiveContainer(container));
                    };
                    this.AddChild(containerButton);

                    firstItem = false;
                }

                // while all the buttons don't fit in the control
                if (this.Parent != null &&
                    this.Width > 0 &&
                    this.Children.Count > 4 &&
                    this.GetChildrenBoundsIncludingMargins().Width > (this.Width - 20))
                {
                    // lets take out the > and put in a ...
                    this.RemoveChild(1);

                    var separator = new TextWidget("...", textColor: ActiveTheme.Instance.PrimaryTextColor)
                    {
                        VAnchor = VAnchor.Center,
                        Margin  = new BorderDouble(right:  5)
                    };
                    this.AddChild(separator, 1);

                    while (this.GetChildrenBoundsIncludingMargins().Width > this.Width - 20 &&
                           this.Children.Count > 4)
                    {
                        this.RemoveChild(3);
                        this.RemoveChild(2);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void SetContainer(ILibraryContainer currentContainer)
        {
            this.CloseChildren();

            var backButton = new IconButton(StaticData.Instance.LoadIcon(Path.Combine("Library", "back.png"), 20, 20).SetToColor(theme.TextColor), theme)
            {
                VAnchor     = VAnchor.Fit | VAnchor.Center,
                Enabled     = currentContainer.Parent != null,
                Name        = "Library Up Button",
                ToolTipText = "Click to go back".Localize(),
                Margin      = theme.ButtonSpacing,
                MinimumSize = new Vector2(theme.ButtonHeight, theme.ButtonHeight)
            };

            backButton.Click += (s, e) =>
            {
                NavigateBack();
            };
            this.AddChild(backButton);

            bool firstItem = true;

            if (this.Width < 250)
            {
                var containerButton = new LinkLabel((libraryContext.ActiveContainer.Name == null ? "?" : libraryContext.ActiveContainer.Name), theme)
                {
                    Name      = "Bread Crumb Button " + libraryContext.ActiveContainer.Name,
                    VAnchor   = VAnchor.Center,
                    Margin    = theme.ButtonSpacing,
                    TextColor = theme.TextColor
                };
                this.AddChild(containerButton);
            }
            else
            {
                var extraSpacing = (theme.ButtonSpacing).Clone(left: theme.ButtonSpacing.Right * .4);

                foreach (var container in currentContainer.AncestorsAndSelf().Reverse())
                {
                    if (!firstItem)
                    {
                        // Add path separator
                        this.AddChild(new TextWidget("/", pointSize: theme.DefaultFontSize + 1, textColor: theme.TextColor)
                        {
                            VAnchor = VAnchor.Center,
                            Margin  = extraSpacing.Clone(top: 2)
                        });
                    }

                    // Create a button for each container
                    var containerButton = new LinkLabel(container.Name, theme)
                    {
                        Name      = "Bread Crumb Button " + container.Name,
                        VAnchor   = VAnchor.Center,
                        Margin    = theme.ButtonSpacing.Clone(top: 1),
                        TextColor = theme.TextColor
                    };
                    containerButton.Click += (s, e) =>
                    {
                        UiThread.RunOnIdle(() => libraryContext.ActiveContainer = container);
                    };
                    this.AddChild(containerButton);

                    firstItem = false;
                }

                var childrenWidth = this.GetChildrenBoundsIncludingMargins().Width;
                // while all the buttons don't fit in the control
                if (this.Parent != null &&
                    this.Width > 0 &&
                    this.Children.Count > 4 &&
                    childrenWidth > (this.Width - 20))
                {
                    // lets take out the > and put in a ...
                    var removedWidth = this.RemoveChild(1).Width;

                    var separator = new TextWidget("...", textColor: theme.TextColor)
                    {
                        VAnchor = VAnchor.Center,
                        Margin  = new BorderDouble(right:  5)
                    };
                    removedWidth -= this.AddChild(separator, 1).Width;

                    while (childrenWidth - removedWidth > this.Width - 20 &&
                           this.Children.Count > 4)
                    {
                        removedWidth += this.RemoveChild(3).Width;
                        removedWidth += this.RemoveChild(2).Width;
                    }

                    UiThread.RunOnIdle(() => this.Width = this.Width + 1);
                }
            }
        }