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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#if defined(Hiro_IconView)
auto mIconView::allocate() -> pObject* {
return new pIconView(*this);
}
auto mIconView::destruct() -> void {
for(auto& item : state.items) item->destruct();
mWidget::destruct();
}
//
auto mIconView::append(sIconViewItem item) -> type& {
state.items.append(item);
item->setParent(this, itemCount() - 1);
signal(append, item);
return *this;
}
auto mIconView::backgroundColor() const -> Color {
return state.backgroundColor;
}
auto mIconView::batchable() const -> bool {
return state.batchable;
}
auto mIconView::batched() const -> vector<IconViewItem> {
vector<IconViewItem> items;
for(auto& item : state.items) {
if(item->selected()) items.append(item);
}
return items;
}
auto mIconView::doActivate() const -> void {
if(state.onActivate) return state.onActivate();
}
auto mIconView::doChange() const -> void {
if(state.onChange) return state.onChange();
}
auto mIconView::doContext() const -> void {
if(state.onContext) return state.onContext();
}
auto mIconView::flow() const -> Orientation {
return state.flow;
}
auto mIconView::foregroundColor() const -> Color {
return state.foregroundColor;
}
auto mIconView::item(unsigned position) const -> IconViewItem {
if(position < itemCount()) return state.items[position];
return {};
}
auto mIconView::itemCount() const -> unsigned {
return state.items.size();
}
auto mIconView::items() const -> vector<IconViewItem> {
vector<IconViewItem> items;
for(auto& item : state.items) items.append(item);
return items;
}
auto mIconView::onActivate(const function<void ()>& callback) -> type& {
state.onActivate = callback;
return *this;
}
auto mIconView::onChange(const function<void ()>& callback) -> type& {
state.onChange = callback;
return *this;
}
auto mIconView::onContext(const function<void ()>& callback) -> type& {
state.onContext = callback;
return *this;
}
auto mIconView::orientation() const -> Orientation {
return state.orientation;
}
auto mIconView::remove(sIconViewItem item) -> type& {
signal(remove, item);
state.items.remove(item->offset());
for(auto n : range(item->offset(), itemCount())) {
state.items[n]->adjustOffset(-1);
}
item->setParent();
return *this;
}
auto mIconView::reset() -> type& {
signal(reset);
for(auto& item : state.items) item->setParent();
state.items.reset();
return *this;
}
auto mIconView::selected() const -> IconViewItem {
for(auto& item : state.items) {
if(item->selected()) return item;
}
return {};
}
auto mIconView::setBackgroundColor(Color color) -> type& {
state.backgroundColor = color;
signal(setBackgroundColor, color);
return *this;
}
auto mIconView::setBatchable(bool batchable) -> type& {
state.batchable = batchable;
signal(setBatchable, batchable);
return *this;
}
auto mIconView::setFlow(Orientation flow) -> type& {
state.flow = flow;
signal(setFlow, flow);
return *this;
}
auto mIconView::setForegroundColor(Color color) -> type& {
state.foregroundColor = color;
signal(setForegroundColor, color);
return *this;
}
auto mIconView::setOrientation(Orientation orientation) -> type& {
state.orientation = orientation;
signal(setOrientation, orientation);
return *this;
}
auto mIconView::setParent(mObject* parent, signed offset) -> type& {
for(auto n : rrange(state.items)) state.items[n]->destruct();
mObject::setParent(parent, offset);
for(auto& item : state.items) item->setParent(this, item->offset());
return *this;
}
auto mIconView::setSelected(const vector<signed>& selections) -> type& {
bool selectAll = selections(0, 0) == ~0;
for(auto& item : state.items) item->state.selected = selectAll;
if(selectAll) return signal(setItemSelectedAll), *this;
if(!selections) return signal(setItemSelectedNone), *this;
for(auto& position : selections) {
if(position >= itemCount()) continue;
state.items[position]->state.selected = true;
}
signal(setItemSelected, selections);
return *this;
}
#endif
|