首页 > 解决方案 > 如何更改 Piston2D / PistonWindow / GlutinWindow 中的光标图标?

问题描述

像正常、忙碌或文本选择。我想创建一个桌面 Windows 应用程序,我需要更改它的图标。

标签: rustwindowmouse-cursorrust-piston

解决方案


Piston 本身并不直接提供更改光标图标的功能。但是,在某些情况下,活塞会暴露底层窗口,这确实提供了该功能。

例如你提到GlutinWindow的,我假设它glutin_window::GlutinWindow来自pistoncore-glutin_window板条箱glutin::window::Window它通过访问字段间接提供对底层的访问ctx

底层证券glutin::window::Window确实有一个set_cursor_icon()你可以指定的地方CursorIcon

use glutin_window::GlutinWindow;
use glutin::window::CursorIcon;

let wnd: GlutinWindow = ...;

wnd.ctx.window().set_cursor_icon(CursorIcon::Default);
wnd.ctx.window().set_cursor_icon(CursorIcon::Wait);
wnd.ctx.window().set_cursor_icon(CursorIcon::Text);

推荐阅读