예제 #1
0
        /// <inheritdoc />
        public override void OnApplyTemplate()
        {
            this.UnSubscribeEvents();

            this.DropDownPopup = this.GetTemplateChild("PART_Popup") as Popup;

            if (this.DropDownPopup is not null)
            {
                KeyboardNavigation.SetDirectionalNavigation(this.DropDownPopup, KeyboardNavigationMode.Cycle);
                KeyboardNavigation.SetTabNavigation(this.DropDownPopup, KeyboardNavigationMode.Continue);
            }

            this.resizeVerticalThumb = this.GetTemplateChild("PART_ResizeVerticalThumb") as Thumb;

            this.resizeBothThumb = this.GetTemplateChild("PART_ResizeBothThumb") as Thumb;

            this.scrollViewer = this.GetTemplateChild("PART_ScrollViewer") as ScrollViewer;

            this.buttonBorder = this.GetTemplateChild("PART_ButtonBorder") as UIElement;

            this.dropDownBorder = this.GetTemplateChild("PART_DropDownBorder") as Border;

            base.OnApplyTemplate();

            this.SubscribeEvents();
        }
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _BackgroundCanvas         = (Canvas)GetTemplateChild(BackgroundCanvasName);
            _TextOverlaysCanvas       = (CanvasControl)GetTemplateChild(TextOverlaysCanvasName);
            _SelectionHighlightBorder = (Border)GetTemplateChild(SelectionHighlightBorderName);
            _CursorIndicatorRectangle = (Rectangle)GetTemplateChild(CursorIndicatorRectangleName);
            _SyntaxErrorToolTip       = (TeachingTip)GetTemplateChild(SyntaxErrorToolTipName);
            ContentScroller           = (ScrollViewer)GetTemplateChild(ContentScrollerName);
            ContentElement            = (ContentPresenter)GetTemplateChild(ContentElementName);

            Guard.IsNotNull(_BackgroundCanvas, nameof(BackgroundCanvasName));
            Guard.IsNotNull(_TextOverlaysCanvas, nameof(TextOverlaysCanvasName));
            Guard.IsNotNull(_SelectionHighlightBorder, nameof(SelectionHighlightBorderName));
            Guard.IsNotNull(_CursorIndicatorRectangle, nameof(CursorIndicatorRectangleName));
            Guard.IsNotNull(_SyntaxErrorToolTip, SyntaxErrorToolTipName);
            Guard.IsNotNull(ContentScroller, ContentScrollerName);
            Guard.IsNotNull(ContentElement, ContentElementName);

            _BackgroundCanvas.SizeChanged       += BackgroundCanvas_SizeChanged;
            _TextOverlaysCanvas.CreateResources += _TextOverlaysCanvas_CreateResources;
            _TextOverlaysCanvas.Draw            += TextOverlaysCanvas_Draw;
            _SyntaxErrorToolTip.Closed          += delegate { ContentScroller.IsHitTestVisible = true; };
            ContentScroller.Loaded     += ContentElement_Loaded;
            ContentElement.SizeChanged += ContentElement_SizeChanged;

            ContentScroller.StartExpressionAnimation(_TextOverlaysCanvas, Axis.X, VisualProperty.Offset);
            ContentScroller.StartExpressionAnimation(_TextOverlaysCanvas, Axis.Y, VisualProperty.Offset);
            ContentScroller.StartExpressionAnimation(_SelectionHighlightBorder, Axis.Y, VisualProperty.Offset);
            ContentScroller.StartExpressionAnimation(_CursorIndicatorRectangle, Axis.X, VisualProperty.Offset);
            ContentScroller.StartExpressionAnimation(_CursorIndicatorRectangle, Axis.Y, VisualProperty.Offset);

            UpdateVisualElementsOnThemeChanged(SyntaxHighlightTheme);
        }
예제 #3
0
        private void InternalSetContent(UIElement content)
        {
            if (_rootVisual == null)
            {
                _rootBorder = new Border();
                CoreServices.Instance.PutVisualRoot(_rootBorder);
                _rootVisual = CoreServices.Instance.MainRootVisual;

                if (_rootVisual == null)
                {
                    throw new InvalidOperationException("The root visual could not be created.");
                }

                CoreWindow.SetInvalidateRender(_rootVisual.XamlRoot.QueueInvalidateRender);

                UIElement.LoadingRootElement(_rootVisual);

                Compositor.RootVisual = _rootVisual.Visual;

                _rootVisual?.XamlRoot.InvalidateMeasure();

                UIElement.RootElementLoaded(_rootVisual);
            }

            if (_rootBorder != null)
            {
                _rootBorder.Child = _content = content;
            }
        }
 private void InitializeComponent()
 {
     AvaloniaXamlLoader.Load(this);
     _DropState = this.Find <TextBlock>("DropState");
     _DragState = this.Find <TextBlock>("DragState");
     _DragMe    = this.Find <Border>("DragMe");
 }
예제 #5
0
        private void InternalSetContent(UIElement content)
        {
            if (_window == null)
            {
                _rootBorder = new Border();
                _popupRoot  = new PopupRoot();

                _window = new Grid
                {
                    IsVisualTreeRoot = true,
                    Children         =
                    {
                        _rootBorder,
                        _popupRoot
                        // Message Dialog => Those are currently using Popup, but they be upper
                        // Drag and drop => Those are added only when needed (they are actually not part of the WinUI visual tree and would have a negative perf impact)
                    }
                };

                UIElement.LoadingRootElement(_window);

                Compositor.RootVisual = _window.Visual;

                UIElement.RootElementLoaded(_window);
            }

            if (_rootBorder != null)
            {
                _rootBorder.Child = _content = content;
            }
        }
예제 #6
0
        /// <inheritdoc />
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            this.HeaderContentHost = this.GetTemplateChild("PART_HeaderContentHost") as FrameworkElement;

            this.contentContainer = this.GetTemplateChild("PART_ContentContainer") as Border;
        }
예제 #7
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (_popup is PopupBase oldPopup)
            {
                oldPopup.CustomLayouter = null;
            }

            _popup                = this.GetTemplateChild("Popup") as IPopup;
            _popupBorder          = this.GetTemplateChild("PopupBorder") as Border;
            _contentPresenter     = this.GetTemplateChild("ContentPresenter") as ContentPresenter;
            _placeholderTextBlock = this.GetTemplateChild("PlaceholderTextBlock") as TextBlock;

            if (_popup is PopupBase popup)
            {
                popup.CustomLayouter = new DropDownLayouter(this, popup);

                popup.BindToEquivalentProperty(this, nameof(LightDismissOverlayMode));
                popup.BindToEquivalentProperty(this, nameof(LightDismissOverlayBackground));
            }

            UpdateHeaderVisibility();
            UpdateContentPresenter();

            if (_contentPresenter != null)
            {
                _contentPresenter.SynchronizeContentWithOuterTemplatedParent = false;

                var thisRef = (this as IWeakReferenceProvider).WeakReference;
                _contentPresenter.DataContextChanged += (snd, evt) =>
                {
                    if (thisRef.Target is ComboBox that)
                    {
                        // The ContentPresenter will automatically clear its local DataContext
                        // on first load.
                        //
                        // When there's no selection, this will cause this ContentPresenter to
                        // received the same DataContext as the ComboBox itself, which could
                        // lead to strange result or errors.
                        //
                        // See comments in ContentPresenter.ResetDataContextOnFirstLoad() method.
                        // Fixed in this PR: https://github.com/unoplatform/uno/pull/1465

                        if (evt.NewValue != null && that.SelectedItem == null && that._contentPresenter != null)
                        {
                            that._contentPresenter.DataContext = null;                             // Remove problematic inherited DataContext
                        }
                    }
                };

                UpdateCommonStates();
            }
        }
예제 #8
0
        /// <inheritdoc />
        public override void OnApplyTemplate()
        {
            this.dropDownButton = this.GetTemplateChild("PART_ToggleButton") as ToggleButton;
            if (this.dropDownButton is ISimplifiedStateControl control)
            {
                control.UpdateSimplifiedState(this.IsSimplified);
            }

            this.DropDownPopup = this.GetTemplateChild("PART_Popup") as Popup;

            if (this.resizeVerticalThumb is not null)
            {
                this.resizeVerticalThumb.DragDelta -= this.OnResizeVerticalDelta;
            }

            this.resizeVerticalThumb = this.GetTemplateChild("PART_ResizeVerticalThumb") as Thumb;
            if (this.resizeVerticalThumb is not null)
            {
                this.resizeVerticalThumb.DragDelta += this.OnResizeVerticalDelta;
            }

            if (this.resizeBothThumb is not null)
            {
                this.resizeBothThumb.DragDelta -= this.OnResizeBothDelta;
            }

            this.resizeBothThumb = this.GetTemplateChild("PART_ResizeBothThumb") as Thumb;
            if (this.resizeBothThumb is not null)
            {
                this.resizeBothThumb.DragDelta += this.OnResizeBothDelta;
            }

            this.menuPanel = this.GetTemplateChild("PART_MenuPanel") as Panel;

            this.snappedImage = this.GetTemplateChild("PART_SelectedImage") as Image;
            this.contentSite  = this.GetTemplateChild("PART_ContentSite") as ContentPresenter;

            if (this.contentBorder is not null)
            {
                this.contentBorder.PreviewMouseDown -= this.OnContentBorderPreviewMouseDown;
            }

            this.contentBorder = this.GetTemplateChild("PART_ContentBorder") as Border;
            if (this.contentBorder is not null)
            {
                this.contentBorder.PreviewMouseDown += this.OnContentBorderPreviewMouseDown;
            }

            this.scrollViewer = this.GetTemplateChild("PART_ScrollViewer") as ScrollViewer;

            this.dropDownBorder = this.GetTemplateChild("PART_DropDownBorder") as Border;

            base.OnApplyTemplate();
        }
예제 #9
0
 /// <summary>
 /// Gets the parts out of the template.
 /// </summary>
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     _shadowOuterStop1  = (GradientStop)GetTemplateChild("PART_ShadowOuterStop1");
     _shadowOuterStop2  = (GradientStop)GetTemplateChild("PART_ShadowOuterStop2");
     _shadowVertical1   = (GradientStop)GetTemplateChild("PART_ShadowVertical1");
     _shadowVertical2   = (GradientStop)GetTemplateChild("PART_ShadowVertical2");
     _shadowHorizontal1 = (GradientStop)GetTemplateChild("PART_ShadowHorizontal1");
     _shadowHorizontal2 = (GradientStop)GetTemplateChild("PART_ShadowHorizontal2");
     _outerGlowBorder   = (Border)GetTemplateChild("PART_OuterGlowBorder");
     UpdateGlowSize(OuterGlowSize);
     UpdateGlowColor(OuterGlowColor);
 }
        /// <inheritdoc/>
        protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
        {
            // Remove any existing events present if the control was previously loaded then unloaded
            ConnectEvents(false);

            AccentDec1Border = e.NameScope.Find <Border>(nameof(AccentDec1Border));
            AccentDec2Border = e.NameScope.Find <Border>(nameof(AccentDec2Border));
            AccentInc1Border = e.NameScope.Find <Border>(nameof(AccentInc1Border));
            AccentInc2Border = e.NameScope.Find <Border>(nameof(AccentInc2Border));

            // Must connect after controls are found
            ConnectEvents(true);

            base.OnApplyTemplate(e);
        }
예제 #11
0
        private void checkedComboBox_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            var toggleButton = (ToggleButton)Template.FindName("toggleButton", this);

            comboBoxBorder = (Border)VisualTreeHelper.GetChild(toggleButton, 0);
            if (delayedBackground != null)
            {
                comboBoxBorder.Background = delayedBackground;
            }
        }
예제 #12
0
        void LoadTemplateItems()
        {
            if (!itemsLoaded)
            {
                ic = (ItemsControl)GetTemplateChild("PART_TabBar");
                sv = (ScrollViewer)GetTemplateChild("PART_TabScroll");
                ch = (Border)GetTemplateChild("PART_Content");

                if (ic != null && sv != null && ch != null)
                {
                    sv.ScrollChanged += sv_ScrollChanged;
                    ic.SizeChanged   += control_SizeChanged;
                    itemsLoaded       = true;
                }
            }
        }
예제 #13
0
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        _backgroundBorder = GetTemplateChild(_partBackgroundName) as Border;

        if (_headerElement is not null)
        {
            _headerElement.SizeChanged -= _headerPanel_SizeChanged;
        }

        _headerElement = GetTemplateChild(_partHeaderName) as FrameworkElement;
        if (_headerElement is not null)
        {
            _headerElement.SizeChanged += _headerPanel_SizeChanged;
        }
    }
예제 #14
0
        /// <summary>
        /// Event handler for when an accent color border is pressed.
        /// This will update the color to the background of the pressed panel.
        /// </summary>
        private void AccentBorder_PointerPressed(object?sender, PointerPressedEventArgs e)
        {
            Border?  border     = sender as Border;
            int      accentStep = 0;
            HsvColor hsvColor   = HsvColor;

            // Get the value component delta
            try
            {
                accentStep = int.Parse(border?.Tag?.ToString() ?? "0", CultureInfo.InvariantCulture);
            }
            catch { }

            if (accentStep != 0)
            {
                // ColorChanged will be invoked in OnPropertyChanged if the value is different
                HsvColor = AccentColorConverter.GetAccent(hsvColor, accentStep);
            }
        }
        /// <summary>
        /// Event handler for when an accent color border is pressed.
        /// This will update the color to the background of the pressed panel.
        /// </summary>
        private void AccentBorder_PointerPressed(object?sender, PointerPressedEventArgs e)
        {
            Border?  border     = sender as Border;
            int      accentStep = 0;
            HsvColor hsvColor   = HsvColor;

            // Get the value component delta
            try
            {
                accentStep = int.Parse(border?.Tag?.ToString() ?? "", CultureInfo.InvariantCulture);
            }
            catch { }

            HsvColor newHsvColor = AccentColorConverter.GetAccent(hsvColor, accentStep);
            HsvColor oldHsvColor = HsvColor;

            HsvColor = newHsvColor;
            OnColorChanged(new ColorChangedEventArgs(oldHsvColor.ToRgb(), newHsvColor.ToRgb()));
        }
        private void checkedEditComboBox_LayoutUpdated(object?sender, EventArgs e)
        {
            //this is the only event I could find firing after OnApplyTemplate().
            if (IsEditable == false)
            {
                throw new Exception("CheckedEditComboBox does not support IsEditable==false. Use CheckedCheckBox instead.");
            }

            if (toggleButton == null || comboBoxBorder != null)
            {
                return;
            }

            comboBoxBorder = (Border)VisualTreeHelper.GetChild(toggleButton, 0);
            if (delayedBackground == null)
            {
                return;
            }

            comboBoxBorder.Background = delayedBackground;
        }
예제 #17
0
        /// <summary>
        /// Gets the template parts out.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _leftGlow   = GetTemplateChild("PART_LeftGlow") as Border;
            _topGlow    = GetTemplateChild("PART_TopGlow") as Border;
            _rightGlow  = GetTemplateChild("PART_RightGlow") as Border;
            _bottomGlow = GetTemplateChild("PART_BottomGlow") as Border;

            _leftGlowStop0   = GetTemplateChild("PART_LeftGlowStop0") as GradientStop;
            _leftGlowStop1   = GetTemplateChild("PART_LeftGlowStop1") as GradientStop;
            _topGlowStop0    = GetTemplateChild("PART_TopGlowStop0") as GradientStop;
            _topGlowStop1    = GetTemplateChild("PART_TopGlowStop1") as GradientStop;
            _rightGlowStop0  = GetTemplateChild("PART_RightGlowStop0") as GradientStop;
            _rightGlowStop1  = GetTemplateChild("PART_RightGlowStop1") as GradientStop;
            _bottomGlowStop0 = GetTemplateChild("PART_BottomGlowStop0") as GradientStop;
            _bottomGlowStop1 = GetTemplateChild("PART_BottomGlowStop1") as GradientStop;

            UpdateGlowColor(InnerGlowColor);
            UpdateGlowSize(InnerGlowSize);
        }
예제 #18
0
        /// <summary>
        /// Gets the UI elements out of the template.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _border = GetTemplateChild("PART_Border") as Border;
            _topLeftContentControl     = GetTemplateChild("PART_TopLeftContentControl") as ContentControl;
            _topRightContentControl    = GetTemplateChild("PART_TopRightContentControl") as ContentControl;
            _bottomRightContentControl = GetTemplateChild("PART_BottomRightContentControl") as ContentControl;
            _bottomLeftContentControl  = GetTemplateChild("PART_BottomLeftContentControl") as ContentControl;

            if (_topLeftContentControl is not null)
            {
                _topLeftContentControl.SizeChanged += ContentControlSizeChanged;
            }

            _topLeftClip     = GetTemplateChild("PART_TopLeftClip") as RectangleGeometry;
            _topRightClip    = GetTemplateChild("PART_TopRightClip") as RectangleGeometry;
            _bottomRightClip = GetTemplateChild("PART_BottomRightClip") as RectangleGeometry;
            _bottomLeftClip  = GetTemplateChild("PART_BottomLeftClip") as RectangleGeometry;

            UpdateClipContent(ClipContent);

            UpdateCornerRadius(CornerRadius);
        }
예제 #19
0
        private void InternalSetContent(UIElement content)
        {
            if (_window == null)
            {
                _rootBorder = new Border();
                _popupRoot  = new PopupRoot();

                _window = new Grid
                {
                    Children = { _rootBorder, _popupRoot }
                };

                UIElement.LoadingRootElement(_window);

                Compositor.RootVisual = _window.Visual;

                UIElement.RootElementLoaded(_window);
            }

            if (_rootBorder != null)
            {
                _rootBorder.Child = _content = content;
            }
        }
예제 #20
0
            public QuickInfoDisplayPanel(
                FrameworkElement?symbolGlyph,
                FrameworkElement?warningGlyph,
                FrameworkElement mainDescription,
                FrameworkElement documentation,
                FrameworkElement typeParameterMap,
                FrameworkElement anonymousTypes,
                FrameworkElement usageText,
                FrameworkElement exceptionText)
            {
                MainDescription  = (TextBlock)mainDescription;
                Documentation    = (TextBlock)documentation;
                TypeParameterMap = (TextBlock)typeParameterMap;
                AnonymousTypes   = (TextBlock)anonymousTypes;
                UsageText        = (TextBlock)usageText;
                ExceptionText    = (TextBlock)exceptionText;

                Orientation = Orientation.Vertical;

                Border?symbolGlyphBorder = null;

                if (symbolGlyph != null)
                {
                    symbolGlyph.Margin = new Thickness(1, 1, 3, 1);
                    symbolGlyphBorder  = new Border()
                    {
                        BorderThickness   = new Thickness(0),
                        BorderBrush       = Brushes.Transparent,
                        VerticalAlignment = VerticalAlignment.Top,
                        Child             = symbolGlyph
                    };
                }

                mainDescription.Margin = new Thickness(1);
                var mainDescriptionBorder = new Border()
                {
                    BorderThickness   = new Thickness(0),
                    BorderBrush       = Brushes.Transparent,
                    VerticalAlignment = VerticalAlignment.Center,
                    Child             = mainDescription
                };

                var symbolGlyphAndMainDescriptionDock = new DockPanel()
                {
                    LastChildFill       = true,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Background          = Brushes.Transparent
                };

                if (symbolGlyphBorder != null)
                {
                    symbolGlyphAndMainDescriptionDock.Children.Add(symbolGlyphBorder);
                }

                symbolGlyphAndMainDescriptionDock.Children.Add(mainDescriptionBorder);

                if (warningGlyph != null)
                {
                    warningGlyph.Margin = new Thickness(1, 1, 3, 1);
                    var warningGlyphBorder = new Border()
                    {
                        BorderThickness     = new Thickness(0),
                        BorderBrush         = Brushes.Transparent,
                        VerticalAlignment   = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Right,
                        Child = warningGlyph
                    };

                    symbolGlyphAndMainDescriptionDock.Children.Add(warningGlyphBorder);
                }

                Children.Add(symbolGlyphAndMainDescriptionDock);
                Children.Add(documentation);
                Children.Add(usageText);
                Children.Add(typeParameterMap);
                Children.Add(anonymousTypes);
                Children.Add(exceptionText);
            }
예제 #21
0
            public QuickInfoDisplayPanel(
                Control?symbolGlyph,
                Control?warningGlyph,
                Control mainDescription,
                Control documentation,
                Control typeParameterMap,
                Control anonymousTypes,
                Control usageText,
                Control exceptionText)
            {
                Orientation = Orientation.Vertical;

                Border?symbolGlyphBorder = null;

                if (symbolGlyph != null)
                {
                    symbolGlyph.Margin = new Thickness(1, 1, 3, 1);
                    symbolGlyphBorder  = new Border()
                    {
                        BorderThickness   = new Thickness(),
                        BorderBrush       = Brushes.Transparent,
                        VerticalAlignment = Avalonia.Layout.VerticalAlignment.Top,
                        Child             = symbolGlyph
                    };
                }

                mainDescription.Margin = new Thickness(1);
                var mainDescriptionBorder = new Border()
                {
                    BorderThickness   = new Thickness(),
                    BorderBrush       = Brushes.Transparent,
                    VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
                    Child             = mainDescription
                };

                var symbolGlyphAndMainDescriptionDock = new DockPanel()
                {
                    LastChildFill       = true,
                    HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Stretch,
                    Background          = Brushes.Transparent
                };

                if (symbolGlyphBorder != null)
                {
                    symbolGlyphAndMainDescriptionDock.Children.Add(symbolGlyphBorder);
                }

                symbolGlyphAndMainDescriptionDock.Children.Add(mainDescriptionBorder);

                if (warningGlyph != null)
                {
                    warningGlyph.Margin = new Thickness(1, 1, 3, 1);
                    var warningGlyphBorder = new Border()
                    {
                        BorderThickness     = new Thickness(),
                        BorderBrush         = Brushes.Transparent,
                        VerticalAlignment   = Avalonia.Layout.VerticalAlignment.Center,
                        HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
                        Child = warningGlyph
                    };

                    symbolGlyphAndMainDescriptionDock.Children.Add(warningGlyphBorder);
                }

                Children.Add(symbolGlyphAndMainDescriptionDock);
                Children.Add(documentation);
                Children.Add(usageText);
                Children.Add(typeParameterMap);
                Children.Add(anonymousTypes);
                Children.Add(exceptionText);
            }
예제 #22
0
 private void InitializeComponent()
 {
     AvaloniaXamlLoader.Load(this);
     expValueTip = this.FindControl <Border>("ExpValueTip");
     lyricBox    = this.FindControl <LyricBox>("LyricBox");
 }
예제 #23
0
 public Area(IRegion region, Border?border = null, Scrollbars?scrollbars = null)
     : base(region)
 {
     this.border     = border;
     this.scrollbars = scrollbars;
 }
예제 #24
0
 public Area(int row, int col, int width, int height, StyleIndex styleIndex = StyleIndex.Default, Border?border = null, Scrollbars?scrollbars = null)
     : base(row, col, width, height, styleIndex)
 {
     this.border     = border;
     this.scrollbars = scrollbars;
 }
 public static void Initialize(Window window, Border root)
 {
     MainWindow = window;
     Root       = root;
 }
예제 #26
0
 public Window(TViewModel viewModel, IRegion region, Border?border = null, Scrollbars?scrollbars = null)
     : this(viewModel, region.row, region.col, region.width, region.height, region.styleIndex, border, scrollbars)
 {
 }
예제 #27
0
        public Window(TViewModel viewModel, int row, int col, int width, int height, StyleIndex styleIndex = StyleIndex.Window, Border?border = null, Scrollbars?scrollbars = null)
            : base(row, col, width, height, styleIndex, border, scrollbars)
        {
            this.state     = State.Hide;
            this.viewModel = viewModel;

            if (this.viewModel == null)
            {
                throw new ArgumentException("The 'viewModel' must an IViewModel successor!", nameof(this.viewModel));
            }

            this.state = State.Editable;                                                               // default state
        }
예제 #28
0
 public ConsoleFormattingOptions(Border?borderSettings = null, bool singleLine = false)
 {
     BorderSettings = borderSettings ?? new Border(0, '\0', '-');
     SingleLine     = singleLine;
 }
예제 #29
0
 public Window(TViewModel viewModel, int row, int col, int width, int height, Border?border = null, Scrollbars?scrollbars = null, StyleIndex styleIndex = StyleIndex.Window)
     : this(viewModel, row, col, width, height, styleIndex, border, scrollbars)
 {
 }
예제 #30
0
        //public static ElementDescriptionInfo? GetDescription(Type type)
        //{
        //  var attribute = type.GetTypeInfo().GetCustomAttribute<ElementDescriptionAttribute>();

        //  if (attribute == null)
        //  {
        //    return null;
        //  }
        //  else
        //  {
        //    return attribute.description;
        //  }
        //}

        internal void DisplayPart(ref DisplayConsolePartInfo partInfo)
        {
            if ((partInfo.width < 1) || (partInfo.height < 1))
            {
                return;                                                                           // there is no work to do
            }

            Debug.Assert(actualWindow != null);

            bool   isActualWindow  = ReferenceEquals(partInfo.region, actualWindow);
            bool   isActualElement = ReferenceEquals(partInfo.region, actualWindow.actualElement);
            bool   isActualItem    = isActualWindow || isActualElement;
            string displayText     = isActualItem ? partInfo.editText : partInfo.displayText;

            if (isActualElement)
            {
                SetVirtualConsoleCursorPosition(ref partInfo);
            }

            if (isActualItem)
            {
                var styleActual = styles[isActualWindow ? actualWindow.styleIndexActualWindow : actualWindow.styleIndexActualElement];

                if (styleActual.foreground != WinColor.None)
                {
                    partInfo.style.foreground = styleActual.foreground;
                }

                if (styleActual.background != WinColor.None)
                {
                    partInfo.style.background = styleActual.background;
                }
            }

            if (displayText == null)
            { // Only paint area by space
                var text = new string(' ', partInfo.width);

                for (int rowLoop = 0; rowLoop < partInfo.height; rowLoop++)
                {
                    this.virtualConsole.Write(partInfo.row + rowLoop, partInfo.col, text, ref partInfo.style);
                }

                Border?partInfoBorder = partInfo.border;

                if (isActualItem)
                {
                    Border?borderActual = partInfo.borderActual;

                    if (borderActual != null)
                    {
                        partInfoBorder = borderActual;
                    }
                }

                if (partInfoBorder != null)
                {
                    var border = (Border)partInfoBorder;

                    if (border.isVisible())
                    {
                        int lastCol     = partInfo.col + partInfo.width - 1;
                        int lastRow     = partInfo.row + partInfo.height - 1;
                        var borderStyle = styles[border.styleIndex];

                        if (borderStyle.foreground == WinColor.None)
                        {
                            borderStyle.foreground = partInfo.style.foreground;
                        }

                        if (borderStyle.background == WinColor.None)
                        {
                            borderStyle.background = partInfo.style.background;
                        }

                        if (border.topLeft != '\0')
                        {
                            this.virtualConsole.Write(partInfo.row, partInfo.col, border.topLeft.ToString(), ref borderStyle);
                        }

                        if (border.topRight != '\0')
                        {
                            this.virtualConsole.Write(partInfo.row, lastCol, border.topRight.ToString(), ref borderStyle);
                        }

                        if (border.bottomLeft != '\0')
                        {
                            this.virtualConsole.Write(lastRow, partInfo.col, border.bottomLeft.ToString(), ref borderStyle);
                        }

                        if (border.bottomRight != '\0')
                        {
                            this.virtualConsole.Write(lastRow, lastCol, border.bottomRight.ToString(), ref borderStyle);
                        }

                        if ((border.top != '\0') && (partInfo.width > 2))
                        {
                            var line = new string(border.top, partInfo.width - 2);

                            this.virtualConsole.Write(partInfo.row, partInfo.col + 1, line, ref borderStyle);
                        }

                        if ((border.bottom != '\0') && (partInfo.width > 2))
                        {
                            var line = new string(border.bottom, partInfo.width - 2);

                            this.virtualConsole.Write(lastRow, partInfo.col + 1, line, ref borderStyle);
                        }

                        if ((border.left != '\0') && (partInfo.height > 2))
                        {
                            for (int rowLoop = 1; rowLoop < partInfo.height - 1; rowLoop++)
                            {
                                this.virtualConsole.Write(partInfo.row + rowLoop, partInfo.col, border.left.ToString(), ref borderStyle);
                            }
                        }

                        if ((border.right != '\0') && (partInfo.height > 2))
                        {
                            for (int rowLoop = 1; rowLoop < partInfo.height - 1; rowLoop++)
                            {
                                this.virtualConsole.Write(partInfo.row + rowLoop, lastCol, border.right.ToString(), ref borderStyle);
                            }
                        }
                    }
                }

                if ((partInfo.scrollbars != null) && (partInfo.scrollbarsInfo != null) && (partInfo.width >= 4) && (partInfo.height >= 4))
                {
                    var scrollbars     = (Scrollbars)partInfo.scrollbars;
                    var scrollbarsInfo = partInfo.scrollbarsInfo;

                    int lastCol = partInfo.col + partInfo.width - 1;
                    int lastRow = partInfo.row + partInfo.height - 1;

                    var scrollbarStyle = styles[scrollbars.styleIndex];

                    if (scrollbarStyle.foreground == WinColor.None)
                    {
                        scrollbarStyle.foreground = partInfo.style.foreground;
                    }

                    if (scrollbarStyle.background == WinColor.None)
                    {
                        scrollbarStyle.background = partInfo.style.background;
                    }

                    if (scrollbarsInfo.leftArrowVisible && (scrollbars.horizontalLeft != '\0'))
                    {
                        // TODO
                    }

                    if (scrollbarsInfo.rightArrowVisible && (scrollbars.horizontalRight != '\0'))
                    {
                        // TODO
                    }

                    if (scrollbarsInfo.upArrowVisible && (scrollbars.verticalUp != '\0'))
                    {
                        // TODO
                    }

                    if (scrollbarsInfo.downArrowVisible && (scrollbars.verticalBottom != '\0'))
                    {
                        // TODO
                    }

                    if ((scrollbarsInfo.horizontalPosition != null) && (scrollbars.horizontalLine != '\0') && (partInfo.width >= 5))
                    {
                        // TODO
                    }

                    if ((scrollbarsInfo.verticalPosition != null) && (scrollbars.verticalLine != '\0') && (partInfo.height >= 5))
                    {
                        // TODO
                    }
                }
            }
            else if (partInfo.height == 1)
            { // Only one line
                this.virtualConsole.Write(partInfo.row, partInfo.col, FormattedDisplayText(displayText, partInfo.width), ref partInfo.style);
            }
            else
            { // multiple line
                var lines = displayText.Split('\n');

                for (int rowLoop = 0; rowLoop < partInfo.height; rowLoop++)
                {
                    string text = null;

                    if (rowLoop < lines.Length)
                    {
                        text = lines[rowLoop];
                    }

                    this.virtualConsole.Write(partInfo.row + rowLoop, partInfo.col, FormattedDisplayText(text, partInfo.width), ref partInfo.style);
                }
            }
        }