mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-29 20:44:25 +00:00
implement separated append method for tab widget
This commit is contained in:
parent
b705fc224d
commit
227cfb30a1
@ -83,11 +83,7 @@ impl Tab {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(
|
pub fn append(&self, page_navigation_request_text: Option<GString>, is_current_page: bool) {
|
||||||
&self,
|
|
||||||
page_navigation_request_text: Option<GString>,
|
|
||||||
is_current_page: bool,
|
|
||||||
) -> u32 {
|
|
||||||
// Generate unique ID for new page components
|
// Generate unique ID for new page components
|
||||||
let id = uuid_string_random();
|
let id = uuid_string_random();
|
||||||
|
|
||||||
@ -128,26 +124,12 @@ impl Tab {
|
|||||||
label.gobject().add_controller(controller);
|
label.gobject().add_controller(controller);
|
||||||
|
|
||||||
// Append new Notebook page
|
// Append new Notebook page
|
||||||
let page_number = self
|
|
||||||
.widget
|
|
||||||
.gobject()
|
|
||||||
.append_page(page.widget(), Some(label.gobject()));
|
|
||||||
|
|
||||||
// Additional setup for Notebook tab created
|
|
||||||
self.widget
|
self.widget
|
||||||
.gobject()
|
.append(label.gobject(), page.widget(), is_current_page, true);
|
||||||
.set_tab_reorderable(page.widget(), true);
|
|
||||||
|
|
||||||
if is_current_page {
|
|
||||||
self.widget.gobject().set_current_page(Some(page_number));
|
|
||||||
}
|
|
||||||
|
|
||||||
if page_navigation_request_text.is_none() {
|
if page_navigation_request_text.is_none() {
|
||||||
page.navigation_request_grab_focus();
|
page.navigation_request_grab_focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result
|
|
||||||
page_number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close active tab
|
// Close active tab
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use gtk::{glib::GString, prelude::WidgetExt, Notebook};
|
use gtk::{glib::GString, prelude::WidgetExt, Box, Notebook};
|
||||||
|
|
||||||
pub struct Widget {
|
pub struct Widget {
|
||||||
gobject: Notebook,
|
gobject: Notebook,
|
||||||
@ -13,6 +13,27 @@ impl Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// 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) {
|
pub fn close(&self) {
|
||||||
self.gobject.remove_page(self.gobject().current_page());
|
self.gobject.remove_page(self.gobject().current_page());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user