@robotPatrol wrote:
hi,
i am trying to move items in my scrollview element, but instead all the items clear. i have added an integer array to create indexes for the items to move to in setup, update, draw and by the clear button within the scroll view example. each time, the scroll view clears.
.h
#pragma once #include "ofMain.h" #include "ofxDatGui.h" class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); int width; ofxDatGuiTheme* theme; ofxDatGuiButton* addItem; ofxDatGuiButton* clearAll; ofxDatGuiScrollView* view; void onScrollViewEvent(ofxDatGuiScrollViewEvent e); void onAddNewItemButtonClick(ofxDatGuiButtonEvent e); void onClearAllButtonClick(ofxDatGuiButtonEvent e); int intVals[8] = {3, 5, 6, 2, 1, 4, 7, 0}; };
.cpp
#include "ofApp.h" void ofApp::setup() { ofSetWindowShape(1920, 1080); ofSetWindowPosition(ofGetScreenWidth()/2 - ofGetWidth()/2, 0); width = 540; theme = new ofxDatGuiThemeMidnight(); // create a button to attach items to the scroll view // addItem = new ofxDatGuiButton("click to add item"); addItem->setStripeVisible(false); addItem->setWidth(width); addItem->setPosition(ofGetWidth()/2 - addItem->getWidth()/2, 240); addItem->setLabelAlignment(ofxDatGuiAlignment::CENTER); addItem->onButtonEvent(this, &ofApp::onAddNewItemButtonClick); // create a scroll view that displays eight items at a time // view = new ofxDatGuiScrollView("ScrollView #1", 8); view->setWidth(width); view->setPosition(addItem->getX(), addItem->getY() + addItem->getHeight() + 1); view->onScrollViewEvent(this, &ofApp::onScrollViewEvent); // add a button to allow us to clear the scroll view out // clearAll = new ofxDatGuiButton("click to clear all items"); clearAll->setStripeVisible(false); clearAll->setWidth(width); clearAll->setPosition(ofGetWidth()/2 - clearAll->getWidth()/2, view->getY() + view->getHeight() + 1); clearAll->setLabelAlignment(ofxDatGuiAlignment::CENTER); clearAll->onButtonEvent(this, &ofApp::onClearAllButtonClick); // add a few items for testing // for(int i=0; i<8; i++) view->add("item " + ofToString(view->getNumItems() + 1)); addItem->setLabel("click to add item - " + ofToString(view->getNumItems()) + " items"); } void ofApp::update() { view->update(); addItem->update(); clearAll->update(); } void ofApp::draw() { view->draw(); addItem->draw(); clearAll->draw(); } void ofApp::onScrollViewEvent(ofxDatGuiScrollViewEvent e) { cout << e.target->getLabel() << " [index " << e.index << "] selected in [" << e.parent->getName() << "]" << endl; } void ofApp::onAddNewItemButtonClick(ofxDatGuiButtonEvent e) { view->add("item " + ofToString(view->getNumItems() + 1)); addItem->setLabel("click to add item - " + ofToString(view->getNumItems()) + " items"); } void ofApp::onClearAllButtonClick(ofxDatGuiButtonEvent e) { //view->clear(); for(int i=0; i<8; i++) { view -> move(view -> get(i), intVals[i]); // view -> move(i, intVals[i]); has the same result } addItem->setLabel("click to add item"); }
this is just a demo to recreate the problem.
in my project i am using a multimap. even though i am using indexes within the bounds of my map and my scrollview, i get
"invalid move operation, check your indices."this is my code:
an example map:
[0] = (first = 1, second = 4)
[1] = (first = 2, second = 10)
[2] = (first = 3, second = 6)
[3] = (first = 3, second = 9)
[4] = (first = 4, second = 7)
[5] = (first = 7, second = 1)
[6] = (first = 7, second = 3)
[7] = (first = 8, second = 8)
[8] = (first = 9, second = 2)
[9] = (first = 10, second = 5)for(int i = 0; i < 10; i ++) {
myscrollview -> move(myscrollview -> get((Map.begin() -> second) -1), i);
}i've also tried:
for(int i = 0; i < 10; i ++) {
myscrollview -> move((Map.begin() -> second) -1, i);
}thanks in advance,
01
Posts: 1
Participants: 1