Skip to content

Commit

Permalink
Merge pull request #2345 from AllenInstitute/feature/2345-bring-dashb…
Browse files Browse the repository at this point in the history
…oard-row-into-view

Bring currently acquiring SCI in dashboard into view
  • Loading branch information
timjarsky authored Feb 28, 2025
2 parents f4a3c4d + 616f9cd commit dca94bd
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Packages/MIES/MIES_AnalysisFunctions_Dashboard.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions Packages/MIES/MIES_GuiUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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
72 changes: 72 additions & 0 deletions Packages/tests/Basic/UTF_GuiUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// @}

0 comments on commit dca94bd

Please sign in to comment.