A game framework written with osu! in mind.
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
4#nullable enable
5
6using System.Collections.Generic;
7
8namespace osu.Framework.Bindables
9{
10 public interface IBindableDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>, ICanBeDisabled, IHasDefaultValue, IUnbindable, IHasDescription
11 where TKey : notnull
12 {
13 /// <summary>
14 /// An event which is raised when this <see cref="IBindableDictionary{TKey, TValue}"/> changes.
15 /// </summary>
16 event NotifyDictionaryChangedEventHandler<TKey, TValue>? CollectionChanged;
17
18 /// <summary>
19 /// Binds self to another bindable such that we receive any values and value limitations of the bindable we bind width.
20 /// </summary>
21 /// <param name="them">The foreign bindable. This should always be the most permanent end of the bind (ie. a ConfigManager)</param>
22 void BindTo(IBindableDictionary<TKey, TValue> them);
23
24 /// <summary>
25 /// Bind an action to <see cref="CollectionChanged"/> with the option of running the bound action once immediately
26 /// with an <see cref="NotifyDictionaryChangedAction.Add"/> event for the entire contents of this <see cref="BindableDictionary{TKey, TValue}"/>.
27 /// </summary>
28 /// <param name="onChange">The action to perform when this <see cref="BindableDictionary{TKey, TValue}"/> changes.</param>
29 /// <param name="runOnceImmediately">Whether the action provided in <paramref name="onChange"/> should be run once immediately.</param>
30 void BindCollectionChanged(NotifyDictionaryChangedEventHandler<TKey, TValue> onChange, bool runOnceImmediately = false);
31
32 /// <summary>
33 /// An alias of <see cref="BindTo"/> provided for use in object initializer scenarios.
34 /// Passes the provided value as the foreign (more permanent) bindable.
35 /// </summary>
36 sealed IBindableDictionary<TKey, TValue> BindTarget
37 {
38 set => BindTo(value);
39 }
40
41 /// <inheritdoc cref="IBindable.GetBoundCopy"/>
42 IBindableDictionary<TKey, TValue> GetBoundCopy();
43 }
44}