mirror of
https://github.com/italicsjenga/muda.git
synced 2024-12-23 12:01:31 +11:00
feat(linux): document requirements and return gtk::Box
This commit is contained in:
parent
c8dcb40d56
commit
6cb2ce1c7a
12
src/lib.rs
12
src/lib.rs
|
@ -106,9 +106,17 @@ impl Menu {
|
|||
Submenu(self.0.add_submenu(label, enabled))
|
||||
}
|
||||
|
||||
/// Adds this menu to a [`gtk::Window`].
|
||||
/// Adds this menu to a [`gtk::Window`]
|
||||
///
|
||||
/// This method adds a [`gtk::Box`] then adds a [`gtk::MenuBar`] as its first child and returns the [`gtk::Box`].
|
||||
/// So if more widgets need to be added, then [`gtk::prelude::BoxExt::pack_start`] or
|
||||
/// similiar methods should be used on the returned [`gtk::Box`].
|
||||
///
|
||||
/// ## Safety:
|
||||
///
|
||||
/// This should be called before anything is added to the window.
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn init_for_gtk_window<W>(&self, w: &W)
|
||||
pub fn init_for_gtk_window<W>(&self, w: &W) -> std::rc::Rc<gtk::Box>
|
||||
where
|
||||
W: gtk::prelude::IsA<gtk::Container>,
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use crate::util::Counter;
|
||||
use gtk::{prelude::*, Orientation};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
static COUNTER: Counter = Counter::new();
|
||||
|
||||
|
@ -33,7 +33,7 @@ struct InnerMenu {
|
|||
// multiple times, and thus can't be used in multiple windows, entry
|
||||
// keeps a vector of a tuple of `gtk::MenuBar` and `gtk::Box`
|
||||
// and push to it every time `Menu::init_for_gtk_window` is called.
|
||||
gtk_items: Vec<(gtk::MenuBar, gtk::Box)>,
|
||||
gtk_items: Vec<(gtk::MenuBar, Rc<gtk::Box>)>,
|
||||
}
|
||||
|
||||
pub struct Menu(Arc<Mutex<InnerMenu>>);
|
||||
|
@ -61,7 +61,7 @@ impl Menu {
|
|||
Submenu(entry)
|
||||
}
|
||||
|
||||
pub fn init_for_gtk_window<W>(&self, w: &W)
|
||||
pub fn init_for_gtk_window<W>(&self, w: &W) -> Rc<gtk::Box>
|
||||
where
|
||||
W: IsA<gtk::Container>,
|
||||
{
|
||||
|
@ -73,7 +73,12 @@ impl Menu {
|
|||
w.add(&vbox);
|
||||
vbox.show_all();
|
||||
|
||||
let vbox = Rc::new(vbox);
|
||||
let vbox_c = Rc::clone(&vbox);
|
||||
|
||||
self.0.lock().gtk_items.push((menu_bar, vbox));
|
||||
|
||||
vbox_c
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![allow(unused)]
|
||||
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
pub struct Counter(AtomicU64);
|
||||
|
@ -11,7 +13,6 @@ impl Counter {
|
|||
self.0.fetch_add(1, Ordering::Relaxed)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn current(&self) -> u64 {
|
||||
self.0.load(Ordering::Relaxed)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue