aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/model/IListChangeNotify.h
blob: a9fcd65b9632286762a916fa7cb9dcb1dde3a81e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include "../Base.h"
#include "cru/common/Base.h"
#include "cru/common/Event.h"

namespace cru::ui::model {
enum ListChangeType {
  kItemAdd,
  kItemRemove,
  kItemSet,
  kItemMove,
  kClear,
};

struct CRU_UI_API ListChange {
  ListChangeType type;
  union {
    Index position;
  };
  union {
    Index count;
    Index new_position;
  };

  constexpr static ListChange ItemAdd(Index index, Index count = 1) {
    return {ListChangeType::kItemAdd, index, count};
  }

  constexpr static ListChange ItemRemove(Index index, Index count = 1) {
    return {ListChangeType::kItemRemove, index, count};
  }

  constexpr static ListChange ItemSet(Index index, Index count = 1) {
    return {ListChangeType::kItemSet, index, count};
  }

  constexpr static ListChange ItemMove(Index position, Index new_position) {
    return {ListChangeType::kItemMove, position, new_position};
  }

  constexpr static ListChange Clear() { return {ListChangeType::kClear}; }
};

struct CRU_UI_API IListChangeNotify : virtual Interface {
  virtual IEvent<ListChange>* ListChangeEvent() = 0;
};
}  // namespace cru::ui::model