slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 601 forks source link

Fullscreen mode howto #2775

Closed frehberg closed 1 year ago

frehberg commented 1 year ago

Please document how to start an application on Linux in fullscreen mode, for example on a RasPi in kiosk mode. Or how can I define on command line the geometry of the main window?

It is possible to set in .slint file a static windows size, and disable the frame around the window. For example the following will be fullscreen on 800x600 screen But it would not be full screen on bigger screen.


export component AppWindow inherits Window {
    preferred-width: 800px;
    preferred-height: 600px;
    no-frame: true;

    in-out property<int> counter: 42;
    callback request-increase-value();
    VerticalBox {
        Text {
            text: "Counter: \{root.counter}";
        }
        Button {
            text: "Increase value";
            clicked => {
                root.request-increase-value();
            }
        }
    }
}
tronical commented 1 year ago

Thanks for the report. I agree, this needs to be documented. The solution that you can use is to set the SLINT_FULLSCREEN environment variable to the value 1 - then the window will be shown truly fullscreen.

We should also add show_fullscreen() API to slint::Window IMO.

frehberg commented 1 year ago

I tried, but the slint rust template does not show up in full screen, maybe additional properties are required to declare Window as "expand"?

SLINT_FULLSCREEN=1 ./target/debug/slint-test

EDIT: I am using Ubuntu 22.04.2 LTS with wayland Running this sample code https://github.com/slint-ui/slint-rust-template

tronical commented 1 year ago

Argh, there's a bug - this regressed :-(. I'll look into it right away, that should be easy to fix.

tronical commented 1 year ago

@frehberg I landed #2776 . I tried against Weston and wayland. It worked for me in the 1.0.2 release, but it was broken in the master branch. Which version were you using?

frehberg commented 1 year ago

Hi, I used the slint-rust-template, defining depencency to "1.0" https://github.com/slint-ui/slint-rust-template/blob/main/Cargo.toml

AFAICS, checking the cargo-build-env, the Cargo.lock did pin to version 1.0.2 , see the screenshot attached

[[package]]
name = "i-slint-backend-winit"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d2d4c3bbf2c9f255b715ad38f84e0296638b22338cce8349b954baf85bf674f"
dependencies = [
 "cfg-if",
 "cfg_aliases",
 "cocoa",
 "const-field-offset",
 "copypasta",
 "derive_more",
 "glutin",
 "glutin-winit",
 "i-slint-common",
 "i-slint-core",
 "i-slint-core-macros",
 "i-slint-renderer-femtovg",
 "i-slint-renderer-skia",
frehberg commented 1 year ago

image

tronical commented 1 year ago

Yep, ok! Then you need to switch to Slint git until we release a new version:

[dependencies]
slint = { version = "1.0", git = "https://github.com/slint-ui/slint", branch = "master" }

[build-dependencies]
slint-build = { version = "1.0", git = "https://github.com/slint-ui/slint", branch = "master" }
JanDiederich commented 1 year ago

When will we get the show_fullscreen() function?

hunger commented 1 year ago

@JanDiederich: I opened #3283 to track the API... that is a bit out of scope in an issue about documentation and I do not want to forget about it.

hunger commented 1 year ago

@tronical: Do we need to add documentation on how to use fullscreen mode still or can we close this report with the fix you did to winit's fullscreen support?

3283 tracks the API you mentioned as missing now.

tronical commented 1 year ago

In my opinion it makes sense to document the SLINT_FULLSCREEN environment variable. But we could also choose to say that it's internal (not public), then this could be closed.

JanDiederich commented 1 year ago

My current workaround is:

if options.is_fullscreen {
    std::env::set_var("SLINT_FULLSCREEN", "1");
}

let window = MainWindow::new().unwrap();

But this is no real solution, since I can't let the user decide to switch to fullscreen at will, after the program started, the application always has to re-start. This is especially annoying when you know that enough frameworks have this exact call built in, like: https://doc.qt.io/qt-6/qwindow.html#showFullScreen.

Edit: Quick google found this for Winit: https://github.com/rust-windowing/winit/blob/master/examples/fullscreen.rs window.set_fullscreen(fullscreen);

So it seems that both, most important window backends, Qt and Winit, have a native built in live go-to-fullscreen capability.

tronical commented 1 year ago

The SLINT_FULLSCREEN variable is now documented for the [winit backend](https://slint.dev/releases/1.2.0/docs/slint/src/advanced/backend_winit] and the Qt backend.

tronical commented 1 year ago

As mentioned in https://github.com/slint-ui/slint/issues/2775#issuecomment-1680342020 the new API is tracked separately and this is documented now.