Module: ui.backend.macos

Source: ./ui/backend/macos.reef


Overview

ui/backend/macos.reef - macOS native window backend using Cocoa Part of reef-stdlib UI module

This module provides native macOS window creation and event handling using the Cocoa framework via Objective-C runtime calls. It's useful for:

  • Native macOS desktop applications
  • Games with simple window needs
  • Cross-platform applications (alongside X11 and Windows backends)

This backend uses C helpers that bridge to Objective-C/Cocoa for window management. The implementation uses NSWindow, NSView, and CGContext.


Types

MacError (enum)

Variants:

  • None
  • InitFailed
  • WindowCreationFailed
  • NotOnMainThread
  • InvalidOperation
  • OutOfMemory

MacWindowConfig

Fields:

Name Type
title string
x int
y int
width int
height int
resizable bool
closable bool
miniaturizable bool
fullscreen_button bool
titled bool
borderless bool

MacApp

Fields:

Name Type
app_handle pointer
is_initialized bool

MacWindow

Fields:

Name Type
app MacApp
window_handle pointer
view_handle pointer
context_handle pointer
width int
height int
x int
y int
content_scale float
is_visible bool
is_open bool

MacEventType (enum)

Variants:

  • None
  • KeyDown
  • KeyUp
  • MouseDown
  • MouseUp
  • MouseMoved
  • MouseDragged
  • ScrollWheel
  • WindowResized
  • WindowMoved
  • WindowClosed
  • WindowFocused
  • WindowUnfocused
  • AppTerminate

MacEvent

Fields:

Name Type
event_type MacEventType
window_id int
x int
y int
dx float
dy float
button int
keycode int
modifiers int

MacAppResult (enum)

Variants:

  • Ok(MacApp)
  • Err(MacError)

MacWindowResult (enum)

Variants:

  • Ok(MacWindow)
  • Err(MacError)

Functions

fn reef_mac_init(): pointer

Application lifecycle

fn reef_mac_terminate(app: pointer): int

fn reef_mac_poll_events(app: pointer): int

fn reef_mac_should_terminate(app: pointer): int

fn reef_mac_screen_width(): int

Screen info

fn reef_mac_screen_height(): int

fn reef_mac_screen_scale(): float

fn reef_mac_create_window(app: pointer, x: int, y: int, w: int, h: int, style_mask: int): pointer

Window operations

fn reef_mac_destroy_window(win: pointer): int

fn reef_mac_show_window(win: pointer): int

fn reef_mac_hide_window(win: pointer): int

fn reef_mac_focus_window(win: pointer): int

fn reef_mac_move_window(win: pointer, x: int, y: int): int

fn reef_mac_resize_window(win: pointer, w: int, h: int): int

fn reef_mac_set_title(win: pointer, title: string): int

fn reef_mac_set_fullscreen(win: pointer, fullscreen: int): int

fn reef_mac_minimize_window(win: pointer): int

fn reef_mac_maximize_window(win: pointer): int

fn reef_mac_window_is_focused(win: pointer): int

fn reef_mac_window_content_scale(win: pointer): float

fn reef_mac_begin_draw(win: pointer): pointer

Drawing operations

fn reef_mac_end_draw(win: pointer, ctx: pointer): int

fn reef_mac_clear(ctx: pointer, r: float, g: float, b: float, a: float): int

fn reef_mac_fill_rect(ctx: pointer, x: float, y: float, w: float, h: float, r: float, g: float, b: float, a: float): int

fn reef_mac_stroke_rect(ctx: pointer, x: float, y: float, w: float, h: float, r: float, g: float, b: float, a: float): int

fn reef_mac_draw_line(ctx: pointer, x1: float, y1: float, x2: float, y2: float, r: float, g: float, b: float, a: float): int

fn reef_mac_draw_text(ctx: pointer, x: float, y: float, text: string, r: float, g: float, b: float, a: float): int

Text rendering

fn reef_mac_poll_event(app: pointer, event_out: pointer): int

Event handling

fn mac_init(): MacAppResult

fn mac_should_terminate(app: MacApp): bool

fn mac_window_config_default(): MacWindowConfig

fn mac_window_config(title: string, width: int, height: int): MacWindowConfig

fn mac_create_window(app: MacApp, config: MacWindowConfig): MacWindowResult

fn mac_window_width(win: MacWindow): int

fn mac_window_height(win: MacWindow): int

fn mac_window_x(win: MacWindow): int

fn mac_window_y(win: MacWindow): int

fn mac_window_is_visible(win: MacWindow): bool

fn mac_window_is_open(win: MacWindow): bool

fn mac_window_is_focused(win: MacWindow): bool

fn mac_window_content_scale(win: MacWindow): float

fn mac_screen_width(app: MacApp): int

fn mac_screen_height(app: MacApp): int

fn mac_screen_scale(app: MacApp): float

fn mac_poll_event(app: MacApp): MacEvent

fn empty_event(): MacEvent

fn mac_event_type(ev: MacEvent): MacEventType

fn mac_event_window(ev: MacEvent): int

fn mac_event_x(ev: MacEvent): int

fn mac_event_y(ev: MacEvent): int

fn mac_event_button(ev: MacEvent): int

fn mac_event_keycode(ev: MacEvent): int

fn mac_event_modifiers(ev: MacEvent): int

fn is_app_ok(r: MacAppResult): bool

fn is_app_err(r: MacAppResult): bool

fn unwrap_app(r: MacAppResult): MacApp

fn empty_app(): MacApp

fn app_error(r: MacAppResult): MacError

fn is_window_ok(r: MacWindowResult): bool

fn is_window_err(r: MacWindowResult): bool

fn unwrap_window(r: MacWindowResult): MacWindow

fn empty_window(): MacWindow

fn window_error(r: MacWindowResult): MacError


Procedures

proc mac_terminate(app: MacApp)

proc mac_poll_events(app: MacApp)

proc mac_destroy_window(win: MacWindow)

proc mac_show_window(win: MacWindow)

proc mac_hide_window(win: MacWindow)

proc mac_focus_window(win: MacWindow)

proc mac_move_window(win: MacWindow, x: int, y: int)

proc mac_resize_window(win: MacWindow, width: int, height: int)

proc mac_set_title(win: MacWindow, title: string)

proc mac_set_fullscreen(win: MacWindow, fullscreen: bool)

proc mac_minimize_window(win: MacWindow)

proc mac_maximize_window(win: MacWindow)

proc mac_begin_draw(win: MacWindow)

proc mac_end_draw(win: MacWindow)

proc mac_clear(win: MacWindow, color: core.Color)

proc mac_fill_rect(win: MacWindow, x: int, y: int, w: int, h: int, color: core.Color)

proc mac_stroke_rect(win: MacWindow, x: int, y: int, w: int, h: int, color: core.Color)

proc mac_draw_line(win: MacWindow, x1: int, y1: int, x2: int, y2: int, color: core.Color)

proc mac_blit_image(win: MacWindow, img: image.Image, x: int, y: int)

proc mac_draw_text(win: MacWindow, x: int, y: int, text: string, color: core.Color)


Generated by reefc doc