Game window
micro::window represents the application's primary display surface. Ownership
is shared — copying a window shares the underlying handle, and the window is
closed only when the last owner is destroyed.
Construction
window(std::string_view title, int w, int h);
Creates and displays a window. Throws micro::error if the window could not be created.
micro::window win{"My Game", 640, 480};
Properties
std::string title() const;
int width() const;
int height() const;
Main loop
[[nodiscard]] bool running();
[[nodiscard]] float dtime() const noexcept;
[[nodiscard]] float fps() const noexcept;
void close() noexcept;
running() polls pending events and returns true while the window is open.
close() signals a stop; the current frame completes before the loop exits.
dtime() returns the time in seconds since the last frame (delta time).
fps() returns the current frames per second based on a sliding window average
of recent frame times (up to 60 samples). This provides a smoothed measurement
that's less susceptible to single-frame spikes.
while (win.running()) {
pos += vel * win.dtime();
rend.clear(micro::color::black);
rend.present();
}
Fullscreen
void set_fullscreen(bool enable);
[[nodiscard]] bool fullscreen() const noexcept;
Toggles borderless fullscreen using the desktop's current video mode.
!!! note "Web (Emscripten)"
set_fullscreen(true) must be called from within a user-gesture handler
(mouse click, key press). The browser silently ignores requests made outside one.
Cursor visibility
void show_cursor(bool visible);
[[nodiscard]] bool cursor_visible() const noexcept;
Input devices
void attach(const std::shared_ptr<input_device>& dev);
Attaches an input device to the window. The window holds a weak reference; the device is automatically unregistered when its last owner is destroyed. See Keyboard, Mouse, and Custom device.