A game framework written with osu! in mind.
at master 76 lines 2.1 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using osu.Framework.Bindables; 6using osu.Framework.Graphics.Containers; 7using osu.Framework.Input.Events; 8 9namespace osu.Framework.Graphics.UserInterface 10{ 11 public abstract class TabItem : ClickableContainer 12 { 13 /// <summary> 14 /// If false, ths <see cref="TabItem{T}"/> cannot be removed from its <see cref="TabControl{T}"/>. 15 /// </summary> 16 public abstract bool IsRemovable { get; } 17 } 18 19 public abstract class TabItem<T> : TabItem 20 { 21 internal Action<TabItem<T>> ActivationRequested; 22 internal Action<TabItem<T>> PinnedChanged; 23 24 public readonly BindableBool Active = new BindableBool(); 25 26 public override bool IsPresent => base.IsPresent || Y == 0; 27 28 public override bool IsRemovable => true; 29 30 /// <summary> 31 /// When true, this tab can be switched to using PlatformAction.DocumentPrevious and PlatformAction.DocumentNext. Otherwise, it will be skipped. 32 /// </summary> 33 public virtual bool IsSwitchable => true; 34 35 public readonly T Value; 36 37 protected TabItem(T value) 38 { 39 Value = value; 40 41 Active.ValueChanged += active => 42 { 43 if (active.NewValue) 44 OnActivated(); 45 else 46 OnDeactivated(); 47 }; 48 } 49 50 private bool pinned; 51 52 public bool Pinned 53 { 54 get => pinned; 55 set 56 { 57 if (pinned == value) return; 58 59 pinned = value; 60 PinnedChanged?.Invoke(this); 61 } 62 } 63 64 protected abstract void OnActivated(); 65 protected abstract void OnDeactivated(); 66 67 protected override bool OnClick(ClickEvent e) 68 { 69 base.OnClick(e); 70 ActivationRequested?.Invoke(this); 71 return true; 72 } 73 74 public override string ToString() => $"{base.ToString()} value: {Value}"; 75 } 76}