Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FAQ] Center on screen #463

Open
XakepSDK opened this issue Nov 6, 2021 · 1 comment
Open

[FAQ] Center on screen #463

XakepSDK opened this issue Nov 6, 2021 · 1 comment
Labels
FAQ Common project related questions and answers

Comments

@XakepSDK
Copy link

XakepSDK commented Nov 6, 2021

Window spawns in top left corner. I want my window be centered on screen. How do i make it spawn centered on screen?

I thought about manually centering window, but i haven't found a way to get screen resolution. Also i heard that wayland does not let you know your screen resolution.

@kivimango
Copy link
Contributor

The problem is getting the screen size in a cross-platform way.
If the target platform is not webASM then you could use
orbclient::get_display_size()
in one of your widget's state init method(), ask the entity of the window with

let window = ctx.window();
// get the window position property, maybe not like this, i cant recall exactly now
let window_x = ctx.widget(window).get("position").clone().x();
let window_x = ctx.widget(window).get("position").clone().y();

then

match orbclient::get_display_size() {
            Ok(screen_size) => {
                self.x = (screen_size.0 - window_width) / 2;
                self.y = (screen_size.1 - window_height) / 2;
                /// set window's positon property values of x and y
            }
            Err(msg) => {
                eprintln!("Cannot determine screen size: {}", msg);
            }

(I just implemented centering on my own lib, i will try port it to back orbtk when i have some time)
https://github.com/kivimango/mygui/blob/main/src/widget/window.rs#L68

@rzerres rzerres added the FAQ Common project related questions and answers label Jan 31, 2022
@rzerres rzerres changed the title Center on screen [FAQ] Center on screen Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FAQ Common project related questions and answers
Projects
None yet
Development

No branches or pull requests

3 participants