Skip to content

Commit be48e0e

Browse files
committed
(release) v0.5.66
1 parent c43bfac commit be48e0e

9 files changed

Lines changed: 202 additions & 4 deletions

File tree

DearPyGui/dearpygui/core.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ def add_tab_bar(name: str, *, reorderable: bool = False, callback: Callable = No
346346
"""Adds a tab bar."""
347347
...
348348

349+
def add_tab_button(name: str, *, label: str = '', show: bool = True, no_reorder: bool = False, leading: bool = False, trailing: bool = False, no_tooltip: bool = False, tip: str = '', callback: Callable = None, callback_data: Any = None, parent: str = '', before: str = '') -> None:
350+
"""Adds a tab button to a tab bar"""
351+
...
352+
349353
def add_table(name: str, headers: List[str], *, callback: Callable = None, callback_data: Any = None, parent: str = '', before: str = '', width: int = 0, height: int = 200, show: bool = True) -> None:
350354
"""Adds table."""
351355
...

DearPyGui/dearpygui/demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ def apply_hue(sender, data):
659659
add_checkbox("tab 2 no_reorder##demo", callback=lambda sender, data: configure_item("tab 2##demo", no_reorder=get_value(sender)))
660660
add_checkbox("tab 2 leading##demo", callback=lambda sender, data: configure_item("tab 2##demo", leading=get_value(sender)))
661661
add_checkbox("tab 2 trailing##demo", callback=lambda sender, data: configure_item("tab 2##demo", trailing=get_value(sender)))
662+
add_checkbox("tab button trailing##demo", callback=lambda sender, data: configure_item("+##demo", trailing=get_value(sender)))
663+
add_checkbox("tab button leading##demo", callback=lambda sender, data: configure_item("+##demo", leading=get_value(sender)))
662664
with tab_bar("Basic Tabbar1##demo"):
663665
with tab("tab 1##demo"):
664666
add_text("This is the tab 1!")
@@ -668,6 +670,8 @@ def apply_hue(sender, data):
668670
add_text("This is the tab 3!")
669671
with tab("tab 4##demo"):
670672
add_text("This is the tab 4!")
673+
add_tab_button("+##demo", callback=lambda sender, data: log_debug("Pressed tab button"))
674+
add_tab_button("?##demo", callback=lambda sender, data: log_debug("Pressed tab button"))
671675

672676
with tree_node("Groups##demo123"):
673677
add_text("Groups can be used to bundle widths together so that you can use functions such as is_item_hovered or add_same_line on the whole group.")

DearPyGui/src/Core/AppItems/mvDocWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ namespace Marvel {
257257
WidgetTableEntry("spacing", "", "", "int", "layout widget, vertical spacing");
258258
WidgetTableEntry("tab", "yes", "", "bool", "layout widget, tab widget");
259259
WidgetTableEntry("tab bar", "yes", "", "string", "layout widget, tab container");
260+
WidgetTableEntry("tab button", "", "yes", "", "button for tab bars");
260261
WidgetTableEntry("table", "", "yes", "", "simple table widget");
261262
WidgetTableEntry("text", "", "", "string", "text widget");
262263
WidgetTableEntry("time picker", "", "yes", "time", "time selecting widget");

DearPyGui/src/Core/AppItems/mvTab.h

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//
99
// * mvTabBar
1010
// * mvTab
11+
// * mvTabButton
1112
//
1213
//-----------------------------------------------------------------------------
1314

@@ -145,7 +146,10 @@ namespace Marvel {
145146

146147
// set other tab's value false
147148
for (mvAppItem* child : parent->getChildren())
148-
*((mvTab*)child)->m_value =false;
149+
{
150+
if(child->getType() == mvAppItemType::TabItem)
151+
*((mvTab*)child)->m_value = false;
152+
}
149153

150154
// set current tab value true
151155
*m_value = true;
@@ -247,4 +251,79 @@ namespace Marvel {
247251

248252
};
249253

254+
//-----------------------------------------------------------------------------
255+
// mvTabButton
256+
//-----------------------------------------------------------------------------
257+
class mvTabButton : public mvAppItem
258+
{
259+
260+
public:
261+
262+
MV_APPITEM_TYPE(mvAppItemType::TabButton, "add_tab_button")
263+
264+
mvTabButton(const std::string& name)
265+
: mvAppItem(name)
266+
{
267+
}
268+
269+
void draw() override
270+
{
271+
pushColorStyles();
272+
ImGui::PushID(this);
273+
274+
if (ImGui::TabItemButton(m_label.c_str(), m_flags))
275+
mvApp::GetApp()->addCallback(getCallback(false), m_name, m_callbackData);
276+
277+
278+
ImGui::PopID();
279+
popColorStyles();
280+
}
281+
282+
void setExtraConfigDict(PyObject* dict) override
283+
{
284+
if (dict == nullptr)
285+
return;
286+
mvGlobalIntepreterLock gil;
287+
288+
// helper for bit flipping
289+
auto flagop = [dict](const char* keyword, int flag, int& flags)
290+
{
291+
if (PyObject* item = PyDict_GetItemString(dict, keyword)) ToBool(item) ? flags |= flag : flags &= ~flag;
292+
};
293+
294+
// window flags
295+
flagop("no_reorder", ImGuiTabItemFlags_NoReorder, m_flags);
296+
flagop("leading", ImGuiTabItemFlags_Leading, m_flags);
297+
flagop("trailing", ImGuiTabItemFlags_Trailing, m_flags);
298+
flagop("no_tooltip", ImGuiTabItemFlags_NoTooltip, m_flags);
299+
300+
if (m_flags & ImGuiTabItemFlags_Leading && m_flags & ImGuiTabItemFlags_Trailing)
301+
m_flags &= ~ImGuiTabItemFlags_Leading;
302+
303+
}
304+
305+
void getExtraConfigDict(PyObject* dict) override
306+
{
307+
if (dict == nullptr)
308+
return;
309+
mvGlobalIntepreterLock gil;
310+
311+
// helper to check and set bit
312+
auto checkbitset = [dict](const char* keyword, int flag, const int& flags)
313+
{
314+
PyDict_SetItemString(dict, keyword, ToPyBool(flags & flag));
315+
};
316+
317+
// window flags
318+
checkbitset("no_reorder", ImGuiTabBarFlags_Reorderable, m_flags);
319+
checkbitset("leading", ImGuiTabItemFlags_Leading, m_flags);
320+
checkbitset("trailing", ImGuiTabItemFlags_Trailing, m_flags);
321+
checkbitset("no_tooltip", ImGuiTabItemFlags_NoTooltip, m_flags);
322+
323+
}
324+
325+
private:
326+
327+
ImGuiTabItemFlags m_flags = ImGuiTabItemFlags_None;
328+
};
250329
}

DearPyGui/src/Core/PythonCommands/mvContainerInterface.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ namespace Marvel {
9191
{mvPythonDataType::String, "before", "This item will be displayed before the specified item in the parent. (runtime adding)", "''"},
9292
}, "Adds a tab to a tab bar. Must be closed with the end_tab command.", "None", "Containers") });
9393

94+
parsers->insert({ "add_tab_button", mvPythonParser({
95+
{mvPythonDataType::String, "name"},
96+
{mvPythonDataType::KeywordOnly},
97+
{mvPythonDataType::String, "label", "", "''"},
98+
{mvPythonDataType::Bool, "show", "Attempt to render", "True"},
99+
{mvPythonDataType::Bool, "no_reorder", "Disable reordering this tab or having another tab cross over this tab", "False"},
100+
{mvPythonDataType::Bool, "leading", "Enforce the tab position to the left of the tab bar (after the tab list popup button)", "False"},
101+
{mvPythonDataType::Bool, "trailing", "Enforce the tab position to the right of the tab bar (before the scrolling buttons)", "False"},
102+
{mvPythonDataType::Bool, "no_tooltip", "Disable tooltip for the given tab", "False"},
103+
{mvPythonDataType::String, "tip", "Adds a simple tooltip", "''"},
104+
{mvPythonDataType::Callable, "callback", "Registers a callback", "None"},
105+
{mvPythonDataType::Object, "callback_data", "Callback data", "None"},
106+
{mvPythonDataType::String, "parent", "Parent to add this item to. (runtime adding)", "''"},
107+
{mvPythonDataType::String, "before", "This item will be displayed before the specified item in the parent. (runtime adding)", "''"},
108+
}, "Adds a tab button to a tab bar", "None", "Containers") });
109+
94110
parsers->insert({ "add_collapsing_header", mvPythonParser({
95111
{mvPythonDataType::String, "name"},
96112
{mvPythonDataType::KeywordOnly},
@@ -560,6 +576,94 @@ namespace Marvel {
560576
return ToPyBool(false);
561577
}
562578

579+
PyObject* add_tab_button(PyObject* self, PyObject* args, PyObject* kwargs)
580+
{
581+
const char* name;
582+
const char* label = "";
583+
int show = true;
584+
int no_reorder = false;
585+
int leading = false;
586+
int trailing = false;
587+
int no_tooltip = false;
588+
const char* tip = "";
589+
PyObject* callback = nullptr;
590+
PyObject* callback_data = nullptr;
591+
const char* parent = "";
592+
const char* before = "";
593+
594+
if (!(*mvApp::GetApp()->getParsers())["add_tab_button"].parse(args, kwargs, __FUNCTION__, &name,
595+
&label, &show, &no_reorder, &leading, &trailing, &no_tooltip, &tip, &callback,
596+
&callback_data, &parent, &before))
597+
return ToPyBool(false);
598+
599+
if (std::string(parent).empty())
600+
{
601+
auto parentItem = mvApp::GetApp()->getItemRegistry().topParent();
602+
603+
if (parentItem == nullptr)
604+
{
605+
ThrowPythonException("add_tab_button must follow a call to add_tabbar.");
606+
return ToPyBool(false);
607+
}
608+
609+
else if (parentItem->getType() == mvAppItemType::TabBar)
610+
{
611+
mvAppItem* item = new mvTabButton(name);
612+
if (callback)
613+
Py_XINCREF(callback);
614+
item->setCallback(callback);
615+
if (callback_data)
616+
Py_XINCREF(callback_data);
617+
item->setCallbackData(callback_data);
618+
619+
item->checkConfigDict(kwargs);
620+
item->setConfigDict(kwargs);
621+
item->setExtraConfigDict(kwargs);
622+
if (AddItemWithRuntimeChecks(item, parent, before))
623+
return ToPyBool(true);
624+
625+
}
626+
627+
else
628+
ThrowPythonException("add_tab_bar was called incorrectly. Did you forget to call end_tab?");
629+
}
630+
631+
else
632+
{
633+
auto parentItem = mvApp::GetApp()->getItemRegistry().getItem(parent);
634+
635+
if (parentItem == nullptr)
636+
{
637+
ThrowPythonException("add_tab parent must exist.");
638+
return ToPyBool(false);
639+
}
640+
641+
else if (parentItem->getType() == mvAppItemType::TabBar)
642+
{
643+
mvAppItem* item = new mvTabButton(name);
644+
if (callback)
645+
Py_XINCREF(callback);
646+
item->setCallback(callback);
647+
if (callback_data)
648+
Py_XINCREF(callback_data);
649+
item->setCallbackData(callback_data);
650+
item->checkConfigDict(kwargs);
651+
item->setConfigDict(kwargs);
652+
item->setExtraConfigDict(kwargs);
653+
if (AddItemWithRuntimeChecks(item, parent, before))
654+
return ToPyBool(true);
655+
}
656+
657+
else
658+
{
659+
ThrowPythonException("add_tab parent must be a tab bar.");
660+
return ToPyBool(false);
661+
}
662+
}
663+
664+
return ToPyBool(false);
665+
}
666+
563667
PyObject* add_group(PyObject* self, PyObject* args, PyObject* kwargs)
564668
{
565669
const char* name;

DearPyGui/src/Core/PythonCommands/mvContainerInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Marvel {
1414
PyObject* end (PyObject* self, PyObject* args, PyObject* kwargs);
1515
PyObject* add_tab_bar (PyObject* self, PyObject* args, PyObject* kwargs);
1616
PyObject* add_tab (PyObject* self, PyObject* args, PyObject* kwargs);
17+
PyObject* add_tab_button (PyObject* self, PyObject* args, PyObject* kwargs);
1718
PyObject* add_group (PyObject* self, PyObject* args, PyObject* kwargs);
1819
PyObject* add_child (PyObject* self, PyObject* args, PyObject* kwargs);
1920
PyObject* add_window (PyObject* self, PyObject* args, PyObject* kwargs);

DearPyGui/src/Core/mvAppItems.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
// - mvTab.h
117117
// * mvTabBar
118118
// * mvTab
119+
// * mvTabButton
119120
//
120121
// - mvText.h
121122
// * mvText

DearPyGui/src/Core/mvMarvel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ namespace Marvel {
614614
ADD_PYTHON_FUNCTION(add_child)
615615
ADD_PYTHON_FUNCTION(add_tab_bar)
616616
ADD_PYTHON_FUNCTION(add_tab)
617+
ADD_PYTHON_FUNCTION(add_tab_button)
617618
ADD_PYTHON_FUNCTION(add_menu_bar)
618619
ADD_PYTHON_FUNCTION(add_menu)
619620
ADD_PYTHON_FUNCTION(add_menu_item)

docs/CHANGELOG.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ HOW TO UPDATE?
2323
- Please report any issue!
2424

2525
-----------------------------------------------------------------------
26-
VERSION 0.5.x
26+
VERSION 0.5.66
2727
-----------------------------------------------------------------------
2828

29-
Decorated log: https://github.com/hoffstadt/DearPyGui/releases/tag/v0.5.x
29+
Decorated log: https://github.com/hoffstadt/DearPyGui/releases/tag/v0.5.66
3030

3131
Changes:
3232
- Data Storage: now thread safe
3333
- set_value: now thread safe
3434
- get_value: now thread safe
3535

36+
New Commands:
37+
- Tab Button: Added "add_tab_button" command
38+
3639
New Keywords:
3740
- tab: Added "no_reorder" keyword
3841
- tab: Added "leading" keyword
@@ -42,7 +45,7 @@ New Keywords:
4245
Fixes:
4346
- tab bar: fixed tab bar callback
4447
- drawing: fixed "originy" issue #309
45-
- table: fixed "originy" issue #297
48+
- table: fixed spacing issue #297
4649

4750
-----------------------------------------------------------------------
4851
VERSION 0.5.62

0 commit comments

Comments
 (0)