Skip to content

Commit

Permalink
Update borealis
Browse files Browse the repository at this point in the history
xfangfang committed Nov 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent b5086ee commit 9061c8a
Showing 3 changed files with 34 additions and 7 deletions.
2 changes: 2 additions & 0 deletions wiliwili/include/view/recycling_grid.hpp
Original file line number Diff line number Diff line change
@@ -239,6 +239,8 @@ class RecyclingGrid : public brls::ScrollingFrame {
* @param downSide 是向下添加还是向上添加,当向上添加时 将 renderedFrame 的 y 减去当前列表项的高度。(y 的值只在向上添加或移除时候改变)
*/
void addCellAt(size_t index, bool downSide);

void removeCell(brls::View *view);
};

class RecyclingGridContentBox : public brls::Box {
37 changes: 31 additions & 6 deletions wiliwili/source/view/recycling_grid.cpp
Original file line number Diff line number Diff line change
@@ -247,6 +247,34 @@ void RecyclingGrid::addCellAt(size_t index, bool downSide) {
brls::Logger::verbose("Cell #{} - added", index);
}

void RecyclingGrid::removeCell(brls::View* view) {
if (!view) return;

// Find the index of the view
size_t index;
bool found = false;
auto& children = this->contentBox->getChildren();

for (size_t i = 0; i < children.size(); i++) {
View* child = children[i];

if (child == view) {
found = true;
index = i;
break;
}
}

if (!found) return;

// Remove it
children.erase(children.begin() + index);

view->willDisappear(true);

this->invalidate();
}

void RecyclingGrid::setDataSource(RecyclingGridDataSource* source) {
if (this->dataSource) delete this->dataSource;

@@ -263,7 +291,7 @@ void RecyclingGrid::reloadData() {
auto children = this->contentBox->getChildren();
for (auto const& child : children) {
queueReusableCell((RecyclingGridItem*)child);
this->contentBox->removeView(child, false);
this->removeCell(child);
}

visibleMin = UINT_MAX;
@@ -391,8 +419,6 @@ void RecyclingGrid::itemsRecyclingLoop() {
while (true) {
RecyclingGridItem* minCell = nullptr;
for (auto it : contentBox->getChildren())

// todo: contentBox 循环时加锁?it出现过空指针报错
if (*((size_t*)it->getParentUserData()) == visibleMin) minCell = (RecyclingGridItem*)it;

// 当第一个cell的顶部 与 组件顶部的距离大于 preFetchLine 行元素的距离时结束
@@ -408,7 +434,7 @@ void RecyclingGrid::itemsRecyclingLoop() {
renderedFrame.size.height -= minCell->getIndex() % spanCount == 0 ? cellHeight + estimatedRowSpace : 0;

queueReusableCell(minCell);
this->contentBox->removeView(minCell, false);
this->removeCell(minCell);

brls::Logger::verbose("Cell #{} - destroyed", visibleMin);

@@ -418,7 +444,6 @@ void RecyclingGrid::itemsRecyclingLoop() {
// 下方元素自动销毁
while (true) {
RecyclingGridItem* maxCell = nullptr;
// todo: contentBox 循环时加锁?it出现过空指针报错
for (auto it : contentBox->getChildren())
if (*((size_t*)it->getParentUserData()) == visibleMax) maxCell = (RecyclingGridItem*)it;

@@ -437,7 +462,7 @@ void RecyclingGrid::itemsRecyclingLoop() {
renderedFrame.size.height -= maxCell->getIndex() % spanCount == 0 ? cellHeight + estimatedRowSpace : 0;

queueReusableCell(maxCell);
this->contentBox->removeView(maxCell, false);
this->removeCell(maxCell);

brls::Logger::verbose("Cell #{} - destroyed", visibleMax);

0 comments on commit 9061c8a

Please sign in to comment.