Skip to main content
ilyus
Senior II
July 12, 2021
Question

ScrollWheel UpdateItemCallbackHandler Not Firing After Nth Element

  • July 12, 2021
  • 4 replies
  • 1099 views

Windows 10, TouchGFX Designer 4.17.0, STM32CubeIDE 1.6.1, Simulator (STM32F469 Disco board present).

What I'm trying to do:

I'm creating a ScrollWheel - manually, without TouchGFX Designer. I use auto-generated ScrollWheel code from Base.cpp as a base code for my own element in View.cpp so that I can customize stuff the way I want (generated on another screen - I just needed pieces of auto-generated code as a base for my code).

In View.cpp (and hpp), I have manually created ScrollWheel with one custom container (no special container for the selected item). The custom container itself is pre-created in Designer, I only link my own scrollwheel to that custom container (attempts at creating custom container outside TouchGFX Designer failed). Then I add callback and whatnot. And it even kinda works correctly (code coming).

What goes wrong:

What's interesting is that my ScrollWheel's update item callback function is only called while I scroll between 0-6th elements out of 0-9 elements (=touchgfx_print inside callbackhandler writing stuff). If I drag the scrollwheel so that element 7 (or 8 or 9) is in the "Selected" position, the callback handler doesn't fire, doesn't do printf and other stuff. Only between elements 0-6 it works flawlessly.

Clearly something happens around element 6, but I don't understand what.

Here's some code, how I created the monster that I created:

View.cpp:

void ScreenMeasurementsView::generatePickProgramWheel() {
	pickProgramScrollWheel.initialize();
	for (int i = 0; i < pickProgramScrollWheelListItems.getNumberOfDrawables(); i++) {
		pickProgramScrollWheelListItems[i].initialize();
	}
	pickProgramScrollWheel.setPosition(210, 215, 190, 170);
	pickProgramScrollWheel.setHorizontal(false);
	pickProgramScrollWheel.setCircular(false);
	pickProgramScrollWheel.setEasingEquation(touchgfx::EasingEquations::backEaseOut);
	pickProgramScrollWheel.setSwipeAcceleration(5);
	pickProgramScrollWheel.setDragAcceleration(5);
	pickProgramScrollWheel.setNumberOfItems(10);
	pickProgramScrollWheel.setSelectedItemOffset(-5);
	pickProgramScrollWheel.setDrawableSize(50, 5);
	pickProgramScrollWheel.setDrawables(pickProgramScrollWheelListItems, updateItemCallback);
	pickProgramScrollWheel.animateToItem(0, 0);
 
	add(pickProgramScrollWheel);
 
}
void ScreenMeasurementsView::updateItemCallbackHandler(touchgfx::DrawableListItemsInterface *items, int16_t containerIndex, int16_t itemIndex) {
	if (items == &pickProgramScrollWheelListItems) {
		touchgfx::Drawable *d = items->getDrawable(containerIndex);
		pickProgramCContainer *cc = (pickProgramCContainer*) d;
		pickProgramScrollWheelUpdateItem(*cc, itemIndex);
		cc->setNumber(itemIndex);
		//cc->setNumber(pickProgramScrollWheel.getSelectedItem());
		for(int i=0;i<10000;i++);
		Unicode::snprintf(selectProgramTextAreaBuffer, WILDCARD_BUFFER_MAX_SIZE, "%d", pickProgramScrollWheel.getSelectedItem());
		selectProgramTextArea.resizeToCurrentText();
		selectProgramTextArea.invalidate();
		//osDelay();
		touchgfx_printf("Current item: %d\n", pickProgramScrollWheel.getSelectedItem());
 
	}
}

Here I create my scrollwheel. Also, every time an item is updated, I also set setNumber - which simply writes the number of every element into dummy elements (its name and code stolen from TouchGFX documentation on ScrollWheel, modified, removed icon changing part) - and does it correctly - my elements initially don't have text ("WC_1WC_2" is its initial content to be accurate, two wildcards with buffers), this function writes stuff to their wildcard buffers correcty, even to elements that I can't select, what I see in simulator is "Program 0", "Program 1"..."Program 9" (all numbered correctly). Also, I write selected item's number into a separate independently created textArea next to my scrollwheel. And I do touchgfx_printf with the selected item number too. It's these numbers that have problems crossing "6" (and showing 7, 8 or 9).

Because the callback doesn't get called when I have 6 or larger selected.

In the element custom container, I actually don't have a textArea, I create it manually in pickProgramCContainer.cpp like this:

void pickProgramCContainer::generateTextAreaW2WC() {
	programNameTextArea.setXY(0, 0);
	programNameTextArea.setPosition(0, 12, 190, 50);
	programNameTextArea.setColor(touchgfx::Color::getColorFromRGB(255, 247, 20));
	programNameTextArea.setLinespacing(0);
	touchgfx::Unicode::snprintf(programNameTextAreaBuffer1[0], WILDCARD_BUFFER_MAX_SIZE, "WC_1");
	programNameTextArea.setWildcard1(programNameTextAreaBuffer1[0]);
	touchgfx::Unicode::snprintf(programNameTextAreaBuffer2[0], WILDCARD_BUFFER_MAX_SIZE, "WC_2");
	programNameTextArea.setWildcard2(programNameTextAreaBuffer2[0]);
	//programNameTextArea.resizeToCurrentText();
	programNameTextArea.setTypedText(touchgfx::TypedText(T_TAHOMA_BOLD_20_CENTER_2WC_RESOURCE));
	add(programNameTextArea);
}

Obviously, whatever needs to be created in header files, is created (variables for wildcard buffers, textarea itself etc). But then again, the text inside elements actually is correct for all elements. I don't think the problem is connected with this textArea-in-the-container part of the code.

Also, all callbacks are hooked up. Duh, otherwise they wouldn't work for the first elements:

ScreenMeasurementsView::ScreenMeasurementsView() :
		WAIT_TIMER_TICKS(0), buttonCallbackView(this, &ScreenMeasurementsView::buttonCallbackHandlerView), flexButtonCallbackView(this, &ScreenMeasurementsView::flexButtonCallbackHandlerView), updateItemCallback(
				this, &ScreenMeasurementsView::updateItemCallbackHandler) {
}

WAIT-bla-bla is my custom function, which I'm not using atm, doesn't do anything, not relevant here.

Also, in View.HPP, this is how scrollWheel is declared

touchgfx::ScrollWheel pickProgramScrollWheel;
	touchgfx::DrawableListItems<pickProgramCContainer, 64> pickProgramScrollWheelListItems;

As far as I have figured, that "64" means the number of elements that are simultaneously visible. I tried 2, I tried 4, I tried 64. When 2, I only see 2 elements at a time on screen. When more than 2, I see 3 (more don't fit in the scrollwheel anyway). This number didn't affect callback firing behavior.

If you want to see some other pieces of code, you're welcome to ask, I do realize my presentation of my situation can be a little chaotic, also given its unusual nature. Can't post entire file as a single View.cpp already has over 400 lines of code, mostly creating different containers and textareas, and they all work OK and they're completely independent from this piece, but if you really ask, I will create a new empty screen and try to reproduce the problem without unnecessary and/or unrelated stuff.

This topic has been closed for replies.

4 replies

Alexandre RENOUX
Visitor II
July 14, 2021

Hello ilyus,

Implementing a ScrollWheel by code should be definitely possible.

I see that the problem is not related to a board, so could you enclose a UI only project ? (in order to make things easier and having a small enough zip file)

To do so, create a new project as Blank UI and then click Edit -> Import UI -> Select the correct .touchgfx of your project with F469-DISCO and validate.

If you don't understand what I just said, just send me your current project and I'll do the isolation myself.

/Alexandre

ilyus
ilyusAuthor
Senior II
July 20, 2021

Of course, will do tomorrow. However, the screens in TouchGFX where I generate stuff are all blank/almost blank anyway, I create EVERYTHING with code only. But sure, instructions seem simple. Guess I'll send you both things. (the project moved on since then, but I was working on another screen, the problem with only elements 0-6 reacting and 7-9 noy is still there)