Esempio n. 1
0
            public ProgressBarField()
            {
                Layout = new HBoxLayout {
                    Spacing = 6
                };
                MinMaxHeight = Theme.Metrics.DefaultButtonSize.Y;

                var bar  = new ThemedFrame();
                var rect = new Widget();

                rect.CompoundPresenter.Add(new WidgetFlatFillPresenter(Lime.Theme.Colors.SelectedBorder));
                rect.Tasks.AddLoop(() => {
                    rect.Size = new Vector2(bar.Width * Mathf.Clamp((float)CurrentPosition / MaxPosition, 0, 1), bar.ContentHeight);
                });
                bar.AddNode(rect);

                textFieldA = new ThemedSimpleText {
                    VAlignment = VAlignment.Center,
                    HAlignment = HAlignment.Center,
                };
                textFieldB = new ThemedSimpleText {
                    VAlignment = VAlignment.Center,
                    HAlignment = HAlignment.Center,
                };

                AddNode(bar);
                AddNode(textFieldA);
                AddNode(textFieldB);

                HideAndClear();
            }
Esempio n. 2
0
 public ModalOperationDialog(GetCurrentStatusDelegate getCurrentStatus, string title = null)
 {
     window = new Window(new WindowOptions {
         FixedSize = true,
         Title     = title ?? "Tangerine",
         Visible   = false,
         Style     = WindowStyle.Borderless
     });
     rootWidget = new ThemedInvalidableWindowWidget(window)
     {
         LayoutBasedWindowSize = true,
         Padding = new Thickness(8),
         Layout  = new VBoxLayout {
             Spacing = 16
         },
         Nodes =
         {
             (statusText = new ThemedSimpleText {
                 Padding = new Thickness(4)
             })
         }
     };
     rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
     rootWidget.LateTasks.AddLoop(() => {
         statusText.Text = $"{title}\n{getCurrentStatus()}";
     });
 }
Esempio n. 3
0
        private void CreateHeaderWidgets(CookingRulesCollection crc, string path, Meta.Item yi,
                                         Widget headerWidget, Widget overridesWidget, CookingRules rules)
        {
            SimpleText computedValueText;
            Button     createOrDestroyOverride = null;

            headerWidget.HitTestTarget = true;
            headerWidget.CompoundPostPresenter.Add(new DelegatePresenter <Widget>((widget) => {
                if (widget.IsMouseOver())
                {
                    widget.PrepareRendererState();
                    Renderer.DrawRect(
                        Vector2.Zero,
                        widget.Size,
                        Theme.Colors.SelectedBackground.Transparentify(0.8f));
                }
            }));
            Func <ITexture> btnTexture = () => IsOverridedByAssociatedCookingRules(crc, path, yi) ? IconPool.GetTexture("Filesystem.Cross") : IconPool.GetTexture("Filesystem.Plus");
            Widget          foldButton;

            headerWidget.Nodes.AddRange(
                (foldButton = CreateFoldButton(overridesWidget)),
                (new ThemedSimpleText {
                ForceUncutText = false,
                VAlignment = VAlignment.Center,
                HAlignment = HAlignment.Left,
                OverflowMode = TextOverflowMode.Ellipsis,
                LayoutCell = new LayoutCell {
                    StretchX = 1
                },
                Size = new Vector2(150, RowHeight),
                MinSize = new Vector2(100, RowHeight),
                MaxSize = new Vector2(200, RowHeight),
                Text = yi.Name,
            }),
                (computedValueText = new ThemedSimpleText {
                LayoutCell = new LayoutCell {
                    StretchX = 3
                },
                ForceUncutText = false,
                HAlignment = HAlignment.Left,
                Size = new Vector2(150, RowHeight),
                MinSize = new Vector2(50, RowHeight),
                MaxSize = new Vector2(300, RowHeight),
            }),
                (createOrDestroyOverride = new ToolbarButton {
                Texture = btnTexture(),
                Clicked = () => CreateOrDestroyFieldOverride(crc, path, yi, overridesWidget, createOrDestroyOverride),
            })
                );
            headerWidget.Clicked            = foldButton.Clicked;
            createOrDestroyOverride.Padding = Thickness.Zero;
            createOrDestroyOverride.Size    = createOrDestroyOverride.MinMaxSize = RowHeight * Vector2.One;
            if (IsCookingRulesFileItself(path))
            {
                rules = GetAssociatedCookingRules(crc, path);
            }
            computedValueText.AddChangeWatcher(() => yi.GetValue(rules.EffectiveRules),
                                               (o) => computedValueText.Text = rules.FieldValueToString(yi, yi.GetValue(rules.EffectiveRules)));
        }
Esempio n. 4
0
        public void EditRow(Row row)
        {
            property = row?.Components.Get <PropertyRow>();
            var   adapter = adapters[property.Animator.ValueType];
            float min, max;

            CalcRange(property.Animator, adapter, out min, out max);
            MinValue = min;
            MaxValue = max;
            toolbar.Nodes.Clear();
            for (int i = 0; i < adapter.ComponentCount; i++)
            {
                var color = ColorTheme.Current.TimelineCurveEditor.Curves[i];
                var curve = new Curve(property.Animator, i, adapter, color);
                Curves.Add(curve);
                toolbar.AddNode(new ColorBoxButton(color));
                var name  = adapter.GetComponentName(i) ?? property.Animator.TargetPropertyPath;
                var label = new ThemedSimpleText(name)
                {
                    MinWidth = 60
                };
                int c = i;
                label.AddChangeWatcher(
                    () => adapter.GetComponentValue(curve.Animator, Document.Current.Animation.Time, c),
                    v => label.Text = name + ": " + v.ToString("0.00"));
                toolbar.AddNode(label);
            }
        }
Esempio n. 5
0
            /// <summary>
            /// Creates basic UI elements, but lefts bundle list empty. To fill it, call <see cref="CreateBundlesList"/>
            /// </summary>
            public BundlePickerWidget(BundlePicker bundlePicker)
            {
                this.bundlePicker = bundlePicker;

                Layout = new VBoxLayout {
                    Spacing = 6
                };
                MaxWidth = 250f;

                checkboxes = new Dictionary <string, ThemedCheckBox>();
                lines      = new Dictionary <string, Widget>();
                scrollView = new ThemedScrollView();
                scrollView.CompoundPostPresenter.Add(new WidgetBoundsPresenter(Lime.Theme.Colors.ControlBorder));
                scrollView.Content.Layout = new VBoxLayout {
                    Spacing = 6
                };
                scrollView.Content.Padding = new Thickness(6);
                scrollView.CompoundPresenter.Add(new WidgetFlatFillPresenter(Color4.White));

                selectButton = new ThemedButton {
                    Text    = "Select all",
                    Clicked = SelectButtonClickHandler
                };

                refreshButton = new ThemedButton {
                    Text    = "Refresh",
                    Clicked = Refresh,
                };

                filter = new ThemedEditBox();
                filter.Tasks.Add(FilterBundlesTask);

                infoText = new ThemedSimpleText("Selected action uses all bundles.")
                {
                    Color        = Theme.Colors.BlackText,
                    MinMaxHeight = Theme.Metrics.DefaultEditBoxSize.Y,
                    Visible      = false,
                    VAlignment   = VAlignment.Center,
                };

                AddNode(filter);
                AddNode(infoText);
                AddNode(scrollView);

                var buttonLine = new Widget {
                    Layout = new HBoxLayout {
                        Spacing = 6
                    }
                };

                AddNode(buttonLine);
                buttonLine.AddNode(new Widget {
                    LayoutCell = new LayoutCell {
                        StretchX = float.MaxValue
                    }, MaxHeight = 0
                });
                buttonLine.AddNode(refreshButton);
                buttonLine.AddNode(selectButton);
                selectButton.Tasks.Add(UpdateTextOfSelectButtonTask());
            }
Esempio n. 6
0
            public RulerRowView(Ruler ruler, Action onDelete, Action onEdit)
            {
                ThemedDeleteButton deleteButton;
                ThemedSimpleText   label;

                Layout          = new HBoxLayout();
                Nodes.Add(label = new ThemedSimpleText {
                    Padding = new Thickness {
                        Left = 10
                    },
                });
                this.AddChangeWatcher(() => ruler.Name, (name) => label.Text = name);
                Nodes.Add(new Widget());
                Nodes.Add(editButton = new ToolbarButton()
                {
                    Anchors       = Anchors.Right,
                    LayoutCell    = new LayoutCell(Alignment.LeftTop),
                    Texture       = IconPool.GetTexture("Tools.Edit"),
                    Highlightable = false,
                });
                Nodes.Add(deleteButton = new ThemedDeleteButton {
                    Anchors    = Anchors.Right,
                    LayoutCell = new LayoutCell(Alignment.LeftTop)
                });
                deleteButton.Clicked = onDelete;
                editButton.Clicked   = onEdit;
                MinMaxHeight         = RowHeight;
            }
 public SkinningWeightsPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
 {
     editorParams.DefaultValueGetter = () => new SkinningWeights();
     indexEditors   = new NumericEditBox[4];
     weightsSliders = new ThemedAreaSlider[4];
     foreach (var o in editorParams.Objects)
     {
         var prop = new Property <SkinningWeights>(o, editorParams.PropertyName).Value;
     }
     for (var i = 0; i <= 3; i++)
     {
         indexEditors[i]      = editorParams.NumericEditBoxFactory();
         indexEditors[i].Step = 1;
         weightsSliders[i]    = new ThemedAreaSlider(range: new Vector2(0, 1), labelFormat: "0.00000");
         var wrapper = new Widget {
             Layout     = new HBoxLayout(),
             LayoutCell = new LayoutCell {
                 StretchY = 0
             }
         };
         var propertyLabel = new ThemedSimpleText {
             Text       = $"Bone { char.ConvertFromUtf32(65 + i) }",
             VAlignment = VAlignment.Center,
             Padding    = new Thickness {
                 Left = 20
             },
             LayoutCell = new LayoutCell {
                 StretchX = 1.0f
             },
             ForceUncutText = false,
             OverflowMode   = TextOverflowMode.Minify,
             HitTestTarget  = false
         };
         wrapper.AddNode(propertyLabel);
         wrapper.AddNode(new Widget {
             Layout = new HBoxLayout {
                 Spacing = 4
             },
             LayoutCell = new LayoutCell {
                 StretchX = 2.0f
             },
             Nodes =
             {
                 indexEditors[i],
                 weightsSliders[i]
             }
         });
         ExpandableContent.AddNode(wrapper);
         customWarningsContainer = new Widget {
             Layout = new VBoxLayout()
         };
         ContainerWidget.AddNode(customWarningsContainer);
         var j = i;
         SetLink(i, CoalescedPropertyComponentValue(sw => sw[j].Index), CoalescedPropertyComponentValue(sw => sw[j].Weight));
     }
     CheckWarnings();
 }
Esempio n. 8
0
        private static void AddPicker(Node table, string name, Node picker)
        {
            var label = new ThemedSimpleText(name)
            {
                VAlignment = VAlignment.Center,
                HAlignment = HAlignment.Left
            };

            label.MinHeight = Theme.Metrics.DefaultButtonSize.Y;
            table.AddNode(label);
            table.AddNode(picker);
        }
Esempio n. 9
0
        public FilesystemItem(string path)
        {
            FilesystemPath = path;
            this.Input.AcceptMouseThroughDescendants = true;
            SimpleText text = null;

            MinMaxSize = new Vector2(ItemWidth, IconSize);
            Layout     = new HBoxLayout {
                Spacing = Spacing
            };
            Padding       = new Thickness(2);
            HitTestTarget = true;
            var isRoot = false;

            if (new DirectoryInfo(FilesystemPath).Parent == null)
            {
                isRoot = true;
            }

            Nodes.AddRange(
                new Image {
                LayoutCell = new LayoutCell {
                    Stretch   = Vector2.Zero,
                    Alignment = new Alignment {
                        X = HAlignment.Right, Y = VAlignment.Center
                    }
                },
                MinMaxSize = new Vector2(IconSize, IconSize),
                Texture    = SystemIconTextureProvider.Instance.GetTexture(FilesystemPath),
            },
                (text = new ThemedSimpleText {
                ForceUncutText = false,
                OverflowMode = TextOverflowMode.Ellipsis,
                Text =
                    isRoot ?
                    FilesystemPath.Remove(FilesystemPath.Length - 1) :
                    Path.GetFileName(FilesystemPath),
                LayoutCell = new LayoutCell {
                    Alignment = new Alignment {
                        X = HAlignment.Right, Y = VAlignment.Bottom
                    }
                }
            }),
                new Widget {
                LayoutCell = new LayoutCell {
                    StretchX = float.MaxValue
                },
                MinWidth      = 0,
                HitTestTarget = true
            }
                );
            text.Width = text.MinMaxWidth = Mathf.Min(ItemWidth - (IconSize + ItemPadding * 2 + Spacing + 2), text.MeasureUncutText().X);
        }
Esempio n. 10
0
 public CheckBoxWithLabel(string text)
 {
     Layout = new HBoxLayout {
         Spacing = 8
     };
     AddNode(CheckBox = new ThemedCheckBox());
     Label            = new ThemedSimpleText(text)
     {
         HitTestTarget = true,
         Clicked       = CheckBox.Toggle
     };
     AddNode(Label);
 }
 public SkinningWeightsPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
 {
     editorParams.DefaultValueGetter = () => new SkinningWeights();
     indexEditors   = new NumericEditBox[4];
     weigthsEditors = new NumericEditBox[4];
     foreach (var o in editorParams.Objects)
     {
         var prop = new Property <SkinningWeights>(o, editorParams.PropertyName).Value;
     }
     for (var i = 0; i <= 3; i++)
     {
         indexEditors[i]      = editorParams.NumericEditBoxFactory();
         indexEditors[i].Step = 1;
         weigthsEditors[i]    = editorParams.NumericEditBoxFactory();
         var wrapper = new Widget {
             Padding = new Thickness {
                 Left = 20
             },
             Layout     = new HBoxLayout(),
             LayoutCell = new LayoutCell {
                 StretchY = 0
             }
         };
         var propertyLabel = new ThemedSimpleText {
             Text           = $"Bone { char.ConvertFromUtf32(65 + i) }",
             VAlignment     = VAlignment.Center,
             LayoutCell     = new LayoutCell(Alignment.LeftCenter, 0),
             ForceUncutText = false,
             MinWidth       = 140,
             OverflowMode   = TextOverflowMode.Minify,
             HitTestTarget  = true,
             TabTravesable  = new TabTraversable(),
         };
         wrapper.AddNode(propertyLabel);
         wrapper.AddNode(new Widget {
             Layout = new HBoxLayout {
                 DefaultCell = new DefaultLayoutCell(Alignment.Center), Spacing = 4
             },
             Nodes =
             {
                 indexEditors[i],
                 weigthsEditors[i]
             }
         });
         ExpandableContent.AddNode(wrapper);
         var j = i;
         SetLink(i, CoalescedPropertyComponentValue(sw => sw[j].Index), CoalescedPropertyComponentValue(sw => sw[j].Weight));
     }
 }
Esempio n. 12
0
 public CommonPropertyEditor(IPropertyEditorParams editorParams)
 {
     EditorParams    = editorParams;
     ContainerWidget = new Widget {
         Layout = new HBoxLayout {
             IgnoreHidden = false
         },
         LayoutCell = new LayoutCell {
             StretchY = 0
         },
     };
     //ContainerWidget.CompoundPostPresenter.Add(new LayoutDebugPresenter(Color4.Red, 2.0f));
     editorParams.InspectorPane.AddNode(ContainerWidget);
     if (editorParams.ShowLabel)
     {
         LabelContainer = new Widget {
             Layout     = new HBoxLayout(),
             LayoutCell = new LayoutCell {
                 StretchX = 1.0f
             },
             Nodes =
             {
                 (PropertyLabel     = new ThemedSimpleText {
                     Text           = editorParams.DisplayName ?? editorParams.PropertyName,
                     VAlignment     = VAlignment.Center,
                     LayoutCell     = new LayoutCell(Alignment.LeftCenter),
                     ForceUncutText = false,
                     Padding        = new Thickness(left: 5.0f),
                     HitTestTarget  = true,
                     TabTravesable  = new TabTraversable()
                 })
             }
         };
         PropertyLabel.Tasks.Add(ManageLabelTask());
         ContainerWidget.Tasks.Add(Tip.ShowTipOnMouseOverTask(PropertyLabel, () => PropertyLabel.Text));
         ContainerWidget.AddNode(LabelContainer);
         EditorContainer = new Widget {
             Layout     = new HBoxLayout(),
             LayoutCell = new LayoutCell {
                 StretchX = 2.0f
             },
         };
         ContainerWidget.AddNode(EditorContainer);
     }
     else
     {
         LabelContainer = EditorContainer = ContainerWidget;
     }
 }
Esempio n. 13
0
        Widget CreateAnimationIndicator()
        {
            var t = new ThemedSimpleText {
                Padding = new Thickness(4, 0), MinWidth = 100
            };
            Action f = () => {
                var distance = Timeline.Instance.Ruler.MeasuredFrameDistance;
                t.Text = (distance == 0) ?
                         $"Col : {Document.Current.AnimationFrame}" :
                         $"Col : {Document.Current.AnimationFrame} {Timeline.Instance.Ruler.MeasuredFrameDistance:+#;-#;0}";
            };

            t.AddChangeWatcher(() => Document.Current.AnimationFrame, _ => f());
            t.AddChangeWatcher(() => Timeline.Instance.Ruler.MeasuredFrameDistance, _ => f());
            return(t);
        }
Esempio n. 14
0
        private Widget AddTitle(Widget widget, out ThemedTabCloseButton closeButton, out ThemedSimpleText title, string id = null)
        {
            Widget titleWidget;
            var    result = new Widget {
                Id         = id,
                LayoutCell = new LayoutCell(),
                Layout     = new VBoxLayout(),
                Nodes      =
                {
                    (titleWidget               = new Widget               {
                        Layout                 = new HBoxLayout(),
                        HitTestTarget          = true,
                        Nodes                  =
                        {
                            (title             = new ThemedSimpleText     {
                                Padding        = new Thickness(4, 0),
                                ForceUncutText = false,
                                MinMaxHeight   = Theme.Metrics.MinTabSize.Y,
                                VAlignment     = VAlignment.Center
                            }),
                            (closeButton       = new ThemedTabCloseButton {
                                LayoutCell     = new LayoutCell(Alignment.Center)
                            })
                        }
                    }),
                    new Frame {
                        Nodes                  =
                        {
                            widget
                        }
                    }
                }
            };

            // Add space between close button and titleWidget right border.
            title.Padding = title.Padding + new Thickness(right: 5);
            titleWidget.CompoundPresenter.Add(new SyncDelegatePresenter <Widget>(w => {
                w.PrepareRendererState();
                Renderer.DrawRect(Vector2.Zero, w.Size, ColorTheme.Current.Docking.PanelTitleBackground);
                Renderer.DrawLine(0, w.Height - 0.5f, w.Width, w.Height - 0.5f, ColorTheme.Current.Docking.PanelTitleSeparator);
            }));
            widget.ExpandToContainerWithAnchors();
            result.FocusScope = new KeyboardFocusScope(result);
            return(result);
        }
Esempio n. 15
0
 public SceneViewThumbnail(OverviewPane overviewPane)
 {
     this.overviewPane = overviewPane;
     window            = new Window(new WindowOptions {
         Style     = WindowStyle.Borderless,
         FixedSize = true,
         Visible   = false,
         Centered  = false,
         Type      = WindowType.ToolTip
     });
     root = new ThemedFrame {
         Layout = new StackLayout(),
         Nodes  =
         {
             new Frame          {
                 Layout = new VBoxLayout(),
                 Nodes  =
                 {
                     new Widget {
                         LayoutCell = new LayoutCell{
                             StretchY = 1
                         }
                     },
                     (label = new ThemedSimpleText{
                         Padding = new Thickness(2)
                     })
                 }
             },
             (thumbnailImage = new Image{
                 Padding = new Thickness(1)
             }),
         },
         Presenter = new ThemedFramePresenter(Color4.Black, Color4.Black)
     };
     new ThemedInvalidableWindowWidget(window)
     {
         LayoutBasedWindowSize = true,
         Layout = new VBoxLayout(),
         Nodes  =
         {
             root
         }
     };
     overviewPane.RootWidget.Tasks.Add(ShowOnMouseOverTask());
 }
Esempio n. 16
0
 public RulerRowView(RulerData overlay, IList <RulerData> overlays) : base()
 {
     Layout          = new HBoxLayout();
     Nodes.Add(Label = new ThemedSimpleText {
         Padding = new Thickness {
             Left = 10
         },
     });
     this.AddChangeWatcher(() => overlay.Name, (name) => Label.Text = name);
     Nodes.Add(new Widget());
     Nodes.Add(deleteButton = new ThemedDeleteButton {
         Anchors    = Anchors.Right,
         LayoutCell = new LayoutCell(Alignment.LeftTop)
     });
     CompoundPresenter.Add(StripePresenter);
     deleteButton.Clicked = () => overlays.Remove(overlay);
     MinMaxHeight         = 20;
 }
Esempio n. 17
0
 public PluginCheckBoxWidget(OrangePluginPanel.PluginCheckBox pluginCheckBox)
 {
     Layout = new HBoxLayout {
         Spacing = 8
     };
     CheckBox          = new ThemedCheckBox();
     Checked           = pluginCheckBox.Active;
     CheckBox.Changed += args => {
         pluginCheckBox.Active = Checked;
         pluginCheckBox.Toogle();
     };
     AddNode(CheckBox);
     Label = new ThemedSimpleText(pluginCheckBox.Label)
     {
         HitTestTarget = true,
         Clicked       = CheckBox.Toggle
     };
     AddNode(Label);
 }
Esempio n. 18
0
        private void UpdateAllShortcutsView(ThemedScrollView allShortcutsView, ThemedScrollView selectedShortcutsView, HotkeyEditor hotkeyEditor, string filter)
        {
            allShortcutsView.Content.Nodes.Clear();
            if (hotkeyEditor.Profile == null)
            {
                return;
            }
            foreach (var category in hotkeyEditor.Profile.Categories)
            {
                var expandableContent = new Frame {
                    Layout = new VBoxLayout {
                        Spacing = 4
                    },
                    Visible = true
                };
                var expandButton = new ThemedExpandButton {
                    Anchors    = Anchors.Left,
                    MinMaxSize = Vector2.One * 20f,
                    Expanded   = expandableContent.Visible
                };
                var title = new ThemedSimpleText {
                    Text       = category.Title,
                    VAlignment = VAlignment.Center,
                    LayoutCell = new LayoutCell(Alignment.LeftCenter, stretchX: 0)
                };
                expandButton.Clicked += () => {
                    expandableContent.Visible = !expandableContent.Visible;
                    expandButton.Expanded     = expandableContent.Visible;
                };
                var header = new Widget {
                    Layout = new HBoxLayout(),
                    Nodes  = { expandButton, title }
                };
                allShortcutsView.Content.AddNode(header);
                allShortcutsView.Content.AddNode(expandableContent);
                var filteredCommands = String.IsNullOrEmpty(filter) ?
                                       category.Commands.Values : category.Commands.Values.Where(i => i.Title.ToLower().Contains(filter));
                title.Color          = filteredCommands.Any() ? Theme.Colors.BlackText : Theme.Colors.GrayText;
                expandButton.Enabled = filteredCommands.Any();
                foreach (var command in filteredCommands)
                {
                    var editor = new ShortcutPropertyEditor(
                        new PreferencesPropertyEditorParams(expandableContent, command, propertyName: "Shortcut", displayName: command.Title));
                    editor.PropertyLabel.OverflowMode = TextOverflowMode.Ellipsis;
                    editor.PropertyLabel.LayoutCell   = new LayoutCell(Alignment.LeftCenter, 1);
                    editor.PropertyLabel.Padding      = new Thickness(expandButton.Width, 0);

                    editor.PropertyLabel.CompoundPresenter.RemoveAll(i => i as SelectionPresenter != null);
                    editor.PropertyLabel.Caret = new CaretPosition();

                    if (!String.IsNullOrEmpty(filter))
                    {
                        var mc    = new MultiCaretPosition();
                        var start = new CaretPosition {
                            IsVisible = true, WorldPos = new Vector2(1, 1)
                        };
                        var finish = new CaretPosition {
                            IsVisible = true, WorldPos = new Vector2(1, 1)
                        };
                        mc.Add(start);
                        mc.Add(finish);
                        editor.PropertyLabel.Caret = mc;
                        start.TextPos  = editor.PropertyLabel.Text.ToLower().IndexOf(filter);
                        finish.TextPos = start.TextPos + filter.Length;
                        new SelectionPresenter(editor.PropertyLabel, start, finish, new SelectionParams()
                        {
                            Color            = Theme.Colors.TextSelection,
                            OutlineThickness = 0
                        });
                    }

                    editor.ContainerWidget.LayoutCell = new LayoutCell(Alignment.LeftCenter, 1);
                    editor.PropertyChanged            = () => {
                        hotkeyEditor.UpdateButtonCommands();
                        hotkeyEditor.UpdateShortcuts();
                    };

                    var dragGesture = new DragGesture();
                    editor.ContainerWidget.Gestures.Add(dragGesture);

                    var task = new Task(UpdateDragCursor(selectedShortcutsView, hotkeyEditor));
                    dragGesture.Recognized += () => editor.ContainerWidget.LateTasks.Add(task);
                    dragGesture.Ended      += () => {
                        editor.ContainerWidget.LateTasks.Remove(task);
                        var nodeUnderMouse = WidgetContext.Current.NodeUnderMouse;
                        if (nodeUnderMouse == selectedShortcutsView && hotkeyEditor.Main != Key.Unknown)
                        {
                            if (hotkeyEditor.Main != Key.Unknown)
                            {
                                command.Shortcut = new Shortcut(hotkeyEditor.Modifiers, hotkeyEditor.Main);
                                hotkeyEditor.UpdateButtonCommands();
                                hotkeyEditor.UpdateShortcuts();
                                hotkeyEditor.SetFocus();
                            }
                        }
                        else if (nodeUnderMouse as KeyboardButton != null)
                        {
                            var button = nodeUnderMouse as KeyboardButton;
                            if (Shortcut.ValidateMainKey(button.Key) && !button.Key.IsModifier())
                            {
                                command.Shortcut = new Shortcut(hotkeyEditor.Modifiers, button.Key);
                                hotkeyEditor.UpdateButtonCommands();
                                hotkeyEditor.UpdateShortcuts();
                                hotkeyEditor.SetFocus();
                            }
                        }
                    };
                }
            }
        }
Esempio n. 19
0
        private Widget CreateKeyboardPane()
        {
            var hotkeyEditor = new HotkeyEditor();
            var pane         = new Widget {
                Layout = new VBoxLayout {
                    Spacing = 10
                },
                Padding = contentPadding
            };

            pane.Awoke += node => hotkeyEditor.SetFocus();

            var profileLabel = new ThemedSimpleText("Profile: ")
            {
                VAlignment = VAlignment.Center,
                HAlignment = HAlignment.Right,
                LayoutCell = new LayoutCell(Alignment.RightCenter, 0)
            };
            var profilePicker = new ThemedDropDownList();

            profilePicker.TextWidget.Padding = new Thickness(3, 0);

            var exportButton = new ThemedButton("Export...");

            exportButton.Clicked = () => {
                var dlg = new FileDialog {
                    Mode            = FileDialogMode.Save,
                    InitialFileName = currentProfile.Name
                };
                if (dlg.RunModal())
                {
                    currentProfile.Save(dlg.FileName);
                }
            };
            var importButton = new ThemedButton("Import...");

            importButton.Clicked = () => {
                var dlg = new FileDialog {
                    Mode = FileDialogMode.Open
                };
                if (dlg.RunModal())
                {
                    string name = Path.GetFileName(dlg.FileName);
                    if (HotkeyRegistry.Profiles.Any(i => i.Name == name))
                    {
                        if (new AlertDialog($"Profile with name \"{name}\" already exists. Do you want to rewrite it?", "Yes", "Cancel").Show() != 0)
                        {
                            return;
                        }
                        else
                        {
                            profilePicker.Items.Remove(profilePicker.Items.First(i => i.Text == name));
                        }
                    }
                    var profile = HotkeyRegistry.CreateProfile(Path.GetFileName(dlg.FileName));
                    profile.Load(dlg.FileName);
                    profile.Save();
                    HotkeyRegistry.Profiles.Add(profile);
                    profilePicker.Items.Add(new CommonDropDownList.Item(profile.Name, profile));
                    profilePicker.Value = profile;
                }
            };
            var deleteButton = new ThemedButton("Delete");

            deleteButton.Clicked = () => {
                if (new AlertDialog($"Are you sure you want to delete profile \"{currentProfile.Name}\"?", "Yes", "Cancel").Show() == 0)
                {
                    currentProfile.Delete();
                    profilePicker.Items.Remove(profilePicker.Items.First(i => i.Value == currentProfile));
                    profilePicker.Index           = 0;
                    HotkeyRegistry.CurrentProfile = profilePicker.Value as HotkeyProfile;
                    foreach (var command in HotkeyRegistry.CurrentProfile.Commands)
                    {
                        command.Command.Shortcut = new Shortcut(Key.Unknown);
                    }
                }
            };

            var categoryLabel = new ThemedSimpleText("Commands: ")
            {
                VAlignment = VAlignment.Center,
                HAlignment = HAlignment.Right,
                LayoutCell = new LayoutCell(Alignment.RightCenter, 0)
            };
            var categoryPicker = new ThemedDropDownList();

            categoryPicker.TextWidget.Padding = new Thickness(3, 0);

            var allShortcutsView = new ThemedScrollView();

            allShortcutsView.Content.Padding = contentPadding;
            allShortcutsView.Content.Layout  = new VBoxLayout {
                Spacing = 8
            };

            var selectedShortcutsView = new ThemedScrollView();

            selectedShortcutsView.Content.Padding = contentPadding;
            selectedShortcutsView.Content.Layout  = new VBoxLayout {
                Spacing = 4
            };

            hotkeyEditor.SelectedShortcutChanged = () => {
                selectedShortcutsView.Content.Nodes.Clear();
                var commands = hotkeyEditor.SelectedCommands.ToLookup(i => i.CategoryInfo);
                foreach (var category in commands)
                {
                    selectedShortcutsView.Content.AddNode(new ThemedSimpleText {
                        Text       = category.Key.Title,
                        VAlignment = VAlignment.Center,
                        Color      = Theme.Colors.GrayText
                    });
                    foreach (var command in category)
                    {
                        var shortcut = new ThemedSimpleText {
                            Text       = command.Shortcut.ToString(),
                            VAlignment = VAlignment.Center,
                            LayoutCell = new LayoutCell(Alignment.LeftCenter, 1)
                        };
                        var name = new ThemedSimpleText {
                            Text       = command.Title,
                            VAlignment = VAlignment.Center,
                            LayoutCell = new LayoutCell(Alignment.LeftCenter, 2)
                        };
                        var deleteShortcutButton = new ThemedTabCloseButton {
                            LayoutCell = new LayoutCell(Alignment.LeftCenter, 0),
                            Clicked    = () => {
                                command.Shortcut = new Shortcut();
                                hotkeyEditor.UpdateButtonCommands();
                                hotkeyEditor.UpdateShortcuts();
                            }
                        };
                        selectedShortcutsView.Content.AddNode(new Widget {
                            Layout = new TableLayout {
                                Spacing = 4, RowCount = 1, ColumnCount = 3
                            },
                            Nodes   = { shortcut, name, deleteShortcutButton },
                            Padding = new Thickness(15, 0)
                        });
                    }
                }
                selectedShortcutsView.ScrollPosition = allShortcutsView.MinScrollPosition;
            };

            var filterBox = new ThemedEditBox {
                MaxWidth = 200
            };

            filterBox.AddChangeWatcher(() => filterBox.Text, text => {
                UpdateAllShortcutsView(allShortcutsView, selectedShortcutsView, hotkeyEditor, text.ToLower());
                allShortcutsView.ScrollPosition = allShortcutsView.MinScrollPosition;
            });

            categoryPicker.Changed += args => {
                hotkeyEditor.Category = (args.Value as CommandCategoryInfo);
                hotkeyEditor.SetFocus();
                int index = -1;
                foreach (var node in allShortcutsView.Content.Nodes.SelectMany(i => i.Nodes))
                {
                    var button = node as ThemedExpandButton;
                    if (button == null)
                    {
                        continue;
                    }
                    index++;
                    if (index == args.Index)
                    {
                        if (!button.Expanded)
                        {
                            button.Clicked?.Invoke();
                        }
                        allShortcutsView.ScrollPosition = button.ParentWidget.Position.Y;
                        break;
                    }
                }
            };

            profilePicker.Changed += args => {
                var profile = args.Value as HotkeyProfile;
                if (profile != null)
                {
                    hotkeyEditor.Profile = profile;
                    filterBox.Text       = null;
                    UpdateAllShortcutsView(allShortcutsView, selectedShortcutsView, hotkeyEditor, filterBox.Text);
                    deleteButton.Enabled = profile.Name != HotkeyRegistry.DefaultProfileName && profilePicker.Items.Count > 1;
                    categoryPicker.Items.Clear();
                    foreach (var category in profile.Categories)
                    {
                        categoryPicker.Items.Add(new CommonDropDownList.Item(category.Title, category));
                    }
                    categoryPicker.Value = null;
                    categoryPicker.Value = profile.Categories.First();
                    currentProfile       = profile;
                }
            };
            UpdateProfiles(profilePicker);

            HotkeyRegistry.Reseted = () => UpdateProfiles(profilePicker);

            pane.AddNode(new Widget {
                Layout = new TableLayout {
                    Spacing = 4, RowCount = 2, ColumnCount = 3
                },
                Nodes =
                {
                    profileLabel,  profilePicker,
                    new Widget {
                        Layout = new HBoxLayout {
                            Spacing = 4
                        },
                        Nodes = { exportButton,importButton, deleteButton               }
                    },
                    categoryLabel, categoryPicker
                },
                LayoutCell = new LayoutCell {
                    StretchY = 0
                }
            });

            pane.AddNode(hotkeyEditor);
            pane.AddNode(new Widget {
                Layout = new HBoxLayout {
                    Spacing = 12
                },
                Nodes =
                {
                    new Widget              {
                        Layout = new VBoxLayout{
                            Spacing = 4
                        },
                        Nodes =
                        {
                            new Widget      {
                                Layout = new HBoxLayout{
                                    Spacing = 8
                                },
                                Nodes =
                                {
                                    new ThemedSimpleText("Search: ")
                                    {
                                        VAlignment = VAlignment.Center,
                                        LayoutCell = new LayoutCell(Alignment.LeftCenter, 0)
                                    },
                                    filterBox
                                },
                                LayoutCell = new LayoutCell{
                                    StretchY = 0
                                }
                            },
                            new ThemedFrame {
                                Nodes  =    { allShortcutsView      },
                                Layout = new VBoxLayout()
                            }
                        }
                    },
                    new Widget              {
                        Layout = new VBoxLayout{
                            Spacing = 4
                        },
                        Nodes =
                        {
                            new ThemedSimpleText("Selected commands:")
                            {
                                LayoutCell = new LayoutCell{
                                    StretchY = 0
                                }
                            },
                            new ThemedFrame {
                                Nodes  =    { selectedShortcutsView },
                                Layout = new VBoxLayout()
                            }
                        }
                    }
                }
            });

            return(pane);
        }
        private ThemedScrollView CreateScrollView()
        {
            scrollView = new ThemedScrollView();
            scrollView.Behaviour.Content.Padding    = new Thickness(4);
            scrollView.Behaviour.Content.Layout     = new VBoxLayout();
            scrollView.Behaviour.Content.LayoutCell = new LayoutCell(Alignment.Center);
            Rectangle calcRect(Widget w)
            {
                var wp = w.ParentWidget;
                var p  = wp.Padding;

                return(new Rectangle(
                           -w.Position + Vector2.Zero - new Vector2(p.Left, p.Top),
                           -w.Position + wp.Size + new Vector2(p.Right, p.Bottom)
                           ));
            }

            scrollView.Content.CompoundPresenter.Add(new SyncDelegatePresenter <Widget>((w) => {
                w.PrepareRendererState();
                var rect = calcRect(w);
                Renderer.DrawRect(rect.A, rect.B, Theme.Colors.GrayBackground.Transparentify(0.9f));
            }));
            scrollView.Content.CompoundPostPresenter.Add(new SyncDelegatePresenter <Widget>((w) => {
                w.PrepareRendererState();
                var rect = calcRect(w);
                Renderer.DrawRectOutline(rect.A, rect.B, Theme.Colors.ControlBorder);
            }));
            foreach (var key in triggers.Keys)
            {
                groupSelection[key] = new Queue <string>();
                checkBoxes[key]     = new Dictionary <string, ThemedCheckBox>();
                var expandButton = new ThemedExpandButton {
                    MinMaxSize = Vector2.One * 20f,
                    LayoutCell = new LayoutCell(Alignment.LeftCenter),
                    Expanded   = true
                };
                var groupLabel = new ThemedSimpleText {
                    Text           = key,
                    VAlignment     = VAlignment.Center,
                    LayoutCell     = new LayoutCell(Alignment.Center),
                    ForceUncutText = false,
                    HitTestTarget  = true
                };
                var header = new Widget {
                    Layout     = new HBoxLayout(),
                    LayoutCell = new LayoutCell(Alignment.Center),
                    Padding    = new Thickness(4),
                    Nodes      =
                    {
                        expandButton,
                        groupLabel
                    }
                };
                var wrapper = new Frame {
                    Padding = new Thickness(4),
                    Layout  = new VBoxLayout(),
                    Visible = true
                };
                expandButton.Clicked += () => {
                    wrapper.Visible = !wrapper.Visible;
                };
                groupLabel.Clicked += () => {
                    wrapper.Visible       = !wrapper.Visible;
                    expandButton.Expanded = !expandButton.Expanded;
                };
                foreach (var trigger in triggers[key])
                {
                    wrapper.AddNode(CreateTriggerSelectionWidget(trigger, key));
                }
                scrollView.Content.AddNode(new Widget {
                    Layout     = new VBoxLayout(),
                    LayoutCell = new LayoutCell(Alignment.Center),
                    Padding    = new Thickness(4),
                    Nodes      =
                    {
                        header,
                        wrapper
                    }
                });
            }
            return(scrollView);
        }