Widget CreateStyleSelector(IUIStyle uiStyle)
        {
            RadioButtonSet <StyleDefinition> radioButtons = new RadioButtonSet <StyleDefinition>(uiStyle);

            foreach (var style in styles)
            {
                radioButtons.DataItems.Add(style);
            }
            radioButtons.SelectionChanged += (sender, args) =>
            {
                if (radioButtons.LookUpSelectedItem(out var d))
                {
                    Select(d);
                }
            };

            return(new BoxGroup(uiStyle, Orientation.Vertical, 0)
            {
                radioButtons
            });
        }

        void Select(StyleDefinition d)
        {
            UIManager.UIStyle.StyleResolver.StyleRules.Clear();
            UIManager.UIStyle.StyleResolver.StyleRules.AddRange(d.Rules);
            UIManager.UIStyle.StyleSystem.WhitePixel = d.WhitePixel;
            DrawingService.WhitePixel = d.WhitePixel;
        }
示例#2
0
 public Button(IUIStyle style, string text = "", IUITexture iconTex = null) : base(style)
 {
     Content = new IconLabel(style)
     {
         Texture = iconTex, Text = text, Enabled = false, Anchor = AnchoredRect.CreateHorizontallyStretched()
     };
 }
示例#3
0
        public Screen(IInputManager rawInputs,
                      IUIStyle style,
                      IBatchedDrawingService drawingService,
                      IGameWindowService windowService)
        {
            actions = new Queue <Action>();

            DrawingService    = drawingService ?? throw new ArgumentNullException(nameof(drawingService));
            WindowService     = windowService ?? throw new ArgumentNullException(nameof(windowService));
            FocusManager      = new ScreenFocusManager(this);
            MouseHoverManager = new MouseHoverManager();
            Root = new RootPane(this, style);
            style.StyleResolver.AddRoot(Root);

            PopUpManager = new PopupManager(Root);

            inputState = new InputStateImpl();

            eventHandler = new ScreenEventHandling(this, Root, rawInputs);
            eventHandler.AddMousePostProcessor(new PopupClosingEventProcessor(Root));
            eventHandler.AddMousePostProcessor(inputState);
            eventHandler.AddKeyPostProcessor(inputState);

            if (TracingUtil.InputTracing.Switch.ShouldTrace(TraceEventType.Verbose))
            {
                eventHandler.AddKeyPreProcessor(new TracingEventSink <KeyEventData>());
                eventHandler.AddMousePreProcessor(new TracingEventSink <MouseEventData>());
                eventHandler.AddTouchPreProcessor(new TracingEventSink <TouchEventData>());
                eventHandler.AddGamePadPreProcessor(new TracingEventSink <GamePadEventData>());
            }
        }
示例#4
0
        public ListView(IUIStyle style) : base(style)
        {
            selectionChangedSupport = new EventSupport <ListSelectionEventArgs>();
            listViewStyle           = StyleSystem.StylesFor <ListViewStyleDefinition>();

            selectedIndex = -1;

            InternalContent = new ScrollPanel <BoxGroup>(UIStyle)
            {
                Content = new BoxGroup(UIStyle)
                {
                    Orientation = Orientation.Vertical
                }
            };

            DataItems = new ObservableCollection <T>();
            DataItems.CollectionChanged += (s, e) =>
            {
                RebuildDataRenderers();
                InvalidateLayout();
            };

            CreateRenderer = ListView.DefaultCreateRenderer;

            MinHeight = 0;
            MaxHeight = int.MaxValue;
        }
示例#5
0
 public NotebookTabList(IUIStyle style) : base(style)
 {
     activeTabChangedSupport = new EventSupport <EventArgs>();
     allowDragReorder        = true;
     notebookStyle           = StyleSystem.StylesFor <NotebookStyleDefinition>();
     DragState = new DragNDropState(this);
 }
        protected TextEditorWidgetBase(IUIStyle style, IDocumentEditor <TView, TDocument> editor) : base(style, editor)
        {
            if (editor == null)
            {
                throw new ArgumentNullException();
            }

            ActionMap    = new KeyboardActionMap();
            RemoteCarets = new ObservableCollection <ICaret>();
            RemoteCarets.CollectionChanged += OnRemoteCaretsChanged;

            Caret = new Caret <TView, TDocument>(UIStyle, Content);
            Caret.AddNotify(this);
            RaiseChildAdded(0, Caret);

            KeyTyped    += OnKeyTyped;
            KeyPressed  += OnKeyPressed;
            KeyRepeated += OnKeyPressed;

            MouseUp      += OnMouseUp;
            MouseDown    += OnMouseDown;
            MouseDragged += OnMouseDragged;

            Cursor    = MouseCursor.IBeam;
            Focusable = true;
            ReadOnly  = false;

            InstallKeyMap();
        }
示例#7
0
 /// <summary>
 ///   For testing to override the document view used.
 /// </summary>
 /// <param name="style"></param>
 /// <param name="editor"></param>
 public TextField(IUIStyle style, IDocumentEditor <DocumentView <PlainTextDocument>, PlainTextDocument> editor) : base(style, editor)
 {
     WrapText = WrapText.None;
     Content.Document.PushFilter(new LineBreakFilter(Content.ViewFactory.TextProcessingRules));
     Content.Document.PushFilter(new MaxLengthFilter(Content.Document, () => MaxLength));
     Clip = true;
 }
示例#8
0
        public Slider(IUIStyle style) : base(style)
        {
            valueChangedSupport = new EventSupport <EventArgs>();

            sliderHandle = new Button(UIStyle);
            sliderHandle.AddStyleClass(SliderHandleStyleClass);
            sliderHandle.Anchor        = AnchoredRect.CreateLeftAnchored();
            sliderHandle.MouseUp      += OnMouseUp;
            sliderHandle.MouseDown    += OnMouseDown;
            sliderHandle.MouseDragged += OnMouseDragged;

            sliderTrack        = new SliderTrack(UIStyle);
            sliderTrack.Anchor = AnchoredRect.Full;

            Group elements = new Group(UIStyle);

            elements.Anchor = AnchoredRect.Full;
            elements.Add(sliderTrack);
            elements.Add(sliderHandle);

            InternalContent = elements;
            Focusable       = true;

            MinValue = 0;
            MaxValue = 10;
            Step     = 1;
            Value    = 0;
        }
示例#9
0
        public NotebookTab(IUIStyle style) : base(style)
        {
            activationRequestedSupport = new EventSupport <EventArgs>();
            closeRequestedSupport      = new EventSupport <EventArgs>();

            emptyContent = new Label(UIStyle)
            {
                Anchor = AnchoredRect.CreateHorizontallyStretched()
            };

            closeButton = new Button(UIStyle);
            closeButton.AddStyleClass(CloseButtonStyleClass);
            closeButton.Anchor           = AnchoredRect.CreateCentered();
            closeButton.ActionPerformed += OnCloseButtonOnClicked;

            InternalContent = new DockPanel(UIStyle);
            InternalContent.LastChildFill = true;
            InternalContent.Add(closeButton, DockPanelConstraint.Right);
            InternalContent.Add(emptyContent, DockPanelConstraint.Left);

            KeyPressed   += OnKeyPressed;
            MouseClicked += OnMouseClick;

            Focusable = true;
        }
示例#10
0
 public SpinningWheel(IUIStyle style) : base(style)
 {
     fadeInAnim          = new SmoothValue(0, 1, FadeDuration, FadeDelay, AnimationLoop.NoLoop);
     rotationValue       = new LerpValue(0, MathHelper.Pi, 1, AnimationLoop.Loop);
     FadeIn              = true;
     Style.ValueChanged += OnStyleChanged;
 }
示例#11
0
        public static Widget CreateRootPanel(IUIStyle uiStyle)
        {
            var basicDemoPane = new BasicDemoPane(uiStyle);

            var demoPanel = new ScrollPanel(uiStyle)
            {
                VerticalScrollbarMode = ScrollbarMode.None,
                Content = basicDemoPane
            }.DoWith(d => d.AddStyleClass("DemoPanel"));

            // Splitter
            return(new Splitter(uiStyle, Direction.Left)
            {
                Anchor = AnchoredRect.CreateFull(10),
                Collapsable = true,
                Collapsed = true,
                FirstPane = new BoxGroup(uiStyle, Orientation.Vertical, 0)
                {
                    { CreateDemoButton("Basic", demoPanel, basicDemoPane), true },
                    { CreateDemoButton("Notebook", demoPanel, new NotebookPane(uiStyle)), true },
                    { CreateDemoButton("Text Area", demoPanel, new TextAreaPane(uiStyle)), true },
                    { CreateDemoButton("Custom Viewport", demoPanel, new CustomViewportPane(uiStyle)), true }
                },
                SecondPane = demoPanel,
                FirstPaneMinSize = 200
            });
        }
示例#12
0
 public ProgressBar(IUIStyle style) : base(style)
 {
     lerpValue = new LerpValue(0, 0, 0.5f, AnimationLoop.NoLoop);
     Min       = 0;
     Max       = 100;
     Value     = 0;
     Direction = ProgressBarDirection.LeftToRight;
 }
示例#13
0
        public RootPane(IScreenService screen, IUIStyle style) : base(style)
        {
            Screen    = screen;
            glassPane = new GlassPane(UIStyle);

            AddInternalHelper(glassPane, InsertPosition.Front, GlassPaneLayer);
            GlassPaneForPopups = true;
        }
示例#14
0
        // ----------------------------------------------------------------------
        public Grid(IUIStyle style) : base(style)
        {
            widgetsPerPosition = new Dictionary <Point, List <IWidget> >();

            RowConstraints = new ObservableCollection <LengthConstraint>();
            RowConstraints.CollectionChanged += (o, e) => InvalidateLayout();
            ColumnConstraints = new ObservableCollection <LengthConstraint>();
            ColumnConstraints.CollectionChanged += (o, e) => InvalidateLayout();
        }
示例#15
0
 public TextAreaPane(IUIStyle style) : base(style)
 {
     VerticalScrollbarMode = ScrollbarMode.Always;
     Content = new TextArea(UIStyle)
     {
         Text   = LoremIpsum + "\n\n" + LoremIpsum,
         Anchor = AnchoredRect.Full
     };
 }
示例#16
0
        public Slider(IUIStyle style, float min, float max, float initialValue, float step) : this(style)
        {
            MinValue = Math.Min(min, max);
            MaxValue = Math.Max(min, max);
            Step     = step;
            Value    = initialValue;

            MouseUp      += OnMouseUp;
            MouseDown    += OnMouseDown;
            MouseDragged += OnMouseDragged;
        }
示例#17
0
        protected TextWidgetBase(IUIStyle style, IDocumentEditor <TView, TDocument> editor) : base(style)
        {
            textStyles = StyleSystem.StylesFor <TextStyleDefinition>();

            ChildrenChanged += HandleOnChildrenChanged;

            DocumentEditor = editor;
            Content        = DocumentEditor.CreateDocumentView(AnchoredRect.CreateTopAnchored());

            WrapText = WrapText.Auto;
        }
示例#18
0
        Widget CreateContentPane(IUIStyle style)
        {
            var g = new Grid(style);

            g.ColumnConstraints.Add(LengthConstraint.Percentage(100));
            g.RowConstraints.Add(LengthConstraint.Auto);
            g.RowConstraints.Add(LengthConstraint.Relative(1));

            g.Add(CreateStyleSelector(style), new Point(0, 0));
            g.Add(WidgetDemo.CreateRootPanel(style), new Point(0, 1));
            return(g);
        }
示例#19
0
        public KeyBox(IUIStyle style, KeyStroke key) : base(style)
        {
            Content = new TextField(style)
            {
                Enabled = false, ReadOnly = true
            };
            Key = key;

            // does not participate in normal focus traversal
            Focusable = false;

            KeyPressed += OnKeyPressed;
            MouseDown  += OnMouseDown;
        }
示例#20
0
        public TextArea(IUIStyle style, IDocumentEditor <DocumentView <PlainTextDocument>, PlainTextDocument> editor) : base(style, editor)
        {
            ActionMap.Register(new KeyStroke(Keys.Enter), OnEnterPressed);
            ActionMap.Register(new KeyStroke(Keys.PageUp), OnPageUpPressed);
            ActionMap.Register(new KeyStroke(Keys.PageDown), OnPageDownPressed);

            lineNumberRenderer = new LineNumberWidget(UIStyle);
            lineNumberRenderer.AddNotify(this);
            lineNumberRenderer.Anchor       = AnchoredRect.CreateLeftAnchored();
            lineNumberRenderer.DocumentView = Content;
            RaiseChildAdded(0, lineNumberRenderer);

            DisplayLineNumbers  = true;
            Caret.CaretChanged += OnCaretChanged;
        }
示例#21
0
        public Notebook(IUIStyle style) : base(style)
        {
            notebookStyle = StyleSystem.StylesFor <NotebookStyleDefinition>();

            Tabs = new NotebookTabList(UIStyle);
            Tabs.ActiveTabChanged += (s, e) => { panel.Content = Tabs.ActiveTab?.Content; };
            Tabs.AddNotify(this);
            RaiseChildAdded(0, Tabs);

            panel = new ScrollPanel(UIStyle);
            panel.AddNotify(this);
            RaiseChildAdded(1, panel);

            KeyPressed += OnKeyPressed;
        }
        public ListDataItemRenderer(IUIStyle style) : base(style)
        {
            selectionChangedSupport = new EventSupport <ListSelectionEventArgs>();
            Anchor          = AnchoredRect.CreateHorizontallyStretched();
            FocusedChanged += (s, e) =>
            {
                if (Focused)
                {
                    selectionChangedSupport.Raise(this, ListSelectionEventArgs.Adjusted);
                }
            };

            MouseClicked += OnMouseClick;
            KeyPressed   += OnKeyPressed;
        }
示例#23
0
        public OptionPane(IUIStyle style) : base(style)
        {
            actionPerformedSupport = new EventSupport <OptionPaneActionArgs>();
            TitleLabel             = new Label(UIStyle);

            dummyContent = new Label(UIStyle);

            buttonContainer = new Grid(UIStyle);
            buttonContainer.RowConstraints.Add(LengthConstraint.Auto);

            InternalContent = new DockPanel(UIStyle);
            InternalContent.LastChildFill = true;
            InternalContent.Add(TitleLabel, DockPanelConstraint.Top);
            InternalContent.Add(buttonContainer, DockPanelConstraint.Bottom);
            InternalContent.Add(dummyContent, DockPanelConstraint.Left);
        }
示例#24
0
        public ScrollPanel(IUIStyle style) : base(style)
        {
            Scrollbar = new Scrollbar(style)
            {
                ScrollbarMode = ScrollbarMode.Auto
            };
            Scrollbar.AddNotify(this);
            RaiseChildAdded(0, Scrollbar);
            Clip = true;

            MouseClicked += OnMouseClick;
            MouseUp      += OnMouseUp;
            MouseDown    += OnMouseDown;
            MouseWheel   += OnMouseWheel;
            MouseDragged += OnMouseDragged;
        }
示例#25
0
        public Scrollbar(IUIStyle style) : base(style)
        {
            scrollbarPositionChangedSupport = new EventSupport <EventArgs>();
            scrollbarStyle = StyleSystem.StylesFor <ScrollbarStyleDefinition>();

            ScrollUnit = 50 / 120f;
            lerpOffset = new LerpValue(0, 0, 0.5f, AnimationLoop.NoLoop);

            MouseDragged += OnMouseDragged;
            MouseWheel   += OnMouseWheel;
            MouseUp      += OnMouseUp;
            MouseDown    += OnMouseDown;
            MouseClicked += OnMouseClick;

            Thumb = new ScrollbarThumb(UIStyle);
        }
示例#26
0
        public RadioButtonSet(IUIStyle style, IEnumerable <T> items = null) : base(style)
        {
            selectionChangedSupport = new EventSupport <ListSelectionEventArgs>();
            InternalContent         = new BoxGroup(UIStyle)
            {
                Orientation = Orientation.Horizontal
            };
            Renderer = DefaultRenderFunction;

            DataItems = new ObservableCollection <T>();
            if (items != null)
            {
                DataItems.AddRange(items);
            }
            DataItems.CollectionChanged += OnItemsChanged;
        }
示例#27
0
        public Playing(IUIStyle s, Game1 parent, GraphicsDeviceManager man) : base(s)
        {
            mapWidget = new MapWidget(s);
            var exit = new Button(s, "Exit")
            {
                Anchor            = AnchoredRect.CreateFixed(0, 0, 100, 60),
                Color             = Color.Aquamarine,
                OnActionPerformed = (se, a) =>
                {
                    parent.State = Game1.GameState.MainMenu;
                }
            };

            this.Add(mapWidget);
            this.Add(exit);
        }
示例#28
0
        public IconLabel(IUIStyle style) : base(style)
        {
            iconLabelStyle = StyleSystem.StylesFor <IconLabelStyleDefinition>();

            Image = new Image(style)
            {
                Padding = new Insets(), Enabled = false
            };
            Image.AddNotify(this);
            RaiseChildAdded(0, Image);

            Label = new Label(style)
            {
                Padding = new Insets(), Enabled = false
            };
            Label.AddNotify(this);
            RaiseChildAdded(1, Label);
        }
示例#29
0
        public ButtonBase(IUIStyle style) : base(style)
        {
            buttonStyle             = StyleSystem.StylesFor <ButtonStyleDefinition>();
            actionPerformedSupport  = new EventSupport <EventArgs>();
            selectionChangedSupport = new EventSupport <EventArgs>();

            pressedAnimation = new SmoothValue(1f, 0f, 0.1f);
            pressedAnimation.FinishAnimation();

            Focusable = true;

            FocusedChanged += (sender, args) => ResetPressState();

            MouseDown    += OnMouseDown;
            MouseUp      += OnMouseUp;
            MouseClicked += OnMouseClick;
            KeyPressed   += OnKeyPressed;
            KeyReleased  += OnKeyReleased;
        }
示例#30
0
        public MainMenu(IUIStyle s, Game1 parent) : base(s)
        {
            var lab = new Label(s, "Welcome to the game")
            {
                Anchor = AnchoredRect.CreateCentered()
            };

            var play = new Button(s, "Play")
            {
                Anchor            = AnchoredRect.CreateFixed(0, 0, 100, 60),
                Color             = Color.Aquamarine,
                OnActionPerformed = (se, a) =>
                {
                    parent.State = Game1.GameState.Playing;
                }
            };

            this.Add(lab);
            this.Add(play);
        }