How can I get the screen resolution
cjrsacred opened this issue · comments
I want to create a window which could adjust the size according to the screen resolution, how can i do it ?
Getting the screen resolution is not a behavior of either the Window
or AdvancedWindow
traits, so if you want to get it, you'll have to look to the underlying window implementation.
I usually use PistonWindow
from the piston_window
crate, which by default uses glutin_window::GlutinWindow
(from pistoncore-glutin_window) which contains a context which contains a winit::Window
which has methods to get monitor information.
So, if you have a PistonWindow
, you can get the size of the monitor which the window is currently in with:
let monitor_dimensions = piston_window
.window
.ctx
.window()
.get_current_monitor()
.get_dimensions();
It's kind of a shame that you can't learn this information from the online docs for these crates. Because of the way rustdoc works, links to the types you need to know more about are not available; they are simply black, unclickable text.
However, if you generate the docs yourself using cargo doc --open
, the links you need will be present, and you can follow PistonWindow
all the way down to find all its inner workings.
Thank you, you helped me a lot