![](/img/trans.png)
[英]Depending on Build Target, use fltk::osxMenuBar or MenuBar in fltk-rs
[英]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 提升到桩顶的预期效果。 然而,这
.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.