natiny_window_set_state

C
void natiny_window_set_state(NatinyWindow id, int state);

Requests one of four exclusive window states: normal, minimized, maximized or fullscreen.

Parameters

Name Type Description
id NatinyWindow Window handle from natiny_window_create
state int One of the constants below

States

Constant Value Desktop Web Android
NATINY_WINDOW_STATE_NORMAL 0 Restores the window from minimized, maximized or fullscreen Leaves fullscreen Shows the status bar
NATINY_WINDOW_STATE_MINIMIZED 1 Minimizes the window No effect No effect
NATINY_WINDOW_STATE_MAXIMIZED 2 Maximizes the window No effect No effect
NATINY_WINDOW_STATE_FULLSCREEN 3 Borderless fullscreen on the monitor the window is mostly on Fullscreen API Hides the status bar

The requested state replaces the current state. For example, requesting NATINY_WINDOW_STATE_MAXIMIZED for a fullscreen window leaves fullscreen before maximizing the window.

Example

C
if (natiny_input_get_key_pressed(NATINY_INPUT_KEY_F11)) {
    int state = natiny_window_get_state(win);
    natiny_window_set_state(win,
        state == NATINY_WINDOW_STATE_FULLSCREEN ? NATINY_WINDOW_STATE_NORMAL
                                                : NATINY_WINDOW_STATE_FULLSCREEN);
}

Notes

  • The request is processed by the event loop. A call to natiny_window_get_state immediately afterward can still return the previous state.
  • Web and Android builds support only NATINY_WINDOW_STATE_NORMAL and NATINY_WINDOW_STATE_FULLSCREEN. Other states have no effect.
  • On Android, fullscreen hides the status bar but does not hide the navigation bar.
  • In a browser fullscreen is granted only from inside a user gesture, so the request can be refused. Use natiny_window_get_state to check whether it was granted.
  • Entering fullscreen records the window's position and size so that NATINY_WINDOW_STATE_NORMAL has somewhere to return to. A window made fullscreen by something other than this call returns to half the monitor's work area, centered.
  • A value other than the four constants is rejected with a message on stderr and leaves the current state unchanged.
  • Fullscreen can resize the window, so natiny_window_get_width and natiny_window_get_height change with it, from the frame after the switch.