@@ -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;
0 commit comments