Skip to content

Commit

Permalink
feat: Add scroll functions to tables #1947 (#2112)
Browse files Browse the repository at this point in the history
* feat: get_x_scroll/get_y_scroll work for tables

* feat: set_x_scroll/set_y_scroll work for tables
  • Loading branch information
v-ein authored Jul 17, 2023
1 parent 0ab014e commit 0499eee
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
48 changes: 42 additions & 6 deletions src/dearpygui_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,16 @@ set_x_scroll(PyObject* self, PyObject* args, PyObject* kwargs)
pChild->configData.scrollX = value;
pChild->configData._scrollXSet = true;
}
else if (window->type == mvAppItemType::mvTable)
{
auto pChild = static_cast<mvTable*>(window);
pChild->_scrollX = value;
pChild->_scrollXSet = true;
}
else
{
mvThrowPythonError(mvErrorCode::mvIncompatibleType, "set_x_scroll",
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow", window);
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow, mvTable", window);
}

return GetPyNone();
Expand Down Expand Up @@ -279,10 +285,16 @@ set_y_scroll(PyObject* self, PyObject* args, PyObject* kwargs)
pChild->configData.scrollY = value;
pChild->configData._scrollYSet = true;
}
else if (window->type == mvAppItemType::mvTable)
{
auto pChild = static_cast<mvTable*>(window);
pChild->_scrollY = value;
pChild->_scrollYSet = true;
}
else
{
mvThrowPythonError(mvErrorCode::mvIncompatibleType, "set_y_scroll",
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow", window);
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow, mvTable", window);
}

return GetPyNone();
Expand Down Expand Up @@ -323,10 +335,16 @@ get_x_scroll(PyObject* self, PyObject* args, PyObject* kwargs)

return ToPyFloat(pChild->configData.scrollX);
}
else if (window->type == mvAppItemType::mvTable)
{
auto pTable = static_cast<mvTable*>(window);

return ToPyFloat(pTable->_scrollX);
}
else
{
mvThrowPythonError(mvErrorCode::mvIncompatibleType, "get_x_scroll",
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow", window);
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow, mvTable", window);
}

return GetPyNone();
Expand Down Expand Up @@ -367,10 +385,16 @@ get_y_scroll(PyObject* self, PyObject* args, PyObject* kwargs)

return ToPyFloat(pChild->configData.scrollY);
}
else if (window->type == mvAppItemType::mvTable)
{
auto pTable = static_cast<mvTable*>(window);

return ToPyFloat(pTable->_scrollY);
}
else
{
mvThrowPythonError(mvErrorCode::mvIncompatibleType, "get_y_scroll",
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow", window);
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow, mvTable", window);
}

return GetPyNone();
Expand Down Expand Up @@ -411,10 +435,16 @@ get_x_scroll_max(PyObject* self, PyObject* args, PyObject* kwargs)

return ToPyFloat(pChild->configData.scrollMaxX);
}
else if (window->type == mvAppItemType::mvTable)
{
auto pTable = static_cast<mvTable*>(window);

return ToPyFloat(pTable->_scrollMaxX);
}
else
{
mvThrowPythonError(mvErrorCode::mvIncompatibleType, "get_x_scroll_max",
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow", window);
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow, mvTable", window);
}

return GetPyNone();
Expand Down Expand Up @@ -455,10 +485,16 @@ get_y_scroll_max(PyObject* self, PyObject* args, PyObject* kwargs)

return ToPyFloat(pChild->configData.scrollMaxY);
}
else if (window->type == mvAppItemType::mvTable)
{
auto pTable = static_cast<mvTable*>(window);

return ToPyFloat(pTable->_scrollMaxY);
}
else
{
mvThrowPythonError(mvErrorCode::mvIncompatibleType, "set_y_scroll_max",
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow", window);
"Incompatible type. Expected types include: mvWindowAppItem, mvChildWindow, mvTable", window);
}

return GetPyNone();
Expand Down
22 changes: 22 additions & 0 deletions src/mvTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,28 @@ void mvTable::draw(ImDrawList* drawlist, float x, float y)
columnnum++;
}

if (_scrollXSet)
{
if (_scrollX < 0.0f)
ImGui::SetScrollHereX(1.0f);
else
ImGui::SetScrollX(_scrollX);
_scrollXSet = false;
}
if (_scrollYSet)
{
if (_scrollY < 0.0f)
ImGui::SetScrollHereY(1.0f);
else
ImGui::SetScrollY(_scrollY);
_scrollYSet = false;
}

_scrollX = ImGui::GetScrollX();
_scrollMaxX = ImGui::GetScrollMaxX();
_scrollY = ImGui::GetScrollY();
_scrollMaxY = ImGui::GetScrollMaxY();

ImGui::EndTable();
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/mvTables.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class mvTable : public mvAppItem
bool _tableHeader = true;
bool _useClipper = false;

float _scrollX = 0.0f;
float _scrollY = 0.0f;
float _scrollMaxX = 0.0f;
float _scrollMaxY = 0.0f;
bool _scrollXSet = false;
bool _scrollYSet = false;

std::vector<bool> _columnColorsSet;
std::vector<bool> _rowColorsSet;
std::vector<bool> _rowSelectionColorsSet;
Expand Down

0 comments on commit 0499eee

Please sign in to comment.