Teek API Documentation

An SDL2-accelerated rendering surface embedded in a Tk frame.

Viewport creates a Tk frame, obtains its native window handle via the Tk C API, then embeds an SDL2 renderer inside it using SDL_CreateWindowFrom. All drawing goes through SDL2 with GPU acceleration — no Tk involvement in the rendering path.

Keyboard input is tracked automatically via Tk bindings so you can poll key state with #key_down? in a game loop.

Inherits: Object

Instance Methods

bind(event, *subs, &block)

Bind a Tk event on the viewport frame.

Automatically chains with internal behavior (key tracking, click-to-focus) so user callbacks don’t clobber #key_down?.

Parameters
  • event String — Tk event name (e.g. 'KeyPress', 'ButtonPress-1')
  • subs Array<Symbol, String> — Tk substitution codes

Returns void

@yield called when the event fires

destroy

Destroy the viewport, its SDL2 renderer, and the Tk frame.

Returns void

destroyed?

Returns Boolean — whether this viewport has been destroyed

focus

Give this viewport keyboard focus so it receives key events.

Returns void

grid(**kwargs)

Grid the viewport into its parent using Tk’s grid geometry manager.

Parameters
  • kwargs — options passed to the Tk grid command

Returns self

initialize(app, parent: nil, width: 640, height: 480, vsync: true)

Parameters
  • app Teek::App — the Teek application
  • parent Teek::Widget, String, nil — parent widget (nil for root)
  • width Integer — initial width in pixels
  • height Integer — initial height in pixels
  • vsync Boolean — enable VSync (default: true). Disable for applications that manage their own frame pacing (e.g. emulators).

Returns Viewport — a new instance of Viewport

inspect

key_down?(keysym)

Check if a key is currently held down. Uses Tk keysym names (lowercase).

Parameters
  • keysym String, Symbol — Tk keysym name (e.g. 'left', 'space', 'a')

Returns Boolean

Example
viewport.key_down?('left')   # arrow key
viewport.key_down?('space')  # spacebar
viewport.key_down?('a')      # letter key

pack(**kwargs)

Pack the viewport into its parent using Tk’s pack geometry manager.

Parameters
  • kwargs — options passed to the Tk pack command

Returns self

render(&block)

Draw with the renderer in a block, auto-presenting at the end.

Returns self

@raise Teek::SDL2::Error if the viewport has been destroyed

@yield renderer the SDL2 renderer for this viewport

@yieldparam renderer Teek::SDL2::Renderer

Example
viewport.render do |r|
  r.clear(0, 0, 0)
  r.fill_rect(10, 10, 100, 50, 255, 0, 0)
end
Attributes

app [R]

Returns Teek::App — the Teek application

frame [R]

Returns Teek::Widget — the underlying Tk frame

keys_down [R]

Returns Set<String> — currently held key names (lowercase keysyms)

renderer [R]

Returns Teek::SDL2::Renderer — the SDL2 renderer