锈。 GTK3。在 `gtk::Window` 中找不到 get_screen() 方法

Rust. GTK3. get_screen() method not found in `gtk::Window`

我想使用“add_provider_for_screen”方法为我的 window 使用 css。

pub fn add_provider_for_screen(screen: &gdk::Screen, provider: &impl IsA<StyleProvider>, priority: u32) 

为此,我需要使用 get_screen() 方法将 window 转换为 GdkScreen。但是,当我尝试这样做时,出现错误: method not found in &gtk::Windowhttps://docs.gtk.org/gtk3/method.Window.get_screen.html

main.rs代码:

use std::process::exit;
use gdk_pixbuf::Pixbuf;
use gtk::{Window, Image, Orientation, WindowType, CssProvider};
use gtk::prelude::{GtkWindowExt, WidgetExt, ContainerExt, ButtonExt, CssProviderExt};

fn main() {
    gtk::init().unwrap();
    init_window();
    gtk::main();
}
fn init_css(win: &gtk::Window) {
    let css = CssProvider::new();
    css.load_from_path("main.css").unwrap();
    let screen = win.gtk_window_get_screen().unwrap();
    gtk::StyleContext::add_provider_for_screen(screen, &css, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
}

fn init_window() {
    let window = gtk::Window::new(WindowType::Toplevel);
    init_css(&window);
// ....
}

此外,如果我尝试在 fn init_window() 中创建 GdkScreen,我会收到类似的错误:method not found in gtk::Window

let screen = window.gtk_screen().unwrap();

Cargo.toml内容:

[dependencies]
gtk="0.15.5"
gdk="0.15.4"
gdk-pixbuf="0.15.11"

来自 Widgnet 的文档,使用方法 WidgetExt::screen:

Get the gdk::Screen from the toplevel window associated with this widget. This function can only be called after the widget has been added to a widget hierarchy with a Window at the top.