using namespace ucl;
- const TString SLOT_PART_FMT = {"swallow.cell_%d"};
+ const TString SLOT_PART_FMT {"swallow.cell_%d"};
+
+ constexpr ElmStyle ITEM_BTN_STYLE {"gallery_image"};
+
+ constexpr SmartEvent BTN_CLICKED {"clicked"};
}}}
namespace gallery {
class ImageGrid::Slot {
private:
- class Item {
+ class Item : public RefCountAware {
public:
- Item(const ImageGrid &imageGrid, Widget &parent) :
+ friend class RefCountObj<Item>;
+ Item(RefCountObjBase &rc,
+ const ImageGrid &imageGrid, Widget &parent) :
+ RefCountAware(&rc),
m_imageGrid(imageGrid),
- m_image(evas_object_image_filled_add(parent.getEvas())),
+ m_btn(elm_button_add(parent)),
+ m_image(evas_object_image_filled_add(m_btn.getEvas())),
m_realizeIndex(-1),
m_wasUpdated(false)
{
+ m_btn.setFocusAlowed(false);
+ m_btn.setStyle(impl::ITEM_BTN_STYLE);
+ m_btn.setContent(m_image);
+ show(m_btn);
show(m_image);
+
+ m_btn.addEventHandler(impl::BTN_CLICKED, WEAK_DELEGATE(
+ Item::onClicked, asWeak(*this)));
}
Widget &getWidget()
{
- return m_image;
+ return m_btn;
}
void setImageLoadSize(const int value)
}
if (!m_wasUpdated) {
- makeTransparent(m_image);
+ makeTransparent(m_btn);
}
}
m_wasUpdated = true;
if (isEmpty(params.imagePath)) {
- makeTransparent(m_image);
+ makeTransparent(m_btn);
return true;
}
evas_object_image_size_get(m_image, &w, &h);
m_image.setARHint(WidgetARHint::NEITHER, w, h);
- makeWhite(m_image);
+ makeWhite(m_btn);
return true;
}
+ private:
+ void onClicked(Widget &wifget, void *eventInfo)
+ {
+ if (isRealized()) {
+ m_imageGrid.handleItemClick(m_realizeIndex);
+ }
+ }
+
private:
const ImageGrid &m_imageGrid;
+ StyledWidget m_btn;
Widget m_image;
int m_realizeIndex;
bool m_wasUpdated;
const int length = m_info.slotLens[isOdd];
for (int i = 0; i < length; ++i) {
- m_items.emplace_back(new Item(imageGrid, m_layout));
+ m_items.emplace_back(makeShared<Item>(imageGrid, m_layout));
m_layout.setContent(
EdjePart(impl::SLOT_PART_FMT.format(i)),
private:
const Info &m_info;
- std::vector<std::unique_ptr<Item>> m_items;
+ std::vector<SharedRef<Item>> m_items;
Layout m_layout;
bool m_isRealized;
};
m_scrollerSize(1), // Must not be 0
m_scrollOffset(0),
- m_unrealizeLock(0)
+ m_unrealizeLock(0),
+ m_eventsLock(0)
{
prepare();
+ ++m_eventsLock;
+
updateSlotCount();
updatePadSizes();
updateScrollBias();
updateRectMins();
+
+ --m_eventsLock;
}
const ImageGrid::Info &ImageGrid::getInfo(const Type type)
createCircleScroller();
m_scroller->addEventHandler(WidgetEvent::RESIZE,
- WEAK_DELEGATE(ImageGrid::onScrollerResize, asWeak(this)));
+ WEAK_DELEGATE(ImageGrid::onScrollerResize, asWeak(*this)));
m_scroller->addEventHandler(WidgetEvent::MOVE,
- WEAK_DELEGATE(ImageGrid::onScrollerMove, asWeak(this)));
+ WEAK_DELEGATE(ImageGrid::onScrollerMove, asWeak(*this)));
m_box.addEventHandler(WidgetEvent::MOVE,
- WEAK_DELEGATE(ImageGrid::onBoxMove, asWeak(this)));
+ WEAK_DELEGATE(ImageGrid::onBoxMove, asWeak(*this)));
}
void ImageGrid::createCircleScroller()
return;
}
+ ++m_eventsLock;
+
unrealizeSlots(0, m_slotCount);
m_itemCount = count;
realizeSlots();
updateRectMins();
+
+ --m_eventsLock;
}
void ImageGrid::update()
}
}
+ void ImageGrid::handleItemClick(const int itemIndex) const
+ {
+ if (m_listener) {
+ m_listener->onItemClicked(itemIndex);
+ }
+ }
+
bool ImageGrid::updateSlotCount()
{
const int newSlotCount = calcSlotCount();
void ImageGrid::handleScrolling()
{
+ if (m_eventsLock > 0) {
+ WLOG("Event handling was blocked!");
+ return;
+ }
+ ++m_eventsLock;
+
if (updateScrollOffset() && updateBeginSlotIndex()) {
realizeSlots();
updateRectMins();
}
+
+ --m_eventsLock;
}
void ImageGrid::handleResize()
{
+ if (m_eventsLock > 0) {
+ WLOG("Event handling was blocked!");
+ return;
+ }
+ ++m_eventsLock;
+
if (updateScrollerSize()) {
bool needRealize = false;
}
updateRectMins();
}
+
+ --m_eventsLock;
}
void ImageGrid::onScrollerResize(Widget &sender, void *eventInfo)