Skip to content

Commit

Permalink
fixed ImagePanel indexing issue on C++ side
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Mar 27, 2019
1 parent 375b9eb commit d9c9e6a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
5 changes: 2 additions & 3 deletions python/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ def cb():
imgView = ImageView(img_window, icons[0][0])

def cb(i):
if i < len(icons):
print("Selected item %i" % i)
imgView.bindImage(icons[i][0])
print("Selected item %i" % i)
imgView.bindImage(icons[i][0])
imgPanel.setCallback(cb)

imgView.setGridThreshold(3)
Expand Down
8 changes: 3 additions & 5 deletions src/example1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,9 @@ class ExampleApplication : public nanogui::Screen {
mCurrentImage = 0;
// Change the active textures.
imgPanel->setCallback([this, imageView](int i) {
if (i < mImagesData.size()) {
imageView->bindImage(mImagesData[i].first.texture());
mCurrentImage = i;
cout << "Selected item " << i << '\n';
}
imageView->bindImage(mImagesData[i].first.texture());
mCurrentImage = i;
cout << "Selected item " << i << '\n';
});
imageView->setGridThreshold(20);
imageView->setPixelInfoThreshold(20);
Expand Down
4 changes: 2 additions & 2 deletions src/imagepanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ int ImagePanel::indexForPosition(const Vector2i &p) const {
}

bool ImagePanel::mouseMotionEvent(const Vector2i &p, const Vector2i & /* rel */,
int /* button */, int /* modifiers */) {
int /* button */, int /* modifiers */) {
mMouseIndex = indexForPosition(p);
return true;
}

bool ImagePanel::mouseButtonEvent(const Vector2i &p, int /* button */, bool down,
int /* modifiers */) {
int index = indexForPosition(p);
if (index >= 0 && mCallback && down)
if (index >= 0 && index < (int) mImages.size() && mCallback && down)
mCallback(index);
return true;
}
Expand Down

0 comments on commit d9c9e6a

Please sign in to comment.