]> O.S.I.I.S - jp/crow.git/commitdiff
close but on tabItem, SelectedTab checks
authorjpbruyere <jp.bruyere@hotmail.com>
Tue, 16 Feb 2016 11:25:34 +0000 (12:25 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Tue, 16 Feb 2016 11:25:34 +0000 (12:25 +0100)
Templates/TabItem.crow
Tests/Interfaces/testTabView.crow
src/GraphicObjects/TabItem.cs
src/GraphicObjects/TabView.cs

index 63b0b9cfd650e03fdf42bddee32e5863e39bede9..a889f4ee813e1039fd0f97c9bc2a9f15b6918a56 100644 (file)
@@ -1,11 +1,21 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <GenericStack Orientation="Vertical" Spacing="0"
-               Width="{../../WidthPolicy}" Height="{../../HeightPolicy}">
-       <Label Margin="5" Name="TabTitle" Width="-1"
+               Width="{../../WidthPolicy}" Height="{../../HeightPolicy}"
+               Background="vgradient|0:DimGray|1:Black"
+               MouseEnter="{Background=vgradient|0:Gray|1:Black}"
+               MouseLeave="{Background=vgradient|0:DimGray|1:Black}">
+       <HorizontalStack Margin="2" Left="{../../TabOffset}"
+               Name="TabTitle"
                HorizontalAlignment="Left"
-               Text="{../../Caption}"
                Height="{../../../TabThickness}"
-               Left="{../../TabOffset}"/>
+               Width="-1">
+               <Label Text="{../../../Caption}"/>
+               <Border CornerRadius="5" BorderWidth="1" Foreground="Transparent"  Height="12" Width="12"
+                                       MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Transparent}">
+                       <Image Focusable="true" Name="Image" Margin="0" Width="0" Height="0" Path="#Crow.Images.Icons.exit2.svg"
+                                MouseClick="../../../../butCloseTabClick"/>
+               </Border>
+       </HorizontalStack>
        <Container
                Name="Content" Width="{../../../WidthPolicy}" Height="{../../../HeightPolicy}"/>
 </GenericStack>
index 32a525559002d4e3665b89a37d21a10649514c48..953dd8c111eaf10128ec5ae6072c45c08de87c77 100644 (file)
@@ -1,9 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <HorizontalStack Fit="true">
-       <TabView CacheEnabled="false" Width="400" Height="200" Orientation="Horizontal" Spacing="20" Margin="0">
-               <TabItem Name="TabItem1" Caption="tab item 1" Width="0" Height="0" Margin="0" Background="Gray"
-                       MouseEnter="{Background=Red}" Focusable="true"
-                       MouseLeave="{Background=Gray}">
+       <TabView Margin="20"
+               Width="400" Height="200" Orientation="Horizontal" Spacing="20">
+               <TabItem Name="TabItem1" Caption="tab item 1" Width="0" Height="0" Margin="0">
                        <VerticalStack Fit="true">
                                <CheckBox/>
                                <CheckBox/>
@@ -12,9 +11,7 @@
                                <Label Text="{fps}" HorizontalAlignment="Right" Foreground="Black" Background="Yellow"/>
                        </VerticalStack>
                </TabItem>
-               <TabItem Name="TabItem2" Caption="tab item 2" Width="0" Height="0" Margin="0" Background="Gray"
-                       MouseEnter="{Background=BlueCrayola}"
-                       MouseLeave="{Background=Gray}">
+               <TabItem Name="TabItem2" Caption="tab item 2" Width="0" Height="0" Margin="0" Background="Gray">
                        <VerticalStack Fit="true">
                                <RadioButton/>
                                <RadioButton/>
                                <Label Text="{fps}" HorizontalAlignment="Left" Background="LimeGreen"/>
                        </VerticalStack>
                </TabItem>
-               <TabItem Name="TabItem2" Caption="tab item 3" Width="0" Height="0" Margin="0" Background="Gray"
-                       MouseEnter="{Background=BlueCrayola}"
-                       MouseLeave="{Background=Gray}">
-                       <TextBox Width="0" Height="0" Multiline="true" TextAlignment="TopLeft"/>
+               <TabItem Name="TabItem2" Caption="tab item 3" Width="0" Height="0" Margin="0" Background="Gray">
+                       <Container Margin="5" CornerRadius="2" Width="0" Height="0">
+                               <TextBox Margin="5" Width="0" Height="0" Multiline="true" TextAlignment="TopLeft"/>
+                       </Container>
                </TabItem>
-               <TabItem Name="TabItem2" Caption="tab item 4" Width="0" Height="0" Margin="0" Background="Gray"
-                       MouseEnter="{Background=BlueCrayola}"
-                       MouseLeave="{Background=Gray}">
+               <TabItem Name="TabItem2" Caption="tab item 4" Width="0" Height="0" Margin="0" Background="Gray">
                        <TextBox/>
                </TabItem>
        </TabView>
        <TabView CacheEnabled="false" Width="200" Height="200" Orientation="Horizontal" Spacing="20" Margin="0">
                <TabItem
-                       MouseEnter="{Background=BlueCrayola}"
-                       MouseLeave="{Background=Gray}"
                        Name="TabItem1" Caption="tab 1" Width="0" Height="0" Margin="0" Background="Gray">
                        <VerticalStack Fit="true">
                                <CheckBox/>
@@ -48,8 +41,6 @@
                        </VerticalStack>
                </TabItem>
                <TabItem
-                       MouseEnter="{Background=BlueCrayola}"
-                       MouseLeave="{Background=Gray}"
                        Name="TabItem2" Caption="tab 2" Width="0" Height="0" Margin="0" Background="Gray">
                        <VerticalStack Fit="true">
                                <RadioButton/>
index a166319a5c490e8f37911d08c7a9f48a739282de..b0e733fb182c4374c7fbf56b373e40e530aa00d0 100644 (file)
@@ -122,11 +122,11 @@ namespace Crow
                        gr.LineTo (TabTitle.Slot.Left - spacing, TabTitle.Slot.Bottom);
                        gr.CurveTo (
                                TabTitle.Slot.Left - spacing / 2, TabTitle.Slot.Bottom,
-                               TabTitle.Slot.Left - spacing / 2, 0,
-                               TabTitle.Slot.Left, 0);
-                       gr.LineTo (TabTitle.Slot.Right, 0);
+                               TabTitle.Slot.Left - spacing / 2, 1,
+                               TabTitle.Slot.Left, 1);
+                       gr.LineTo (TabTitle.Slot.Right, 1);
                        gr.CurveTo (
-                               TabTitle.Slot.Right + spacing / 2, 0,
+                               TabTitle.Slot.Right + spacing / 2, 1,
                                TabTitle.Slot.Right + spacing / 2, TabTitle.Slot.Bottom,
                                TabTitle.Slot.Right + spacing, TabTitle.Slot.Bottom);
                        gr.LineTo (Slot.Width, TabTitle.Slot.Bottom);
@@ -178,7 +178,6 @@ namespace Crow
                        TabView tv = Parent as TabView;
                        TabItem previous = null, next = null;
                        int tmp = TabOffset + e.XDelta;
-                       Debug.WriteLine (tmp);
                        if (tmp < tv.Spacing)
                                TabOffset = tv.Spacing;
                        else if (tmp > Parent.getSlot ().Width - TabTitle.Slot.Width - tv.Spacing)
@@ -207,6 +206,9 @@ namespace Crow
                                TabOffset = tmp;
                        }
                }
+               public void butCloseTabClick (object sender, OpenTK.Input.MouseButtonEventArgs e){
+                       (Parent as TabView).RemoveChild(this);
+               }
                #endregion
 
        }
index 3e90d35c24bd8187045c9749e9acf2acb24b4fe9..a480ae09eb38931c01bdfd0a1cfd956619ba2fe4 100644 (file)
@@ -69,21 +69,20 @@ namespace Crow
                public virtual int SelectedTab {
                        get { return selectedTab; }
                        set {
-                               if (selectedTab == value)
-                                       return;
-
-                               (Children [selectedTab] as TabItem).IsSelected = false;
+                               if (selectedTab < Children.Count && SelectedTab >= 0)
+                                       (Children [selectedTab] as TabItem).IsSelected = false;
 
                                selectedTab = value;
 
-                               (Children [selectedTab] as TabItem).IsSelected = true;
+                               if (selectedTab < Children.Count && SelectedTab >= 0)
+                                       (Children [selectedTab] as TabItem).IsSelected = true;
 
                                NotifyValueChanged ("SelectedTab", selectedTab);
                                registerForGraphicUpdate ();
                        }
                }
                int tabThickness;
-               [XmlAttributeAttribute()][DefaultValue(20)]
+               [XmlAttributeAttribute()][DefaultValue(22)]
                public virtual int TabThickness {
                        get { return tabThickness; }
                        set {
@@ -93,6 +92,14 @@ namespace Crow
                                NotifyValueChanged ("TabThickness", tabThickness);
                        }
                }
+
+               //prevent caching, because drawing order is different depending on selected tab
+               [XmlAttributeAttribute()][DefaultValue(false)]
+               public override bool CacheEnabled {
+                       get {return false;}
+                       set { }
+               }
+
                public override T AddChild<T> (T child)
                {
                        TabItem ti = child as TabItem;
@@ -110,11 +117,12 @@ namespace Crow
                }
                public override void RemoveChild (GraphicObject child)
                {
-                       TabItem ti = child as TabItem;
+                       int idx = Children.IndexOf (child);
                        base.RemoveChild (child);
-                       if (ti.IsSelected)
-                               SelectedTab = Math.Min(0, Children.Count - 1);
-
+                       if (selectedTab > Children.Count - 1)
+                               SelectedTab--;
+                       else
+                               SelectedTab = selectedTab;
                }
                public override bool ArrangeChildren { get { return true; } }
                public override bool UpdateLayout (LayoutingType layoutType)
@@ -166,7 +174,9 @@ namespace Crow
                                        continue;
                                Children [i].Paint (ref gr);
                        }
-                       Children [SelectedTab].Paint (ref gr);
+
+                       if (SelectedTab < Children.Count && SelectedTab >= 0)
+                               Children [SelectedTab].Paint (ref gr);
 
                        gr.Restore ();
                }
@@ -178,6 +188,10 @@ namespace Crow
                                HostContainer.hoverWidget = this;
                                onMouseEnter (this, e);
                        }
+
+                       if (SelectedTab > Children.Count - 1)
+                               return;
+
                        if (((Children[SelectedTab] as TabItem).Content.Parent as GraphicObject).MouseIsIn(e.Position))
                        {
                                Children[SelectedTab].checkHoverWidget (e);