implement separated append method for tab widget

This commit is contained in:
yggverse 2024-10-06 17:41:17 +03:00
parent b705fc224d
commit 227cfb30a1
2 changed files with 24 additions and 21 deletions

View file

@ -1,4 +1,4 @@
use gtk::{glib::GString, prelude::WidgetExt, Notebook};
use gtk::{glib::GString, prelude::WidgetExt, Box, Notebook};
pub struct Widget {
gobject: Notebook,
@ -13,6 +13,27 @@ impl Widget {
}
// Actions
pub fn append(
&self,
label: &Box,
page: &Box,
is_current_page: bool,
is_reorderable: bool,
) -> u32 {
// Append new Notebook page
let page_number = self.gobject.append_page(page, Some(label));
// Additional setup for Notebook tab created
self.gobject.set_tab_reorderable(page, is_reorderable);
if is_current_page {
self.gobject.set_current_page(Some(page_number));
}
// Result
page_number
}
pub fn close(&self) {
self.gobject.remove_page(self.gobject().current_page());
}