瀏覽代碼

LibGUI: Add TabWidget::set_tab_title(Widget&, StringView)

This lets you change the title of a tab after creating it.
Andreas Kling 5 年之前
父節點
當前提交
ee7e7e6d55
共有 2 個文件被更改,包括 17 次插入1 次删除
  1. 14 0
      Libraries/LibGUI/TabWidget.cpp
  2. 3 1
      Libraries/LibGUI/TabWidget.h

+ 14 - 0
Libraries/LibGUI/TabWidget.cpp

@@ -259,4 +259,18 @@ int TabWidget::active_tab_index() const
     }
     return -1;
 }
+
+void TabWidget::set_tab_title(Widget& tab, const StringView& title)
+{
+    for (auto& t : m_tabs) {
+        if (t.widget == &tab) {
+            if (t.title != title) {
+                t.title = title;
+                update();
+            }
+            return;
+        }
+    }
+}
+
 }

+ 3 - 1
Libraries/LibGUI/TabWidget.h

@@ -65,7 +65,9 @@ public:
 
     void remove_tab(Widget& tab) { remove_widget(tab); }
 
-    Function<void(const Widget&)> on_change;
+    void set_tab_title(Widget& tab, const StringView& title);
+
+    Function<void(Widget&)> on_change;
 
 protected:
     TabWidget();