From 9803c31c1d41183f0fb19c2036f764467a57c06c Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Mon, 3 Feb 2025 15:50:54 +0100 Subject: [PATCH 1/2] ScrollListboxIntoView: Add it with tests --- Packages/MIES/MIES_GuiUtilities.ipf | 35 +++++++++++ Packages/tests/Basic/UTF_GuiUtilities.ipf | 72 +++++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/Packages/MIES/MIES_GuiUtilities.ipf b/Packages/MIES/MIES_GuiUtilities.ipf index 00e64214ce..ef2f1c4ef3 100644 --- a/Packages/MIES/MIES_GuiUtilities.ipf +++ b/Packages/MIES/MIES_GuiUtilities.ipf @@ -2438,3 +2438,38 @@ Function ResizeControlsSafe(STRUCT WMWinHookStruct &s) // return zero so that other hooks are called as well return 0 End + +/// @brief Scroll in the given ListBox the row into view +/// +/// @retval 0 if scrolling was done, 1 if not +Function ScrollListboxIntoView(string win, string ctrl, variable row) + + variable startRow, numVisRows + + ControlInfo/W=$win $ctrl + ASSERT(V_flag == CONTROL_TYPE_LISTBOX, "Expected a listbox") + + WAVE/Z/SDFR=$S_DataFolder listWave = $S_Value + ASSERT(WaveExists(listWave), "Missing list wave") + + ASSERT(!IsNaN(row), "Expected row to be not NaN") + row = limit(row, 0, DimSize(listWave, ROWS)) + + numVisRows = trunc(V_height / V_rowHeight) + + if(row < V_startRow) + // move row to the first visible row + ListBox $ctrl, row=row, win=$win + + return 0 + endif + + if(row >= (V_startRow + numVisRows)) + // move row to the last visible row + ListBox $ctrl, row=(row - numVisRows + 1), win=$win + + return 0 + endif + + return 1 +End diff --git a/Packages/tests/Basic/UTF_GuiUtilities.ipf b/Packages/tests/Basic/UTF_GuiUtilities.ipf index f9ad315b15..48d7925f55 100644 --- a/Packages/tests/Basic/UTF_GuiUtilities.ipf +++ b/Packages/tests/Basic/UTF_GuiUtilities.ipf @@ -386,3 +386,75 @@ static Function NoNullReturnFromGetSetVariableString() End /// @} + +/// ScrollListboxIntoView +/// @{ + +static Function GetTopRow_IGNORE(string win, string ctrl) + + Controlinfo/W=$win $ctrl + + return V_startRow +End + +static Function TestScrollListboxIntoView() + + string win, ctrl + variable topRow, ret + + Make/T listWave = num2str(p) + + NewPanel/N=testpanelLB + win = S_name + + ListBox list, listWave=listWave, size={300, 100} + ctrl = "list" + DoUpdate/W=$win + + try + ScrollListboxIntoView(win, ctrl, NaN) + FAIL() + catch + CHECK_NO_RTE() + endtry + + DoUpdate/W=$win + topRow = GetTopRow_IGNORE(win, ctrl) + CHECK_EQUAL_VAR(topRow, 0) + + // clips to zero + ret = ScrollListboxIntoView(win, ctrl, -1) + CHECK_EQUAL_VAR(ret, 1) + + DoUpdate/W=$win + topRow = GetTopRow_IGNORE(win, ctrl) + CHECK_EQUAL_VAR(topRow, 0) + + // clips to available rows + ret = ScrollListboxIntoView(win, ctrl, 500) + CHECK_EQUAL_VAR(ret, 0) + + DoUpdate/W=$win + topRow = GetTopRow_IGNORE(win, ctrl) + CHECK_EQUAL_VAR(topRow, 124) + + // moves to the top if lower than current + ret = ScrollListboxIntoView(win, ctrl, 50) + CHECK_EQUAL_VAR(ret, 0) + + DoUpdate/W=$win + topRow = GetTopRow_IGNORE(win, ctrl) + CHECK_EQUAL_VAR(topRow, 50) + + // and to the bottom if larger + ret = ScrollListboxIntoView(win, ctrl, 75) + CHECK_EQUAL_VAR(ret, 0) + + DoUpdate/W=$win + topRow = GetTopRow_IGNORE(win, ctrl) + CHECK_EQUAL_VAR(topRow, 71) + + KillOrMoveToTrash(wv = listWave) +End + +/// @} From 616f9cd5f9750f6f61dee9bb700dfe46104bf998 Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Mon, 3 Feb 2025 16:08:52 +0100 Subject: [PATCH 2/2] AD_Update: Bring the newest dashboard entry into view --- Packages/MIES/MIES_AnalysisFunctions_Dashboard.ipf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Packages/MIES/MIES_AnalysisFunctions_Dashboard.ipf b/Packages/MIES/MIES_AnalysisFunctions_Dashboard.ipf index b78085117a..867ba14ffc 100644 --- a/Packages/MIES/MIES_AnalysisFunctions_Dashboard.ipf +++ b/Packages/MIES/MIES_AnalysisFunctions_Dashboard.ipf @@ -69,6 +69,8 @@ Function AD_Update(string win) selWave[][][%$LISTBOX_LAYER_FOREGROUND] = AD_GetColorForResultMessage(listWave[p][%Result]) helpWave[] = "Result:\r" + listWave[p][%Result] + + ScrollListboxIntoView(mainPanel, "list_dashboard", Inf) else SetNumberInWaveNote(listWave, NOTE_INDEX, 0) endif