natiny.window.set_state

Lua
natiny.window.set_state(win, state)

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

Parameters

Name Type Description
win number Window handle from natiny.window.create
state number One of the constants below

States

Constant Desktop Web Android
natiny.window.STATE_NORMAL Restores the window from minimized, maximized or fullscreen Leaves fullscreen Shows the status bar
natiny.window.STATE_MINIMIZED Minimizes the window No effect No effect
natiny.window.STATE_MAXIMIZED Maximizes the window No effect No effect
natiny.window.STATE_FULLSCREEN 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

Lua
if natiny.input.get_key_pressed(natiny.input.KEY_F11) then
    if natiny.window.get_state(win) == natiny.window.STATE_FULLSCREEN then
        natiny.window.set_state(win, natiny.window.STATE_NORMAL)
    else
        natiny.window.set_state(win, natiny.window.STATE_FULLSCREEN)
    end
end

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 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 diagnostic message 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.