Skip to content

Commit a5a0201

Browse files
v-einhoffstadt
andauthored
feat: Synced tables (#2592)
* fix (mvTable): Allow creation of synced tables. * feat (tables): Added mvSyncedTables for easier creation of synced tables. --------- Co-authored-by: Jonathan Hoffstadt <[email protected]>
1 parent e56ecdb commit a5a0201

File tree

8 files changed

+167
-6
lines changed

8 files changed

+167
-6
lines changed

dearpygui/_dearpygui.pyi

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dearpygui/_dearpygui_RTD.py

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dearpygui/dearpygui.py

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mvAppItem.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ CanItemTypeBeVisible(mvAppItemType type)
565565
case mvAppItemType::mvTable:
566566
case mvAppItemType::mvTableColumn:
567567
case mvAppItemType::mvTableRow:
568+
case mvAppItemType::mvSyncedTables:
568569
case mvAppItemType::mvButton: return true;
569570
default: return false;
570571
}
@@ -1008,6 +1009,7 @@ DearPyGui::GetEntityDesciptionFlags(mvAppItemType type)
10081009
case mvAppItemType::mvTable:
10091010
case mvAppItemType::mvTableCell:
10101011
case mvAppItemType::mvTableRow:
1012+
case mvAppItemType::mvSyncedTables:
10111013
case mvAppItemType::mv2dHistogramSeries:
10121014
case mvAppItemType::mvAreaSeries:
10131015
case mvAppItemType::mvBarSeries:
@@ -3350,6 +3352,24 @@ DearPyGui::GetEntityParser(mvAppItemType type)
33503352
setup.createContextManager = true;
33513353
break;
33523354
}
3355+
case mvAppItemType::mvSyncedTables:
3356+
{
3357+
AddCommonArgs(args, (CommonParserArgs)(
3358+
MV_PARSER_ARG_ID |
3359+
MV_PARSER_ARG_PARENT |
3360+
MV_PARSER_ARG_BEFORE |
3361+
MV_PARSER_ARG_FILTER |
3362+
MV_PARSER_ARG_SHOW)
3363+
);
3364+
3365+
setup.about =
3366+
"Links all tables that are immediate children of this container so that they share "
3367+
"their state (mostly column sizes). Other children are rendered as is. This is "
3368+
"an experimental feature, use with caution.";
3369+
setup.category = { "Tables", "Containers", "Widgets" };
3370+
setup.createContextManager = true;
3371+
break;
3372+
}
33533373
case mvAppItemType::mvDrawLine:
33543374
{
33553375
AddCommonArgs(args, (CommonParserArgs)(

src/mvAppItem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ GetEntityCommand(mvAppItemType type)
336336
case mvAppItemType::mvTable: return "add_table";
337337
case mvAppItemType::mvTableColumn: return "add_table_column";
338338
case mvAppItemType::mvTableRow: return "add_table_row";
339+
case mvAppItemType::mvSyncedTables: return "add_synced_tables";
339340
case mvAppItemType::mvDrawLine: return "draw_line";
340341
case mvAppItemType::mvDrawArrow: return "draw_arrow";
341342
case mvAppItemType::mvDrawTriangle: return "draw_triangle";

src/mvAppItemTypes.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
X( mvTable ) \
5252
X( mvTableColumn ) \
5353
X( mvTableRow ) \
54+
X( mvSyncedTables ) \
5455
X( mvDrawLine ) \
5556
X( mvDrawArrow ) \
5657
X( mvDrawTriangle ) \

src/mvTables.cpp

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ void mvTable::draw(ImDrawList* drawlist, float x, float y)
168168
apply_local_theming(this);
169169

170170
{
171-
ScopedID id(uuid);
172-
173171
auto row_renderer = [&](mvAppItem* row, mvAppItem* prev_visible_row=nullptr)
174172
{
175173
//TableNextRow() ends the previous row, if any, and determines background color for it.
@@ -241,7 +239,14 @@ void mvTable::draw(ImDrawList* drawlist, float x, float y)
241239

242240
handleImmediateScroll();
243241

244-
if (ImGui::BeginTable(info.internalLabel.c_str(), _columns, _flags,
242+
const char* table_id = info.internalLabel.c_str();
243+
// If this table is a part of a synced group, use that group's internalLabel
244+
// instead. In most cases, it will contain UUID so that all groups are distinct
245+
// but tables within the group are synced.
246+
if (info.parentPtr && info.parentPtr->type == mvAppItemType::mvSyncedTables)
247+
table_id = info.parentPtr->info.internalLabel.c_str();
248+
249+
if (ImGui::BeginTable(table_id, _columns, _flags,
245250
ImVec2((float)config.width, (float)config.height), (float)_inner_width))
246251
{
247252
state.lastFrameUpdate = GContext->frame;
@@ -670,3 +675,51 @@ void mvTable::setPyValue(PyObject* value)
670675
_imguiFilter.InputBuf[i] = 0;
671676
_imguiFilter.Build();
672677
}
678+
679+
void mvSyncedTables::draw(ImDrawList* drawlist, float x, float y)
680+
{
681+
//-----------------------------------------------------------------------------
682+
// pre draw
683+
//-----------------------------------------------------------------------------
684+
685+
// show/hide
686+
if (!config.show)
687+
return;
688+
689+
// push font if a font object is attached
690+
if (font)
691+
{
692+
ImFont* fontptr = static_cast<mvFont*>(font.get())->getFontPtr();
693+
ImGui::PushFont(fontptr);
694+
}
695+
696+
// themes
697+
apply_local_theming(this);
698+
699+
//-----------------------------------------------------------------------------
700+
// draw
701+
//-----------------------------------------------------------------------------
702+
{
703+
ScopedID id(uuid);
704+
705+
for (auto& child : childslots[1])
706+
{
707+
child->draw(drawlist, ImGui::GetCursorPosX(), ImGui::GetCursorPosY());
708+
}
709+
UpdateAppItemState(state);
710+
}
711+
712+
//-----------------------------------------------------------------------------
713+
// post draw
714+
//-----------------------------------------------------------------------------
715+
716+
// handle popping themes
717+
cleanup_local_theming(this);
718+
719+
// pop font off stack
720+
if (font)
721+
ImGui::PopFont();
722+
723+
if (handlerRegistry)
724+
handlerRegistry->checkEvents(&state);
725+
}

src/mvTables.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,11 @@ class mvTable : public mvAppItem
9292
int direction;
9393
};
9494

95-
};
95+
};
96+
97+
class mvSyncedTables : public mvAppItem
98+
{
99+
public:
100+
explicit mvSyncedTables(mvUUID uuid) : mvAppItem(uuid) {}
101+
void draw(ImDrawList* drawlist, float x, float y) override;
102+
};

0 commit comments

Comments
 (0)