]> O.S.I.I.S - jp/crow.git/commitdiff
simplified tabView as TemplatedGroup
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 27 Mar 2021 17:45:57 +0000 (18:45 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 27 Mar 2021 19:06:09 +0000 (20:06 +0100)
Crow/Default.style
Crow/Templates/TabView.template [new file with mode: 0644]
Crow/src/Widgets/TabItem.cs [deleted file]
Crow/src/Widgets/TabView.cs
Samples/common/ui/Interfaces/Experimental/SimplifiedTabView.crow [new file with mode: 0644]
Samples/common/ui/Interfaces/Experimental/tabviewTest.crow
Samples/common/ui/Interfaces/TemplatedContainer/testTabView.crow

index f2f9482384896eef54d2d4a177345959776f553a..0e442eb61c01b290ba5afc9d370206e7ab6e1017 100644 (file)
@@ -137,19 +137,6 @@ Splitter {
        StickyMouse="10";
        Background = "Grey";
 }
-
-TabView {
-       CacheEnabled = "false";
-       AllowDrop = "true";
-}
-TabItem {
-       Caption = "TabItem";
-       Focusable = "true";
-       CacheEnabled = "true";
-       //MouseEnter = "{Background = Cobalt;Foreground=White;}";
-       //MouseLeave = "{Foreground=LightGrey;Background=Jet;}";
-       AllowDrag = "true";
-}
 Window {
        Caption = "Window";
        Focusable = "true";
diff --git a/Crow/Templates/TabView.template b/Crow/Templates/TabView.template
new file mode 100644 (file)
index 0000000..af4eae0
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<VerticalStack Spacing="0" > 
+       <ListBox Data="{./Items}" Fit="true" HorizontalAlignment="Left" VerticalAlignment="Top"> 
+               <Template>
+                       <HorizontalStack Name="ItemsContainer" Background="{./Background}" />
+               </Template>
+               <ItemTemplate>
+                       <ListItem Fit="true" Background="Transparent" IsSelected="{IsVisible}"
+                                       Selected="{.DataSource.Visible='true'};{Background=Grey}"
+                                       Unselected="{.DataSource.Visible='false'};{Background=Transparent}"> 
+                               <Label Text="{Name}" Margin="5" />
+                       </ListItem>
+               </ItemTemplate>
+       </ListBox>
+       <Group Name="ItemsContainer" Background="Grey" Margin="10"/>
+</VerticalStack>
+
diff --git a/Crow/src/Widgets/TabItem.cs b/Crow/src/Widgets/TabItem.cs
deleted file mode 100644 (file)
index cc6c489..0000000
+++ /dev/null
@@ -1,329 +0,0 @@
-// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
-using System;
-using System.ComponentModel;
-using Crow.Cairo;
-using System.Linq;
-
-namespace Crow
-{
-       public class TabItem : TemplatedContainer
-       {
-               #region CTOR
-               protected TabItem() {}
-               public TabItem (Interface iface, string style = null) : base (iface, style) { }
-               #endregion
-
-               public event EventHandler QueryClose;
-
-               internal TabView tview = null;
-
-               #region Private fields
-               Widget titleWidget;
-               int tabOffset;
-               bool isSelected;
-               //Measure tabThickness;
-               Fill selectedBackground = Colors.Transparent;
-               #endregion
-
-               #region TemplatedControl overrides
-               public override Widget Content {
-                       get {
-                               return _contentContainer == null ? null : _contentContainer.Child;
-                       }
-                       set {
-                               if (Content != null) {
-                                       Content.LogicalParent = null;
-                                       _contentContainer.SetChild (null);
-                               }
-                               _contentContainer.SetChild(value);
-                               if (value != null)
-                                       value.LogicalParent = this;
-                       }
-               }
-               protected override void loadTemplate(Widget template = null)
-               {
-                       base.loadTemplate (template);
-
-                       titleWidget = this.child.FindByName ("TabTitle");
-               }
-               internal Widget TabTitle { get { return titleWidget; }}
-               #endregion
-
-               /// <summary>
-               /// order of redrawing, items can't be reordered in TemplatedGroup due to data linked, so we need another index
-               /// instead of children list order
-               /// </summary>
-               public int viewIndex = 0;
-               public virtual int ViewIndex {
-                       get { return viewIndex; }
-                       set {
-                               if (viewIndex == value)
-                                       return;
-                               viewIndex = value;
-                               NotifyValueChangedAuto (viewIndex);
-                       }
-               }
-                       
-               [DefaultValue(0)]
-               public int TabOffset {
-                       get { return tabOffset; }
-                       set {
-                               if (tabOffset == value)
-                                       return;
-                               tabOffset = value;
-                               NotifyValueChangedAuto (tabOffset);
-
-                               RegisterForLayouting (LayoutingType.X);
-                               RegisterForGraphicUpdate ();
-                       }
-               }
-               public Measure TabHeight {
-                       get { return tview == null ? Measure.Fit : tview.TabHeight; }
-               }
-               public bool IsActiveTab => tview?.ActiveTab == this;
-               public Measure TabWidth {
-                       get { return tview == null ? Measure.Fit : tview.TabWidth; }
-               }
-               [DefaultValue(false)]
-               public virtual bool IsSelected {
-                       get { return isSelected; }
-                       set {
-                               if (isSelected == value)
-                                       return;
-
-                               //Console.WriteLine ($"TabItem({this.dataSource}).IsSelected: {isSelected} -> {value}");
-                               /*if (tview != null)
-                                       tview.SelectedTab = tview.Children.IndexOf(this);*/
-                               //Console.WriteLine ($"TabView.IsSelected({this.Caption}): {isSelected} -> {value}");
-                               //Console.WriteLine (new System.Diagnostics.StackTrace());
-                               
-                               isSelected = value;
-
-                               if (IsSelected)
-                                       tview.ActiveTab = this;                         
-
-                               NotifyValueChangedAuto (isSelected);
-                               RegisterForRedraw ();
-                       }
-               }
-
-               /// <summary>
-               /// background fill of the control, maybe solid color, gradient, image, or svg
-               /// </summary>
-               [DesignCategory ("Appearance")][DefaultValue("DimGrey")]
-               public virtual Fill SelectedBackground {
-                       get { return selectedBackground; }
-                       set {
-                               if (selectedBackground == value)
-                                       return;                         
-                               if (value == null)
-                                       return;
-                               selectedBackground = value;
-                               NotifyValueChangedAuto (selectedBackground);
-                               RegisterForRedraw ();
-                       }
-               }
-               protected override void onDraw (Context gr)
-               {
-                       gr.Save ();
-
-                       parentRWLock.EnterReadLock ();
-
-                       TabView tv = Parent as TabView;
-
-                       //TODO:this appens in designView
-                       if (tv == null) {
-                               parentRWLock.ExitReadLock ();
-                               return;
-                       }
-
-                       Rectangle r = TabTitle.Slot;
-                       r.Width = TabWidth;
-
-                       gr.MoveTo (0.5, r.Bottom-0.5);
-                       gr.LineTo (r.Left - tv.LeftSlope, r.Bottom-0.5);
-                       gr.CurveTo (
-                               r.Left - tv.LeftSlope / 2, r.Bottom-0.5,
-                               r.Left - tv.LeftSlope / 2, 0.5,
-                               r.Left, 0.5);
-                       gr.LineTo (r.Right, 0.5);
-                       gr.CurveTo (
-                               r.Right + tv.RightSlope / 2, 0.5,
-                               r.Right + tv.RightSlope / 2, r.Bottom-0.5,
-                               r.Right + tv.RightSlope, r.Bottom-0.5);
-                       gr.LineTo (Slot.Width-0.5, r.Bottom-0.5);
-
-                       parentRWLock.ExitReadLock ();
-
-                       gr.LineTo (Slot.Width-0.5, Slot.Height-0.5);
-                       gr.LineTo (0.5, Slot.Height-0.5);
-                       gr.ClosePath ();
-                       gr.LineWidth = 1;
-                       Foreground.SetAsSource (IFace, gr);
-                       gr.StrokePreserve ();
-                       gr.ClipPreserve ();
-
-                       if (IsActiveTab)
-                               SelectedBackground.SetAsSource (IFace, gr, ClientRectangle);
-                       else
-                               Background.SetAsSource (IFace, gr, ClientRectangle);
-
-                       gr.Fill ();
-
-                       base.onDraw (gr);
-
-                       gr.Restore ();
-               }
-
-               Point dragStartPoint;
-               int dragThreshold = 16;
-               int dis = 128;
-               internal TabView savedParent = null;
-
-
-               void makeFloating (TabView tv) {                        
-                       lock (IFace.UpdateMutex) {                              
-                               ImageSurface di = new ImageSurface (Format.Argb32, dis, dis);
-                               IFace.DragImageHeight = dis;
-                               IFace.DragImageWidth = dis;
-                               using (Context ctx = new Context (di)) {
-                                       double div = Math.Max (LastPaintedSlot.Width, LastPaintedSlot.Height);
-                                       double s = (double)dis / div;
-                                       ctx.Scale (s, s);
-                                       if (bmp == null)
-                                               this.onDraw (ctx);
-                                       else {
-                                               if (LastPaintedSlot.Width>LastPaintedSlot.Height)
-                                                       ctx.SetSource (bmp, 0, (LastPaintedSlot.Width-LastPaintedSlot.Height)/2);
-                                               else
-                                                       ctx.SetSource (bmp, (LastPaintedSlot.Height-LastPaintedSlot.Width)/2, 0);
-
-                                               ctx.Paint ();
-                                       }
-                               }
-                               IFace.DragImage = di;
-                       }
-                       tv.RemoveChild (this);
-                       savedParent = tv;
-               }
-
-               public override ILayoutable Parent {
-                       get {
-                               return base.Parent;
-                       }
-                       set {
-                               base.Parent = value;
-                               if (value != null) {
-                                       dragStartPoint = IFace.MousePosition;
-                                       savedParent = value as TabView;
-                               }
-                       }
-               }
-               protected override void onStartDrag (object sender, DragDropEventArgs e)
-               {
-                       base.onStartDrag (sender, e);
-
-                       dragStartPoint = IFace.MousePosition;
-               }
-               public override void onEndDrag (object sender, DragDropEventArgs e)
-               {
-                       base.onEndDrag (sender, e);
-
-                       if (Parent != null)
-                               return;
-
-                       savedParent.AddChild (this);
-
-                       IFace.ClearDragImage ();
-               }
-               public override void onDrop (object sender, DragDropEventArgs e)
-               {
-                       base.onDrop (sender, e);
-                       if (Parent != null)
-                               return;
-                       TabView tv = e.DropTarget as TabView;
-                       if (tv == null)
-                               return;
-
-                       IFace.ClearDragImage ();
-
-                       tv.AddChild (this);
-               }
-               #region Mouse Handling
-               public override bool PointIsIn (ref Point m)
-               {
-                       if (!base.PointIsIn (ref m))
-                               return false;
-                       if (tview == null)//double check this, just added to prevent exception
-                               return false;
-                       if (m.Y < tview.TabHeight)
-                               return TabTitle.Slot.ContainsOrIsEqual (m);
-                       else
-                               return this.isSelected;
-               }
-               public override void onMouseUp (object sender, MouseButtonEventArgs e)
-               {
-                       base.onMouseUp (sender, e);
-                       tview?.UpdateLayout (LayoutingType.ArrangeChildren);
-               }
-               public override void onMouseMove (object sender, MouseMoveEventArgs e)
-               {
-                       base.onMouseMove (sender, e);
-
-                       if (Parent == null)
-                               return;
-                       
-                       if (!IsDragged)
-                               return;
-
-                       TabView tv = Parent as TabView;
-                       if (Math.Abs (e.Position.Y - dragStartPoint.Y) > dragThreshold ||
-                               Math.Abs (e.Position.X - dragStartPoint.X) > dragThreshold) {
-                               makeFloating (tv);
-                               return;
-                       }
-
-                       Rectangle cb = ClientRectangle;
-
-                       int tmp = TabOffset + e.XDelta;
-                       if (tmp < tview.LeftSlope) {                            
-                               TabOffset = tview.LeftSlope;
-                       } else if (tmp > cb.Width - tv.RightSlope - tv.TabWidth) {
-                               TabOffset = cb.Width - tv.RightSlope - tv.TabWidth;
-                       }else{
-                               dragStartPoint.X = e.Position.X;
-                               TabItem[] tabItms = tv.Children.Cast<TabItem>().OrderBy (t=>t.ViewIndex).ToArray();
-                               if (ViewIndex > 0 && e.XDelta < 0) {
-                                       TabItem previous = tabItms [ViewIndex - 1];
-                                       if (tmp < previous.TabOffset + tview.TabWidth / 2) {
-                                               previous.ViewIndex = ViewIndex;
-                                               ViewIndex--;
-                                               tv.UpdateLayout (LayoutingType.ArrangeChildren);
-                                       }
-
-                               }else if (ViewIndex < tabItms.Length - 1 && e.XDelta > 0) {
-                                       TabItem next = tabItms [ViewIndex + 1];
-                                       if (tmp > next.TabOffset - tview.TabWidth / 2){
-                                               next.ViewIndex = ViewIndex;
-                                               ViewIndex++;
-                                               tv.UpdateLayout (LayoutingType.ArrangeChildren);
-                                       }
-                               }
-                               TabOffset = tmp;
-                       }
-               }
-               public void butCloseTabClick (object sender, MouseButtonEventArgs e){                   
-                       QueryClose.Raise (this, null);
-                       //if tab is used as a templated item root in a templatedGroup, local datasource
-                       //is not null, in this case, removing the data entries will delete automatically the item
-                       if (localDataSourceIsNull)
-                               (Parent as TabView)?.DeleteChild (this);
-               }
-               #endregion
-
-       }
-}
-
index 3067243dc16d446290189104928d0ccec803fee5..440322fd100bd73edc0f0e52ac41eff8127e2e88 100644 (file)
@@ -9,330 +9,28 @@ using System.Linq;
 
 namespace Crow
 {
-       public class TabView : Group
+       public class TabView : TemplatedGroup
        {
                #region CTOR
                public TabView () { }
                public TabView (Interface iface, string style = null) : base (iface, style) { }
                #endregion
 
-               #region Private fields
-               int adjustedTab = -1;
-               int leftSlope;
-               int rightSlope;
-               Measure tabHeight, tabWidth;
-               Orientation _orientation;
-               TabItem activeTab;
-               bool activateNewTab;
-               #endregion
+               Orientation orientation;
 
-               #region public properties
                [DefaultValue (Orientation.Horizontal)]
-               public virtual Orientation Orientation {
-                       get { return _orientation; }
-                       set {
-                               if (_orientation == value)
-                                       return;
-                               _orientation = value;
-                               NotifyValueChangedAuto (_orientation);
-                               if (_orientation == Orientation.Horizontal)
-                                       NotifyValueChanged ("TabOrientation", Orientation.Vertical);
-                               else
-                                       NotifyValueChanged ("TabOrientation", Orientation.Horizontal);
-                               this.RegisterForLayouting (LayoutingType.ArrangeChildren);
-                       }
-               }
-               [DefaultValue (16)]
-               public int LeftSlope {
-                       get { return leftSlope; }
-                       set {
-                               if (leftSlope == value)
-                                       return;
-                               leftSlope = value;
-                               NotifyValueChangedAuto (leftSlope);
-                               //tabSizeHasChanged = true;
-                               //RegisterForLayouting (LayoutingType.ArrangeChildren);
-                       }
-               }
-               //bool tabSizeHasChanged = false;
-               [DefaultValue (16)]
-               public int RightSlope {
-                       get { return rightSlope; }
-                       set {
-                               if (rightSlope == value)
-                                       return;
-                               rightSlope = value;
-                               NotifyValueChangedAuto (rightSlope);
-                               //tabSizeHasChanged = true;
-                               //RegisterForLayouting (LayoutingType.ArrangeChildren);
-                       }
-               }
-               [DefaultValue ("18")]
-               public Measure TabHeight {
-                       get { return tabHeight; }
-                       set {
-                               if (tabHeight == value)
-                                       return;
-                               tabHeight = value;
-                               NotifyValueChangedAuto (tabHeight);
-                               //                              childrenRWLock.EnterReadLock ();
-                               //                              foreach (GraphicObject ti in Children) {
-                               //                                      ti.NotifyValueChanged ("TabHeight", tabHeight);
-                               //                              }
-                               //                              childrenRWLock.ExitReadLock ();
-                               RegisterForLayouting (LayoutingType.ArrangeChildren);
-                       }
-               }
-               [DefaultValue ("120")]
-               public Measure TabWidth {
-                       get { return adjustedTab > 0 ? (Measure)adjustedTab : tabWidth; }
+               public Orientation Orientation {
+                       get => orientation;
                        set {
-                               if (tabWidth == value)
-                                       return;
-                               tabWidth = value;
-                               NotifyValueChangedAuto (TabWidth);
-                               //
-                               //                              childrenRWLock.EnterReadLock ();
-                               //                              foreach (GraphicObject ti in Children) { 
-                               //                                      ti.NotifyValueChanged ("TabWidth", tabWidth);
-                               //                              }
-                               //                              childrenRWLock.ExitReadLock ();
-                               RegisterForLayouting (LayoutingType.ArrangeChildren);
-                       }
-               }
-               /// <summary>
-               /// If true new tabs will be set as the active tab of this tabview.
-               /// </summary>
-               [DefaultValue (true)]
-               public bool ActivateNewTab {
-                       get => activateNewTab;
-                       set {
-                               if (activateNewTab == value)
-                                       return;
-                               activateNewTab = value;
-                               NotifyValueChangedAuto (activateNewTab);
-            }
-        }
-               public virtual TabItem ActiveTab {
-                       get => activeTab;
-                       set {                           
-                               if (activeTab == value)
+                               if (orientation == value)
                                        return;
-
-                               //Console.WriteLine ($"TabView.ActiveTab: {activeTab?.DataSource} -> {value?.DataSource}");
-
-                               if (value != null) {
-                                       if (activeTab != null) {
-                                               activeTab.IsSelected = false;
-                                               ActiveTab.NotifyValueChanged ("IsActiveTab", false);
-                                       }
-                                       activeTab = value;
-                                       ActiveTab.IsSelected = true;
-                                       ActiveTab.NotifyValueChanged ("IsActiveTab", true);
-                               } else
-                                       activeTab = value;
-
-                               NotifyValueChangedAuto (activeTab);
-                               RegisterForRedraw ();
-                       }
-               }
-               #endregion
-
-               public override void AddChild (Widget child) {
-                       TabItem ti = child as TabItem;
-                       if (ti == null)
-                               throw new Exception ("TabView control accept only TabItem as child.");
-
-                       ti.MouseDown += Ti_MouseDown;
-                       ti.TabTitle.LayoutChanged += Ti_TabTitle_LayoutChanged;
-                       ti.tview = this;
-
-                       base.AddChild (child);
-
-                       ti.ViewIndex = Children.Count - 1;
-
-                       if (ActivateNewTab || ti.ViewIndex == 0)
-                               ti.IsSelected = true;
-
-                       this.RegisterForLayouting (LayoutingType.ArrangeChildren);
-               }
-               public override void RemoveChild (Widget child) {
-                       TabItem ti = child as TabItem;
-                       if (ti == null)
-                               throw new Exception ("TabView control accept only TabItem as child.");
-
-                       ti.MouseDown -= Ti_MouseDown;
-                       ti.TabTitle.LayoutChanged -= Ti_TabTitle_LayoutChanged;
-                       ti.tview = null;
-
-                       childrenRWLock.EnterReadLock ();
-
-                       TabItem[] tabItms = Children.Cast<TabItem> ().OrderBy (t => t.ViewIndex).ToArray ();
-                       if (ActiveTab == ti) {                          
-                               if (tabItms.Length > 1) {
-                                       if (ti.ViewIndex == tabItms.Length - 1)
-                                               ActiveTab = tabItms[ti.ViewIndex - 1];
-                                       else
-                                               ActiveTab = tabItms[ti.ViewIndex + 1];
-                               } else
-                                       ActiveTab = null;
+                               orientation = value;
+                               NotifyValueChangedAuto (orientation);
+                               NotifyValueChanged ("OppositeOrientation", OppositeOrientation);
                        }
-                       for (int i = ti.viewIndex + 1; i < tabItms.Length; i++)
-                               tabItms[i].ViewIndex--;
-
-                       /*int selTabViewIdx = -1;
-
-                       if (SelectedTab < tabItms.Length && SelectedTab >= 0)
-                               selTabViewIdx = (Children [SelectedTab] as TabItem).ViewIndex;
-
-                       for (int i = selTabViewIdx+1; i < tabItms.Length; i++)
-                               tabItms [i].ViewIndex--;
-
-                       if (selTabViewIdx > tabItms.Length - 2)
-                               selTabViewIdx = tabItms.Length - 2;
-
-                       if (selTabViewIdx < 0)
-                               SelectedTab = -1;
-                       else
-                               SelectedTab = Children.IndexOf (tabItms [selTabViewIdx]);*/
-
-                       childrenRWLock.ExitReadLock ();
-
-                       base.RemoveChild (child);
-               }
-
-               public override bool ArrangeChildren { get { return true; } }
-               public override bool UpdateLayout (LayoutingType layoutType) {
-                       RegisteredLayoutings &= (~layoutType);
-
-                       if (layoutType == LayoutingType.ArrangeChildren && Children.Count > 0) {
-                               Rectangle cb = ClientRectangle;
-
-                               int tabSpace = tabWidth + leftSlope;
-                               int tc = Children.Count (c => c.Visible == true);
-
-                               if (tc > 0)
-                                       tabSpace = Math.Min (tabSpace, (cb.Width - rightSlope) / tc);
-
-                               if (tabSpace < tabWidth + leftSlope)
-                                       adjustedTab = tabSpace - leftSlope;
-                               else
-                                       adjustedTab = -1;
-
-                               //System.Diagnostics.Debug.WriteLine ("tabspace: {0} tw:{1}", tabSpace, tabWidth);
-
-                               childrenRWLock.EnterReadLock ();
-                               TabItem[] tabItms = Children.Cast<TabItem> ().OrderBy (t => t.ViewIndex).ToArray ();
-                               childrenRWLock.ExitReadLock ();
-                               int curOffset = leftSlope;
-
-                               for (int i = 0; i < tabItms.Length; i++) {
-                                       if (!tabItms[i].Visible)
-                                               continue;
-                                       tabItms[i].NotifyValueChanged ("TabHeight", tabHeight);
-                                       tabItms[i].NotifyValueChanged ("TabWidth", TabWidth);
-                                       if (!tabItms[i].IsDragged) {
-                                               tabItms[i].TabOffset = curOffset;
-                                               //System.Diagnostics.Debug.WriteLine ("offset: {0}=>{1}", tabItms [i].Name, tabItms [i].TabOffset);
-                                       }
-                                       if (Orientation == Orientation.Horizontal) {
-                                               curOffset += tabSpace;
-                                       } else
-                                               curOffset += tabSpace;
-                               }
-
-                               //if no layouting remains in queue for item, registre for redraw
-                               if (RegisteredLayoutings == LayoutingType.None && IsDirty)
-                                       IFace.EnqueueForRepaint (this);
-
-                               return true;
-                       }
-
-                       return base.UpdateLayout (layoutType);
-               }
-               public override void OnLayoutChanges (LayoutingType layoutType) {
-                       if (_orientation == Orientation.Horizontal) {
-                               if (layoutType == LayoutingType.Width)
-                                       RegisterForLayouting (LayoutingType.ArrangeChildren);
-                       } else if (layoutType == LayoutingType.Height)
-                               RegisterForLayouting (LayoutingType.ArrangeChildren);
-
-                       base.OnLayoutChanges (layoutType);
-               }
-
-               internal TabItem[] VisibleTabsByViewIdx =>
-                       Children.Where (tt => tt.Visible).Cast<TabItem> ().
-                               OrderBy (t => t.ViewIndex).ToArray ();
-
-               protected override void onDraw (Context gr) {
-                       Rectangle rBack = new Rectangle (Slot.Size);
-
-                       Background.SetAsSource (IFace, gr, rBack);
-                       CairoHelpers.CairoRectangle (gr, rBack, CornerRadius);
-                       gr.Fill ();
-
-                       gr.Save ();
-
-                       if (ClipToClientRect) {
-                               //clip to client zone
-                               CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
-                               gr.Clip ();
-                       }
-
-                       childrenRWLock.EnterReadLock ();
-
-                       TabItem[] tabItms = VisibleTabsByViewIdx;
-
-                       TabItem sti = ActiveTab;
-                       int selTabViewIdx = sti == null ? tabItms.Length - 1 : sti.ViewIndex;
-
-                       int i = 0;
-                       while (i < selTabViewIdx) {
-                               tabItms[i].Paint (gr);
-                               i++;
-                       }
-                       i = tabItms.Length - 1;
-                       while (i > selTabViewIdx) {
-                               tabItms[i].Paint (gr);
-                               i--;
-                       }
-
-                       if (selTabViewIdx >= 0 && selTabViewIdx < tabItms.Length)
-                               tabItms[selTabViewIdx].Paint (gr);
-
-                       childrenRWLock.ExitReadLock ();
-
-                       gr.Restore ();
-               }
-
-               protected override void onDragEnter (object sender, DragDropEventArgs e) {
-                       base.onDragEnter (sender, e);
-
-                       TabItem ti = e.DragSource as TabItem;
-                       if (ti == null)
-                               return;
-                       if (ti.Parent != null || ti.savedParent == this)
-                               return;
-
-                       this.AddChild (ti);
-
-                       Point p = ScreenPointToLocal (IFace.MousePosition) - Margin;
-
-                       p.X = Math.Max (leftSlope, p.X);
-                       p.X = Math.Min (ClientRectangle.Width - rightSlope - TabWidth, p.X);
-                       ti.TabOffset = p.X;
-
-                       IFace.ClearDragImage ();
-
-               }
-
-               void Ti_TabTitle_LayoutChanged (object sender, LayoutingEventArgs e) {
-                       if (e.LayoutType == LayoutingType.X)
-                               RegisterForLayouting (LayoutingType.ArrangeChildren);
-               }
-               void Ti_MouseDown (object sender, MouseButtonEventArgs e) {
-                       ActiveTab = sender as TabItem;
                }
+               public Orientation OppositeOrientation 
+                       => orientation == Orientation.Vertical ? Orientation.Horizontal : Orientation.Vertical;         
        }
 }
 
diff --git a/Samples/common/ui/Interfaces/Experimental/SimplifiedTabView.crow b/Samples/common/ui/Interfaces/Experimental/SimplifiedTabView.crow
new file mode 100644 (file)
index 0000000..7082be3
--- /dev/null
@@ -0,0 +1,11 @@
+<TabView>
+       <Widget Name="Item 1" Background="SeaGreen"/>
+       <Widget Name="Item 2" IsVisible="false" Background="Red"/>
+       <Widget Name="Item 3" IsVisible="false" Background="Blue"/>
+       <Widget Name="Item 4" IsVisible="false" Background="Green"/>
+       <Widget Name="Item 5" IsVisible="false" Background="Pink"/>
+       <Widget Name="Item 6" IsVisible="false" Background="SeaGreen"/>
+       <Widget Name="Item 7" IsVisible="false" Background="DarkGrey"/>
+       <Widget Name="Item 8" IsVisible="false" Background="Onyx"/>
+       <Widget Name="Item 9" IsVisible="false" Background="Yellow"/>
+</TabView>
\ No newline at end of file
index c578b0ca6607770e16c87c1d5353945b4c35b629..f874a2c6e2c9b6f9b4f1480220c299d789be055f 100644 (file)
@@ -1,22 +1,25 @@
-<ListBox >
-       <Template>
-               <VerticalStack> 
-                       <ListBox Data="{./Items}" Height="Fit">
-                               <Template>
-                                       <HorizontalStack Name="ItemsContainer" Background="{./Background}"/>
-                               </Template>
-                               <ItemTemplate>
-                                       <ListItem Width="Fit" Background="Transparent" IsSelected="{IsVisible}"
-                                                       Selected="{.DataSource.Visible='true'};{Background=Blue}"
-                                                       Unselected="{.DataSource.Visible='false'};{Background=Transparent}"> 
-                                               <Label Text="{Caption}" Margin="5" />
-                                       </ListItem>
-                               </ItemTemplate>
-                       </ListBox>                      
-                       <Group Name="ItemsContainer"/>
-               </VerticalStack>
-       </Template>
-       <GroupBox Caption="item 1" IsVisible="false"/>
-       <GroupBox Caption="item 2" IsVisible="true"/>
-       <GroupBox Caption="item 3" IsVisible="false"/>
-</ListBox>
\ No newline at end of file
+<VerticalStack>
+       <ListBox Name="lb">
+               <Template>
+                       <VerticalStack Spacing="0"> 
+                               <ListBox Data="{./Items}" Height="Fit" SelectedItem="{²./SelectedItem}">
+                                       <Template>
+                                               <HorizontalStack Name="ItemsContainer" Background="{./Background}"/>
+                                       </Template>
+                                       <ItemTemplate>
+                                               <ListItem Width="Fit" Background="Transparent" IsSelected="{IsVisible}"
+                                                               Selected="{.DataSource.Visible='true'};{Background=CornflowerBlue}"
+                                                               Unselected="{.DataSource.Visible='false'};{Background=Transparent}"> 
+                                                       <Label Text="{Caption}" Margin="5" />
+                                               </ListItem>
+                                       </ItemTemplate>
+                               </ListBox>                      
+                               <Group Name="ItemsContainer"/>
+                       </VerticalStack>
+               </Template>
+               <GroupBox Caption="item 1" IsVisible="false" Background="CornflowerBlue"/>
+               <GroupBox Caption="item 2" IsVisible="true" Background="CornflowerBlue"/>
+               <GroupBox Caption="item 3" IsVisible="false" Background="CornflowerBlue"/>
+       </ListBox>
+       <Label DataSource="{../lb.SelectedItem}" Text="{Caption}"/> 
+</VerticalStack>
\ No newline at end of file
index 7aa4cdd58ef9060b503e59efdacfe878d131a920..f54a718230cda162e91b75e4cf6639549940c0dd 100644 (file)
@@ -1,37 +1,28 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<Group Height="90%" Width="95%">
 <VerticalStack >
        <HorizontalStack Height="Fit">
                <Label Text="Selected Tab:"/>
-               <Label Text="{../../tabview1.SelectedTab}"/>
+               <Label Name="lab" />
        </HorizontalStack>
-       <TabView Name="tabview1" Background="DimGrey" Orientation="Horizontal">
-               <TabItem Name="TabItem1" Caption="tab item 1" Background="DimGrey">
-                       <VerticalStack Margin="20">
-                               <CheckBox/>
-                               <CheckBox/>
-                               <CheckBox/>
-                               <CheckBox/>
-                       </VerticalStack>
-               </TabItem>
-               <TabItem Name="TabItem2" Caption="tab item 2" Background="DimGrey">
-                       <VerticalStack Height="Fit" Margin="10">
-                               <RadioButton Fit="true"/>
-                               <RadioButton/>
-                               <RadioButton/>
-                               <RadioButton/>
-                       </VerticalStack>
-               </TabItem>
-               <TabItem Name="TabItem3" Background="DimGrey" Caption="tab item 3">
-                       <Container Margin="5" CornerRadius="2" >
-                               <TextBox Margin="5" Multiline="true" TextAlignment="Left"/>
-                       </Container>
-               </TabItem>
-               <TabItem Name="TabItem4" Background="DimGrey" Caption="tab item 4" Margin="0">
+       <TabView Name="tabview1" Background="DimGrey" Orientation="Horizontal"
+               SelectedItemChanged="{../lab.Background='Blue'}">
+               <VerticalStack Name="tab #1" Margin="20">
+                       <CheckBox/>
+                       <CheckBox/>
+                       <CheckBox/>
+                       <CheckBox/>
+               </VerticalStack>
+               <VerticalStack Name="tab #2" Margin="20">
+                       <RadioButton/>
+                       <RadioButton/>
+                       <RadioButton/>
+                       <RadioButton/>
+               </VerticalStack>
+               <VerticalStack Name="tab #3" Margin="20">
                        <TextBox/>
-               </TabItem>
+                       <TextBox/>
+                       <TextBox/>
+                       <TextBox/>
+               </VerticalStack> 
        </TabView>
-       <Button Background="vgradient|0:DimGrey|1:Black" HorizontalAlignment="Right"
-               Caption="Add new tab" Width="Fit" Height="30" MouseDown="onAddTabButClick"/>
-</VerticalStack>
-</Group>
\ No newline at end of file
+</VerticalStack> 
\ No newline at end of file