Exemple #1
0
 private void InsertChildInside(TvComponent child)
 {
     //if (_thisComponent.Viewport != null)
     //{
     //    child.UpdateViewport(_thisComponent.Viewport.Inner(child.Viewport), addIfNotExists: true);
     //}
 }
        public IComponentMetadata Add(TvComponent component)
        {
            var metadata = _parent.Add(component);

            _myComponents.Add(component);
            OnComponentAdded(component.Metadata);
            return(metadata);
        }
Exemple #3
0
 public TvStackPanel(IComponentTree root, string name = null)
 {
     _childs        = new KeyedComponentsTree <int>(root);
     _thisComponent = new TvComponent <StackLayout>(new StackLayout(), name ?? $"TvStackPanel_{Guid.NewGuid()}");
     Name           = _thisComponent.Name;
     _thisComponent.Metadata.ViewportChanged += OnViewportChange;
     _childs.ComponentAdded   += OnChildAdded;
     _childs.ComponentRemoved += OnChildRemoved;
 }
Exemple #4
0
        private void CreateNeededBehaviors(TvComponent component)
        {
            var behaviorsToBeCreated = component.BehaviorsMetadatas.Where(bm => !bm.Created).ToList();

            foreach (var bm in behaviorsToBeCreated)
            {
                bm.CreateBehavior(Engine.ServiceProvider);
            }
        }
Exemple #5
0
 public TvCanvas(IComponentTree root, string name = null)
 {
     _root          = root;
     _childs        = new ListComponentTree(root);
     _thisComponent = new TvComponent <object>(new Object(), name ?? $"TvCanvas_{Guid.NewGuid()}");
     Name           = _thisComponent.Name;
     _thisComponent.Metadata.ViewportChanged += OnViewportChange;
     _childs.ComponentAdded   += OnChildAdded;
     _childs.ComponentRemoved += OnChildRemoved;
     root.ComponentRemoved    += OnRootRemoved;
 }
        public bool Remove(TvComponent component)
        {
            if (_myComponents.Contains(component))
            {
                _parent.Remove(component);
                _myComponents.Remove(component);
                OnComponentRemoved(component.Metadata);
                return(true);
            }

            return(false);
        }
Exemple #7
0
 public TvGrid(IComponentTree root, GridState state, string name = null)
 {
     _state     = state;
     _component = new TvComponent <GridState>(_state, name ?? $"TvGrid_{Guid.NewGuid()}");
     Name       = _component.Name;
     _component.Metadata.ViewportChanged += OnViewportChanged;
     _root = root;
     _ui   = new TvGridComponentTree(_root);
     _ui.ComponentAdded     += OnComponentAdded;
     _ui.ComponentRemoved   += OnComponentRemoved;
     _root.ComponentRemoved += OnRootRemoved;
 }
Exemple #8
0
        public TvControl(ISkin skin, IViewport viewport, TState initialState, string name = null)
        {
            _component = new TvComponent <TState>(initialState, name ?? $"TvControl_<$>");
            Metadata   = new TvControlMetadata(this, _component.ComponentId);
            var typename   = GetType().Name.ToLowerInvariant();
            var genericIdx = typename.IndexOf('`');

            ControlType  = genericIdx != -1 ? typename.Substring(0, genericIdx) : typename;
            CurrentStyle = skin.GetControlStyle(this);
            State        = initialState;
            _component.AddViewport(viewport);
            AddElements();
        }
 protected override void AddCustomElements(TvComponent <ActivityIndicatorState> component)
 {
     component.AddBehavior(c =>
     {
         _ticks++;
         if (_ticks == 30)
         {
             _ticks = 0;
             _idx++;
             _idx = _idx % 4;
             return(true);
         }
         return(false);
     });
 }
        IComponentMetadata IComponentTree.Add(TvComponent component)
        {
            if (_myComponents.ContainsKey(_currentKey))
            {
                _myComponents[_currentKey].Add(component);
            }
            else
            {
                var child = new ListComponentTree(_parent);
                _myComponents.Add(_currentKey, child);
                child.Add(component);
            }

            OnComponentAdded(component.Metadata);
            return(component.Metadata);
        }
        bool IComponentTree.Remove(TvComponent component)
        {
            foreach (var key in _myComponents.Keys)
            {
                var childTree = _myComponents[key];
                if (childTree.Remove(component))
                {
                    OnComponentRemoved(component.Metadata);
                    if (!childTree.Components.Any())
                    {
                        _myComponents.Remove(key);
                    }

                    return(true);
                }
            }

            return(false);
        }
Exemple #12
0
        private static async Task Main(string[] args)
        {
            var builder = new HostBuilder();

            builder.UseTvision2(setup =>
            {
                setup.UseDotNetConsoleDriver();
                setup.Options.UseStartup((sp, tui) =>
                {
                    var cm         = sp.GetService <IColorManager>();
                    var attr       = cm.BuildAttributeFor(TvColor.Yellow, TvColor.Blue);
                    var helloWorld = new TvComponent <string>("Tvision2 rocks!");
                    helloWorld.AddDrawer(ctx =>
                    {
                        ctx.DrawStringAt(ctx.State, TvPoint.Zero, attr);
                    });
                    helloWorld.AddViewport(new Viewport(new TvPoint(10, 10), 30));
                    tui.UI.Add(helloWorld);
                    return(Task.CompletedTask);
                });
            }).UseConsoleLifetime();
            await builder.RunTvisionConsoleApp();
        }
Exemple #13
0
 protected override void AddCustomElements(TvComponent <WindowState> component)
 {
     component.AddDrawer(new BorderDrawer(CurrentStyle, Metadata));
 }
Exemple #14
0
 public TvComponentMetadata(TvComponent component)
 {
     Component = component;
 }
Exemple #15
0
 protected virtual void AddCustomElements(TvComponent <TState> component)
 {
 }
Exemple #16
0
 public bool Remove(TvComponent component) => Remove(component.Metadata);
Exemple #17
0
 public IComponentMetadata Add(TvComponent component) => Add(component.Metadata);