How to set position of main window of imgui-rs examples?

Would someone please help me with this tiny little nit?

Lately, almost no matter what crate I try to use there seems to usually be some silly little show-stopper like simply setting the position of a window.

I'm using the imgui-rs crate at

The main window setting takes place in
I've looked at the docs to no avail.

Here is the code that creates the main window, and I can't use it to position the window with WindowBuilder::new() :

use glium::glutin;
use glium::glutin::event::{Event, WindowEvent};
use glium::glutin::event_loop::{ControlFlow, EventLoop};
use glium::glutin::window::WindowBuilder;
use glium::{Display, Surface};
use imgui::{Context, FontConfig, FontGlyphRanges, FontSource, Ui};
use imgui_glium_renderer::Renderer;
use imgui_winit_support::{HiDpiMode, WinitPlatform};
use std::time::Instant;

mod clipboard;

pub struct System {
    pub event_loop: EventLoop<()>,
    pub display: glium::Display,
    pub imgui: Context,
    pub platform: WinitPlatform,
    pub renderer: Renderer,
    pub font_size: f32,

pub fn init(title: &str) -> System {
    let title = match title.rfind('/') {
        Some(idx) => title.split_at(idx + 1).1,
        None => title,
    let event_loop = EventLoop::new();
    let context = glutin::ContextBuilder::new().with_vsync(true);
    // let mon = winit::MonitorId::get_name();
    let builder = WindowBuilder::new()
        // .window
        // .set_position(glutin::dpi::LogicalPosition::new(50f64, 50f64)) //  FAIL
        .with_inner_size(glutin::dpi::LogicalSize::new(1024f64, 768f64)); // 1024f64, 768f64
... ...

i managed to set the window position like so:

in, use window.set_outer_position in this part that is a few lines under the lines that you posted:

let mut platform = WinitPlatform::init(&mut imgui);
        let gl_window = display.gl_window();
        let window = gl_window.window();
        window.set_outer_position(winit::dpi::PhysicalPosition{x: 123, y: 456}); // this is the new line
        platform.attach_window(imgui.io_mut(), &window, HiDpiMode::Rounded);

Also, add a direct dependency to Cargo.toml in order to access the winit::dpi::PhysicalPosition type, which does not seem to be exposed by imgui-winit-support:

winit = "*"

(tested on linux/x11)


Thank you mmmmib! This was extremely educational!
I added the winit = "*" to the Cargo.toml, and then placed
use winit::dpi::PhysicalPosition; in, but I get

error[E0433]: failed to resolve: use of undeclared type or module `winit`
  --> examples/support/
10 | use winit::dpi::PhysicalPosition;
   |     ^^^^^ use of undeclared type or module `winit`

What else must I do?

  • you don't need the use statement, the code i posted uses the complete path of winit::dpi::PhysicalPosition. The use statement would only be necessary if you wanted to write PhysicalPosition without the namespace before it.
  • be sure to add the winit = "*" at the bottom of the [dev-dependecies] section imgui-examples/Cargo.toml, not the one in the repo's main directory
  • add the line window.set_outer_position(winit::dpi::PhysicalPosition{x: 123, y: 456}); in imgui-examples/examples/ (see above for exact location)
  • inside the imgui-examples directory, run cargo run --example hello_world

@mmmmib Thank you again for your lucid instructions!

You are a great programmer!

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.