diff --git a/UI/ui_tab_widget.cpp b/UI/ui_tab_widget.cpp index 80856ea..3126a99 100644 --- a/UI/ui_tab_widget.cpp +++ b/UI/ui_tab_widget.cpp @@ -14,6 +14,8 @@ UI_tab_widget::UI_tab_widget(std::vector tab_names, size_t selected void UI_tab_widget::set_selected(size_t selected) { + if (selected >= m_tab_names.size()) + return; m_selected_tab = selected; emit ui_changed(); emit changed(m_selected_tab); @@ -27,7 +29,8 @@ void UI_tab_widget::set_visible(size_t index, bool visible) { if (index >= m_tab_visible.size()) { - m_tab_visible.resize(index + 1); + // Only allow known tab amount from constructor + return; } m_tab_visible.at(index) = visible; emit ui_changed(); @@ -39,13 +42,10 @@ bool UI_tab_widget::visible(size_t index) const void UI_tab_widget::set_tab_name(size_t index, std::string name) { - if (index >= m_tab_names.size()) + if (index >= m_tab_names.size() || index >= m_tab_visible.size()) { - m_tab_names.resize(index + 1); - } - if (index >= m_tab_visible.size()) - { - m_tab_visible.resize(index + 1, true); + // Only allow known tab amount from constructor + return; } m_tab_names.at(index) = name; emit ui_changed(); @@ -85,6 +85,7 @@ void UI_tab_widget::from_json(const json &j) } m_selected_tab = j.at("selected"); } + json UI_tab_widget::to_json(size_t id) const { json j = UI_item::to_json(id);