Window
A window is the core component of an application. It is the object where all events from child controls are processed.
Window styles, backgrounds, and flags
The Type changes a window’s frame, while Background communicates the meaning of its content. Initialization flags control interactions such as resizing and closing.
These screenshots show focused windows rendered by the window guide example with the default theme. The example installs the built-in AppCUI palette (.palette(Palette::BuiltIn)) so the named colors match the theme. An inactive window uses the theme’s inactive background instead.
Frame styles
| Type | Screenshot |
|---|---|
Type::ClassicDouble-line frame while focused; single-line when inactive or moving. | ![]() |
Type::RoundedSingle-line frame with rounded corners. | ![]() |
Type::PanelTitle bar with no surrounding frame. The title is centered. | ![]() |
Type::BorderlessNo frame and no inner margin. The title is left-aligned. The tag, when set, is on the right. | ![]() |
Backgrounds
The colors below are the default theme’s; other themes can choose different colors.
| Background | Screenshot |
|---|---|
Background::NormalDark blue ( #000080); the default. | ![]() |
Background::ErrorDark red ( #800000) for failures. | ![]() |
Background::WarningOlive ( #808000) for cautions. | ![]() |
Background::NotificationDark green ( #008000) for information. | ![]() |
Initialization flags
| Flags | Screenshot |
|---|---|
Flags::NoneMovable, fixed size, with a close button. | ![]() |
Flags::SizeableAdds the maximize/restore button and the resize grip. | ![]() |
Flags::NoCloseButtonHides the close button. | ![]() |
Flags::NoTitleHides the title text. The frame, buttons, tag, and hotkey stay. | ![]() |
Flags::FixedPosition prevents moving the window and adds no separate visual indicator. Flags can be combined with |; for example, Flags::Sizeable | Flags::NoCloseButton permits resizing while hiding the close button. Flags::NoTitle only hides the title text: a Classic or Rounded frame is still drawn, and the close button, tag, and hotkey remain.
Run the example from the repository root to try each option:
cargo run --example window_guide -- classic
cargo run --example window_guide -- notification
cargo run --example window_guide -- sizeable
The other choices are rounded, panel, borderless, error, warning, no-close, no-title, and fixed-position.
For example, a resizable error dialog can combine Flags::Sizeable with Background::Error:
#![allow(unused)]
fn main() {
let window = Window::with_type(
"Import failed",
layout!("a:c,w:40,h:10"),
window::Flags::Sizeable,
window::Type::Rounded,
window::Background::Error,
);
}
To create a Window use:
Window::newmethod (with 3 parameters: a title, a layout and initialization flags)Window::with_typemethod (with 5 parameters: a title, a layout, initialization flags, a type and a background)- macro
window!.
let w = Window::new("Title", layout!("x:10,y:5,w:15,h:9"),window::Flags::None);
let w2 = window!("Title,a:c,w:10,h:10");
let w3 = window!("title='Some Title',a:c,w:30,h:10,flags=[Sizeable])");
let w4 = window!("title='WithTag',a:c,w:30,h:10,tag:MyTag)");
let w5 = window!("Title,a:c,w:10,h:10,key:Alt+F10");
let w6 = window!("Title,a:c,w:10,h:10,key:auto");
Keep in mind that window will NOT handle any events from its children.
A window supports all common parameters (as they are described in Instantiate via Macros section). Besides them, the following named parameters are also accepted:
| Parameter name | Type | Positional parameter | Purpose |
|---|---|---|---|
title or text or caption | String | Yes (first positional parameter) | The title (text) of the window |
flags | String or List | No | Window initialization flags |
type | String | No | Window type (visual) |
bg or back or background | String | No | The background of the window. |
tag | String | No | The tag of the window |
hotkey or hot-key or key | Key | No | The hotkey associated with a window. You can also use the auto value to ask the framework to find the first available key (from Alt+1 to Alt+9) |
To create a window that will handle events from its children, use the #[Window(...)] attribute:
#[Window(events=..., )]
struct MyWindow {
// specific fields
}
The attribute rewrites that struct in three ways:
- it inserts a field
base: Windowas the first field (every constructor initializesbase) - it implements
DerefandDerefMut, soWindowmethods such asaddandset_titleare called onbase - it implements every event trait with an empty body, except the traits named in
events. Those are left for you to write.
For example, #[Window(events = ButtonEvents)] struct MyWin { x: i32 } becomes a struct with base: Window and x: i32, plus Deref / DerefMut, plus an empty impl CheckBoxEvents for MyWin, an empty impl RadioBoxEvents for MyWin, and an empty impl for every other event trait. impl ButtonEvents for MyWin is not generated.
The expansion, the compiler errors that follow from it (missing field 'base', conflicting trait implementations, Control not implemented), and the same code written without the attribute are described in What the #[Window] attribute does.
A window supports the following initialization flags:
window::Flags::None- regular window (with a close button)window::Flags::SizeableorSizeable(for window! macro) - a window that has the resize grip and the maximize buttonwindow::Flags::NoCloseButtonorNoCloseButton(for window! macro) - a window without a close buttonwindow::Flags::FixedPositionorFixedPosition(for window! macro) - a window that can not be movedwindow::Flags::NoTitleorNoTitle(for window! macro) - hides the title text. The frame (when the type has one), the close button, the tag, and the hotkey stay visible
the following types:
window::Type::ClassicorClassic(for window! macro) - a regular window with a classic look (double border). The title is centeredwindow::Type::RoundedorRounded(for window! macro) - a window with rounded corners. The title is centeredwindow::Type::PanelorPanel(for window! macro) - a window with a top bar and no borders. The title is centeredwindow::Type::BorderlessorBorderless(for window! macro) - a window with no frame and no inner margin. The title is left-aligned, and the tag is placed on the right
the following backgrounds:
window::Background::NormalorNormal(for window! macro) - a regular window (using the default background color)window::Background::ErrororError(for window! macro) - a window with a red background to indicate an error messagewindow::Background::NotificationorNotification(for window! macro) - a window with a different background designed for notification messageswindow::Background::WarningorWarning(for window! macro) - a window with a different background designed for Warning messages
Methods
Besides the Common methods for all Controls, a window also has the following additional methods:
| Method | Purpose |
|---|---|
add(...) | Adds a new control as a child of the current window |
control(...) | Returns an immutable reference to a control based on its handle |
control_mut(...) | Returns a mutable reference to a control based on its handle |
request_focus_for_control(...) | Requests the focus for a specific control, given a specific handle |
toolbar() | Returns a mutable reference to the current window’s toolbar |
set_title(...) | Sets the window title. Example: win.set_title("Title") — this sets the title of the window to Title. |
title() | Returns the title of the current window |
set_tag(...) | Sets the window tag. Example: win.set_tag("ABC") — this sets the tag of the window to ABC. |
tag() | Returns the tag of the current window |
clear_tag() | Clears the current tag. It is equivalent to set_tag(""). |
set_auto_hotkey() | Automatically selects a free hotkey (in the format Alt+{number} where {number} is between 1 and 9). |
enter_resize_mode() | Enters resize mode programmatically. |
close | Closes the current window. |
Key association
In terms of key association, a Window has two modes:
- Normal mode (for when a window has focus)
- Resize/Move mode (in this mode you can use arrows and various combinations to move the window)
For normal mode
| Key | Purpose |
|---|---|
Ctrl+Alt+M or Ctrl+Alt+R | Switch the window to resize/move mode |
Escape | Triggers a call to on_cancel(...) method. By default this will close the window. However you can change the behavior and return ActionRequest::Deny from the on_cancel callback |
Up or Alt+Up or Ctrl+Up | Moves to the closest control on the upper side of the current one. |
Down or Alt+Down or Ctrl+Down | Moves to the closest control on the bottom side of the current one |
Left or Alt+Left or Ctrl+Left | Moves to the closest control on the left side of the current one |
Right or Alt+Right or Ctrl+Right | Moves to the closest control on the right side of the current one |
OBS: Keep in mind that if any of these keys (in particular Left, Right, Up and Down) are captured by one of the children of a window, they will not be processed by the window.
For resize/move mode
| Key | Purpose |
|---|---|
Escape or Enter or Tab or Space | Switch back to the normal mode |
Left, Up, Right, Down | Arrow keys can be used to move the window |
C | Centers the current window to the Desktop |
M or R | Maximizes or Restores the size of the current window |
Alt+{Left, Up, Right, Down} | Moves the window towards one of the margins of the Desktop. For example Alt+Up will move current window to the top margin of the client space of the Desktop |
Ctrl+{Left, Up, Right, Down} | Increases or decreases the Width or Height of the current Window |
Events
Window related events can be intercepted via WindowEvents trait. You will need to add WindowEvents in the list of events like in the following example:
#![allow(unused)]
fn main() {
#[Window(events=WindowEvents)]
struct MyWindow { ... }
impl WindowEvents for MyWindow { ... }
}
WindowEvents is defined in the following way:
#![allow(unused)]
fn main() {
pub trait WindowEvents {
fn on_close(&mut self) -> EventProcessStatus {
EventProcessStatus::Ignored
}
fn on_layout_changed(&mut self, old_layout: Rect, new_layout: Rect) {}
fn on_activate(&mut self) {}
fn on_deactivate(&mut self) {}
fn on_accept(&mut self) {}
fn on_cancel(&mut self) -> ActionRequest {
ActionRequest::Allow
}
}
}
These methods are called under the following scenarios:
| Method | Called when |
|---|---|
on_layout_changed(...) | Called whenever the size or position of a window changes. |
on_activate(...) | Called whenever a window or a modal window receives the focus |
on_deactivate(...) | Called whenever a window or a modal window loses the focus |
on_accept(...) | Called only for modal windows when you hit the Enter key |
on_cancel(...) | For a modal window this method is called when you press Escape. You can use this method to disable closing via Escape key and for an exit with a value (via method exit_with(...)For a regular window (non-modal) this method can be called when you pressed Esc key or when you pressed the close button from a window. |
Window Tags
For every window, a tag can be set for a window (a tag is a string associated with a Window that reflects its purpose). To set a tag use .set_tag("<name") method.
For example, the following code:
fn main() -> Result<(), appcui::system::Error> {
App::new()
.window(|| {
let mut win = window!("Title,a:c,w:40,h:9");
win.set_tag("TAG");
win
})
.run()
}
should generate a window that looks like the following:

On a Classic, Rounded, or Panel window the tag is drawn on the left side of the title bar, as in the picture above. On a Borderless window the tag is drawn on the right.
Window Hot Key
You can also associate a hot key to a window. A hot key allows you to quickly switch between windows. In the next example, we set up Alt+7 as a hot key for a window.
fn main() -> Result<(), appcui::system::Error> {
App::new()
.window(|| {
let mut win = window!("Title,a:c,w:40,h:9");
win.set_hotkey(key!("Alt+7"));
win
})
.run()
}
should generate a window that looks like the following:










