繁体   English   中英

如何使用 fltk-rs 提升 window

[英]How to raise a window using fltk-rs

我正在尝试“提升”(在其他重叠的 windows 的“顶部”绘制并可能“激活”)特定的 window 以响应事件。 FLTK 官方文档似乎说Fl_Window::show()方法是执行此操作的方法。 但是,在fltk-rs中没有对应WindowExt::show() (或任何类似的)方法。

有一个WidgetExt::show()方法,但它在调用时不会引发 window。 还有一个同样有希望但同样令人失望DoubleWindow::platform_show()方法。

要做的是调用 .hide( .hide() ,然后立即在有问题的 window 上调用.show() 这产生了将有问题的 window 提升到桩顶的预期效果。 然而,这

  • 看起来很hacky,对吧? 就像绕过一个人的后部到达一个人的肘部。
  • 确实隐藏然后显示window。 On my Debian system running i3, this is almost unnoticeable (the flicker might just be standard window-redrawing), but under Windows this is terrible, because .hide .hide() ing the window triggers a short (but oh-so-noticeable) fade -out animation (和.show()将其对应的淡入 animation,另外甚至可能还会发生一些收缩/增长操作),这是糟糕的用户体验,看起来有些故障。

这是一个例子:


use fltk::{
    prelude::*,
    app::App,
    enums::Color,
    frame::Frame,
    window::DoubleWindow,
    button::Button,
};

fn main() {
    let a = App::default();
    
    let mut sub_win = DoubleWindow::default()
        .with_size(128, 128)
        .with_pos(64, 64);
    sub_win.set_border(false);
    sub_win.set_color(Color::Magenta); // So you can see it clearly.
    let _ = Frame::default().with_label("Sub Window")
        .with_size(128, 128)
        .with_pos(0, 0);
    sub_win.end();
    sub_win.show();
    
    let mut main_win = DoubleWindow::default().with_label("Main Window")
        .with_size(256, 128)
        .with_pos(0, 0);
    let mut b0 = Button::default().with_label("won't work")
        .with_size(96, 64)
        .with_pos(20, 32);
    let mut b1 = Button::default().with_label("is hacky")
        .with_size(96, 64)
        .with_pos(130, 32);
    main_win.end();
    main_win.show();
    
    b0.set_callback({
        let mut sub_win = sub_win.clone();
        move |_| {
            sub_win.show();          // The FLTK docs suggest this should work.
            sub_win.platform_show(); // This also disappoints.
        }
    });

    b1.set_callback(move |_| {
        sub_win.hide();          // This combination is what
        sub_win.show();          // actually works.
    });
    
    a.run().unwrap();
}

如果有人知道我寻求的魔法咒语,我将不胜感激。

On the C++ end, Fl_Widget::show() is a virtual function that should raise the window, if the variable points to a top-level window (a window with no parent). 在 Rust 方面,我看到这些行:

extern "C" {
    pub fn Fl_Window_show(arg1: *mut Fl_Window);
}

这似乎表明存在调用 Fl_Window::show() 的直接接口,对于 Fl_Double_Window 也是如此。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM