Skip to content

Commit

Permalink
fix for scrollview not reseting itself properly after items deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
braitsch committed Feb 7, 2016
1 parent 711bf79 commit 9ab2545
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
/* Begin PBXFileReference section */
8A17732D1C3B249A006561BD /* ofxDatGuiTheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiTheme.h; sourceTree = "<group>"; };
8A17732E1C3B249A006561BD /* ofxDatGuiThemes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiThemes.h; sourceTree = "<group>"; };
8A2BB1B61C5AEA09002D8003 /* Line.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Line.h; sourceTree = "<group>"; };
8A4166C91C5AB741005F9557 /* ofxDatGuiScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiScrollView.h; sourceTree = "<group>"; };
8AB358191BB23256002AC802 /* ofxDatGui2dPad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGui2dPad.h; sourceTree = "<group>"; };
8AB3581A1BB23256002AC802 /* ofxDatGuiButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxDatGuiButton.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -178,6 +179,7 @@
E4B69E1D0A3A1BDC003C02F2 /* main.cpp */,
E4B69E1E0A3A1BDC003C02F2 /* ofApp.cpp */,
E4B69E1F0A3A1BDC003C02F2 /* ofApp.h */,
8A2BB1B61C5AEA09002D8003 /* Line.h */,
);
path = src;
sourceTree = SOURCE_ROOT;
Expand Down
27 changes: 17 additions & 10 deletions src/components/ofxDatGuiScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class ofxDatGuiScrollView : public ofxDatGuiComponent {
return static_cast<ofxDatGuiButton*>(children[index]);
}

ofxDatGuiButton* get(string name)
{
for(auto i:children) if (i->is(name)) return static_cast<ofxDatGuiButton*>(i);
return nullptr;
}

void swap(int index1, int index2)
{
if (isValidIndex(index1) && isValidIndex(index2) && index1 != index2){
Expand Down Expand Up @@ -223,6 +229,7 @@ class ofxDatGuiScrollView : public ofxDatGuiComponent {
ofColor mBackground;
ofxDatGuiTheme* mTheme;

int mY;
int mSpacing;
int mNumVisible;
bool mAutoHeight;
Expand All @@ -237,26 +244,26 @@ class ofxDatGuiScrollView : public ofxDatGuiComponent {
{
if (children.size() > 0 && mRect.inside(e.x, e.y) == true){
float sy = e.scrollY * 2;
int topY = children.front()->getY();
int btnH = children.front()->getHeight() + mSpacing;
int minY = mRect.height + mSpacing - (children.size() * btnH);
bool allowScroll = false;
mY = children.front()->getY();
if (sy < 0){
if (topY > minY){
topY += sy;
if (topY < minY) topY = minY;
if (mY > minY){
mY += sy;
if (mY < minY) mY = minY;
allowScroll = true;
}
} else if (sy > 0){
if (topY < 0){
topY += sy;
if (topY > 0) topY = 0;
if (mY < 0){
mY += sy;
if (mY > 0) mY = 0;
allowScroll = true;
}
}
if (allowScroll){
children.front()->setPosition(0, topY);
for(int i=0; i<children.size(); i++) children[i]->setPosition(0, topY + (btnH * i));
children.front()->setPosition(0, mY);
for(int i=0; i<children.size(); i++) children[i]->setPosition(0, mY + (btnH * i));
}
}
}
Expand All @@ -275,7 +282,7 @@ class ofxDatGuiScrollView : public ofxDatGuiComponent {

void positionItems()
{
int y = children.front()->getY();
int y = mY;
for(auto i:children){
i->setPosition(0, y);
y = i->getY() + i->getHeight() + mSpacing;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ofxDatGuiSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class ofxDatGuiSlider : public ofxDatGuiComponent {

bool hitTest(ofPoint m)
{
if (!mEnabled){
if (!mEnabled || !mVisible){
return false;
} else if (m.x>=x+mLabel.width && m.x<= x+mLabel.width+mSliderWidth && m.y>=y+mStyle.padding && m.y<= y+mStyle.height-mStyle.padding){
return true;
Expand Down

0 comments on commit 9ab2545

Please sign in to comment.