コード例 #1
0
ファイル: AlertDialog.cs プロジェクト: klenin/Citrus
        public AlertDialog(string text, params string[] buttons)
        {
            if (buttons.Length == 0)
            {
                buttons = new[] { "Ok" };
            }
            window = new Window(new WindowOptions {
                FixedSize = true,
                Title     = "Tangerine",
                Visible   = false,
                Style     = WindowStyle.Dialog
            });
            rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                LayoutBasedWindowSize = true,
                Padding = new Thickness(8),
                Layout  = new VBoxLayout {
                    Spacing = 16
                },
                Nodes =
                {
                    new ThemedSimpleText(text)
                    {
                        Padding = new Thickness(4)
                    },
                    (buttonsPanel = new Widget{
                        Layout = new HBoxLayout{
                            Spacing = 8
                        },
                        LayoutCell = new LayoutCell(Alignment.RightCenter, 1, 0),
                    })
                }
            };
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            var cancelIndex = buttons.ToList().IndexOf("Cancel");

            if (cancelIndex >= 0)
            {
                result = cancelIndex;
                rootWidget.LateTasks.AddLoop(() => {
                    if (rootWidget.Input.ConsumeKeyPress(Key.Escape))
                    {
                        Close(cancelIndex);
                    }
                });
            }
            for (int i = 0; i < buttons.Length; i++)
            {
                var button = new ThemedButton {
                    Text = buttons[i]
                };
                int j = i;
                button.Clicked += () => Close(j);
                buttonsPanel.AddNode(button);
                if (i == 0)
                {
                    button.SetFocus();
                }
            }
        }
コード例 #2
0
        public Result Show(Marker marker, bool canDelete)
        {
            Widget             buttonsPanel;
            Button             deleteButton;
            Button             okButton;
            Button             cancelButton;
            DropDownList       actionSelector;
            EditBox            markerIdEditor;
            ThemedDropDownList jumpToSelector;
            Result             result;
            var window = new Window(new WindowOptions {
                FixedSize = true, Title = "Marker properties", Visible = false, Style = WindowStyle.Dialog
            });

            jumpToSelector = new ThemedDropDownList();
            foreach (var m in Document.Current.Container.Markers)
            {
                jumpToSelector.Items.Add(new ThemedDropDownList.Item(m.Id, m));
            }
            jumpToSelector.Text = marker.JumpTo;
            var rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                LayoutBasedWindowSize = true,
                Padding = new Thickness(8),
                Layout  = new VBoxLayout {
                    Spacing = 16
                },
                Nodes =
                {
                    new Widget  {
                        Layout = new TableLayout{
                            ColCount    = 2,
                            RowCount    = 3,
                            Spacing     = 8,
                            ColDefaults =
                            {
                                new LayoutCell(Alignment.RightCenter, 0.5f, 0),
                                new LayoutCell(Alignment.LeftCenter,     1, 0)
                            }
                        },
                        Nodes =
                        {
                            new ThemedSimpleText("Marker Id"),
                            (markerIdEditor = new ThemedEditBox{
                                Text = marker.Id,                   MinSize= Theme.Metrics.DefaultEditBoxSize * new Vector2(2, 1)
                            }),
                            new ThemedSimpleText("Action"),
                            (actionSelector = new ThemedDropDownList{
                                Items =
                                {
                                    new DropDownList.Item("Play",    MarkerAction.Play),
                                    new DropDownList.Item("Jump",    MarkerAction.Jump),
                                    new DropDownList.Item("Stop",    MarkerAction.Stop),
                                    new DropDownList.Item("Destroy", MarkerAction.Destroy),
                                },
                                Value = marker.Action
                            }),
                            new ThemedSimpleText("Jump to"),
                            jumpToSelector,
                        }
                    },
                    (buttonsPanel = new Widget{
                        Layout = new HBoxLayout{
                            Spacing = 8
                        },
                        LayoutCell = new LayoutCell(Alignment.RightCenter),
                        Nodes =
                        {
                            (okButton     = new ThemedButton("Ok")),
                            (cancelButton = new ThemedButton("Cancel")),
                        }
                    })
                }
            };

            if (canDelete)
            {
                deleteButton = new ThemedButton("Delete");
                buttonsPanel.AddNode(deleteButton);
                deleteButton.Clicked += () => {
                    result = Result.Delete;
                    window.Close();
                };
            }
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            rootWidget.LateTasks.Add(new KeyPressHandler(Key.Escape,
                                                         (input, key) => {
                input.ConsumeKey(key);
                window.Close();
            }));
            okButton.Clicked += () => {
                result = Result.Ok;
                window.Close();
            };
            cancelButton.Clicked += window.Close;
            okButton.SetFocus();
            result = Result.Cancel;
            window.ShowModal();
            if (result == Result.Ok)
            {
                marker.Id     = markerIdEditor.Text;
                marker.Action = (MarkerAction)actionSelector.Value;
                marker.JumpTo = jumpToSelector.Text;
            }
            return(result);
        }
コード例 #3
0
        public ManageRulersDialog()
        {
            Button cancelButton;
            Button okButton;
            var    window = new Window(new WindowOptions {
                Title      = "Manage Rulers",
                Style      = WindowStyle.Dialog,
                ClientSize = new Vector2(300, 200),
                Visible    = false
            });
            var collection = new ObservableCollection <Ruler>(ProjectUserPreferences.Instance.Rulers);
            var lines      = new List <RulerLine>();
            ThemedScrollView container;
            WindowWidget     rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                Padding = new Thickness(8),
                Layout  = new VBoxLayout(),
                Nodes   =
                {
                    (container            = new ThemedScrollView {
                        Padding           = new Thickness        {
                            Right         =           10
                        },
                    }),
                    new Widget {
                        Padding           = new Thickness        {
                            Top           =            10
                        },
                        Layout            = new HBoxLayout       {
                            Spacing       =        8
                        },
                        LayoutCell = new LayoutCell(Alignment.RightCenter),
                        Nodes      =
                        {
                            (okButton     = new ThemedButton     {
                                Text      = "Ok"
                            }),
                            (cancelButton = new ThemedButton     {
                                Text      = "Cancel"
                            }),
                        }
                    }
                }
            };

            container.CompoundPresenter.Add(new SyncDelegatePresenter <Widget>(
                                                w => {
                if (w.Parent == null)
                {
                    return;
                }
                var listView = (ThemedScrollView)w;
                w.PrepareRendererState();
                var i     = (int)(listView.ScrollPosition / RowHeight);
                var start = 0f;
                while (true)
                {
                    float height;
                    if (start == 0f)
                    {
                        height = RowHeight - listView.ScrollPosition % RowHeight;
                    }
                    else
                    {
                        height = start + RowHeight <= w.Size.Y ? RowHeight : w.Size.Y - start;
                    }
                    var color = i % 2 == 0
                                                ? ColorTheme.Current.Inspector.StripeBackground2
                                                : ColorTheme.Current.Inspector.StripeBackground1;
                    Renderer.DrawRect(new Vector2(0, start), new Vector2(w.Size.X, start + height), color);
                    start += height;
                    i++;
                    if (start >= w.Size.Y)
                    {
                        break;
                    }
                }
            }));
            container.Content.Layout = new VBoxLayout {
                Spacing = 4
            };
            var list = new Widget {
                Layout = new VBoxLayout(),
            };

            container.Content.AddNode(list);
            list.Components.Add(new WidgetFactoryComponent <Ruler>(ruler => new RulerRowView(ruler,
                                                                                             // Delete button clicked
                                                                                             () => {
                collection.Remove(ruler);
                container.ScrollPosition = container.ScrollPosition > RowHeight ? container.ScrollPosition - RowHeight : 0;
            },
                                                                                             // Edit button clicked
                                                                                             () => {
                if (ruler.AnchorToRoot)
                {
                    var size = Document.Current.Container.AsWidget.Size / 2;
                    foreach (var line in ruler.Lines)
                    {
                        line.Value += (line.RulerOrientation == RulerOrientation.Horizontal ? size.Y : size.X);
                    }
                }
                collection.Remove(ruler);
                lines.AddRange(ruler.Lines);
            }), collection));
            okButton.Clicked += () => {
                var temp = ProjectUserPreferences.Instance.Rulers.ToList();
                foreach (var ruler in temp.Except(collection))
                {
                    ProjectUserPreferences.Instance.Rulers.Remove(ruler);
                }
                ProjectUserPreferences.Instance.ActiveRuler.Lines.AddRange(lines);
                if (!ProjectUserPreferences.Instance.RulerVisible && lines.Count != 0)
                {
                    (SceneViewCommands.ToggleDisplayRuler as Command)?.Issue();
                }
                Core.UserPreferences.Instance.Save();
                Application.InvalidateWindows();
                window.Close();
            };
            cancelButton.Clicked += () => window.Close();
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            rootWidget.LateTasks.AddLoop(() => {
                if (rootWidget.Input.ConsumeKeyPress(Key.Escape))
                {
                    window.Close();
                    UserPreferences.Instance.Load();
                }
            });
            okButton.SetFocus();
            window.ShowModal();
        }