コード例 #1
0
ファイル: Menu.cs プロジェクト: communityus-branch/Myra
        private void InsertItem(IMenuItem iMenuItem, int index)
        {
            var    menuItem = iMenuItem as MenuItem;
            Widget widget;

            if (menuItem != null)
            {
                menuItem.Changed += MenuItemOnChanged;
                var menuItemButton = new MenuItemButton(this, MenuItemStyle)
                {
                    Text = menuItem.Text,
                    Tag  = menuItem
                };

                if (menuItem.Color.HasValue)
                {
                    menuItemButton.TextColor = menuItem.Color.Value;
                }

                menuItemButton.MouseEntered += MouseOnEntered;
                menuItemButton.MouseLeft    += MouseOnLeft;
                menuItemButton.SubMenu.Items = menuItem.Items;
                menuItemButton.Toggleable    = menuItem.Items.Count > 0;

                if (menuItemButton.Toggleable)
                {
                    menuItemButton.PressedChanged += ButtonOnPressedChanged;
                }
                else
                {
                    menuItemButton.Click += ButtonOnClick;
                }

                widget = menuItemButton;
            }
            else
            {
                if (Orientation == Orientation.Horizontal)
                {
                    widget = new VerticalSeparator(SeparatorStyle);
                }
                else
                {
                    widget = new HorizontalSeparator(SeparatorStyle);
                }
            }

            iMenuItem.Menu   = this;
            iMenuItem.Widget = widget;

            AddItem(widget, index);
            UpdateGridPositions();
        }
コード例 #2
0
        private void InsertItem(IMenuItem item, int index)
        {
            item.Menu = this;

            var menuItem = item as MenuItem;

            if (menuItem != null)
            {
                menuItem.Changed += MenuItemOnChanged;

                if (Orientation == Orientation.Horizontal)
                {
                    menuItem.Label.ApplyLabelStyle(MenuStyle.LabelStyle);
                }
                else
                {
                    menuItem.ImageWidget.ApplyPressableImageStyle(MenuStyle.ImageStyle);
                    menuItem.Label.ApplyLabelStyle(MenuStyle.LabelStyle);
                    menuItem.Shortcut.ApplyLabelStyle(MenuStyle.ShortcutStyle);
                }

                // Add only label, as other widgets(image and shortcut) would be optionally added by SetMenuItem
                InternalChild.Widgets.Add(menuItem.Label);
                SetMenuItem((MenuItem)item);
            }
            else
            {
                SeparatorWidget separator;
                if (Orientation == Orientation.Horizontal)
                {
                    separator = new VerticalSeparator(null);
                }
                else
                {
                    separator = new HorizontalSeparator(null);
                }

                separator.ApplySeparatorStyle(MenuStyle.SeparatorStyle);

                InternalChild.Widgets.Add(separator);

                ((MenuSeparator)item).Separator = separator;
            }
        }