ui::WindowOptions¶
Header: winui/ui/WindowOptions.hpp.
What a Window is created with: title, size, theme, frame, placement and the per-window services. A Window owns one, given to its constructor. title, theme, backdrop and icon take a value or a property: bound to a property, the window follows it for as long as both live, so one ui::Property<ui::ThemeRequest> can drive every window of an app. style, chrome, system_menu and the size limits seed the Window's own live properties (set_style(), ...), which is where to change them afterwards; the rest is read once, when the OS window is created by ui::run() or Window::show().
A bound field subscribes to its properties while the Window is constructed. A Window that is a class member therefore has to be declared after the properties it binds, since members are constructed in declaration order; bound to a member declared later, it reads an object that does not exist yet.
Example:
int main()
{
ui::Property<ui::ThemeRequest> theme{{.mode = ui::ThemeMode::Dark}};
ui::Window window{{
.title = "My Application",
.size = {1024, 768},
.theme = theme, // every window bound to `theme` switches with it
.backdrop = ui::Backdrop::Mica,
.min_size = {480, 320},
}};
window.set_content(ui::Text{.text = "Hello"});
return ui::run(window);
}
| Field | Type | Default | |
|---|---|---|---|
title |
Binding<std::string> |
The caption and taskbar text, UTF-8; Window::title(). Bound, the window follows it. | |
size |
Size |
{800.0f, 600.0f} |
The client area's size in DIPs, the room the content gets, whatever frame the theme draws around it; scaled by DPI at creation. |
theme |
Binding<ThemeRequest> |
What to resolve the live Theme from; Window::set_theme(). Defaults to ThemeMode::System, which follows the OS light/dark, accent and high-contrast settings as they change. Bound, the window follows it (a pin_theme() in between is undone by the next change). A designated list needs its type here: .theme = ui::ThemeRequest{.mode = ...}. |
|
backdrop |
Binding<Backdrop> |
{Backdrop::None} |
Opt-in system backdrop material (ui::Backdrop); Window::set_backdrop(). Bound, the window follows it. |
style |
WindowStyle |
The frame (ui::WindowStyle). The defaults give a plain resizable window with a caption, a system menu and minimize and maximize buttons. Seeds Window::set_style(); change it live through the Window afterwards. | |
spell_check |
SpellCheckOptions |
See SpellCheckOptions above. |
|
initial_state |
WindowState |
WindowState::Normal |
The state to show in. Normal honors the launcher, so a shortcut set to "Run: Maximized" or "Minimized" still gets its way. |
position |
std::optional<Point> |
Top-left of the window, in DIPs of the primary monitor. Absent lets the system cascade it. | |
min_size |
Size |
Smallest client size the user can drag the window to, in DIPs; zero on an axis leaves it unconstrained. Not applied while full screen. | |
max_size |
Size |
Largest client size, in DIPs; zero on an axis leaves it unconstrained. | |
placement |
std::optional<WindowPlacement> |
A placement saved from Window::placement() on a previous run. Overrides initial_state and position. The system pulls it back on screen if its monitor is gone. |
|
chrome |
ChromeOverrides |
Seeds Window::set_chrome(): this window's own frame colors and corners over the theme's. | |
icon |
Binding<std::optional<WindowIcon>> |
The caption and taskbar icon; Window::set_icon(). Absent uses the executable's first icon resource, the one the file manager shows for the file, or the system's default without one. ui::WindowIcon{.resource = "#101"} picks another of the executable's icons. Bound, the window follows it. |
|
system_menu |
std::vector<MenuItem> |
Seeds Window::set_system_menu() when non-empty. | |
taskbar_progress |
Binding<TaskbarProgress> |
The progress the taskbar button shows; Window::taskbar_progress(), which also sets it after construction. Bound, the button follows it, such as a job's progress while it runs. A Window class member binds only properties declared before it (see WindowOptions). Example: cpp ui::Property<double> done{0.0}; // the export's progress, 0 to 1 ui::Window window{{ .title = "Export", .taskbar_progress = ui::bind(done, [](double f) { const auto state = f < 1.0 ? ui::TaskbarProgressState::Normal : ui::TaskbarProgressState::None; return ui::TaskbarProgress{state, f}; }), }}; |
|
owner |
Window* |
nullptr |
The window this one belongs to: an owned window stays above its owner, minimizes and closes with it, and has no taskbar button of its own. nullptr: none. |
modal |
bool |
false |
With an owner: the owner takes no input while this window is open, and gets the activation back when it closes. Ignored without one. |
visible |
bool |
true |
false creates the window hidden, laid out and ready for Window::show(). position and size still apply; initial_state and placement do not, as both would show it. |
close_hides |
bool |
false |
Closing hides the window instead of destroying it, by the close button, Alt+F4 and Window::close() alike, after on_closing() has had its say. For a window the app shows again, like a tray flyout; ui::quit() still takes it down with the loop. |