Documentation ¶
Overview ¶
Package nksdl provides integration between Nuklear and SDL2 via the github.com/kbolino/go-nk and github.com/veandco/go-sdl2 modules.
Index ¶
- Variables
- type ConvertOpts
- type DefaultNkDriver
- func (d *DefaultNkDriver) CreateContext() (*nk.Context, error)
- func (d *DefaultNkDriver) CreateConvertConfig(vertexLayout []nk.DrawVertexLayoutElement, vertexSize, vertexAlignment uint32, ...) *nk.ConvertConfig
- func (d *DefaultNkDriver) CreateFont(atlas *nk.FontAtlas, scale float32) (*nk.Font, error)
- func (d *DefaultNkDriver) CreateFontAtlas() (*nk.FontAtlas, error)
- type DefaultSDLDriver
- type Driver
- func (d *Driver) BGColor() sdl.Color
- func (d *Driver) Context() *nk.Context
- func (d *Driver) Destroy() (err error)
- func (d *Driver) FrameEnd() (err error)
- func (d *Driver) FrameStart() error
- func (d *Driver) Init() error
- func (d *Driver) RenderScale() float32
- func (d *Driver) Renderer() *sdl.Renderer
- func (d *Driver) SetBGColor(color sdl.Color)
- func (d *Driver) SetRenderScale(renderScale float32) error
- func (d *Driver) Window() *sdl.Window
- type EventHandler
- type EventListener
- type EventType
- type FontOpts
- type KeyAction
- type KeyInput
- type NkDriver
- type RenderOpts
- type SDLDriver
- type WindowOpts
Constants ¶
This section is empty.
Variables ¶
var DefaultBindings = map[KeyInput]KeyAction{ {Code: sdl.K_LSHIFT}: {Key1: nk.KeyShift}, {Code: sdl.K_RSHIFT}: {Key1: nk.KeyShift}, {Code: sdl.K_RETURN}: {Key1: nk.KeyEnter}, {Code: sdl.K_TAB}: {Key1: nk.KeyTab}, {Code: sdl.K_BACKSPACE}: {Key1: nk.KeyBackspace}, {Code: sdl.K_HOME}: {Key1: nk.KeyTextStart, Key2: nk.KeyScrollStart}, {Code: sdl.K_END}: {Key1: nk.KeyTextEnd, Key2: nk.KeyScrollEnd}, {Code: sdl.K_PAGEUP}: {Key1: nk.KeyScrollUp}, {Code: sdl.K_PAGEDOWN}: {Key2: nk.KeyScrollDown}, {Code: sdl.K_UP}: {Key1: nk.KeyUp}, {Code: sdl.K_DOWN}: {Key1: nk.KeyDown}, {Code: sdl.K_LEFT}: {Key1: nk.KeyLeft}, {Code: sdl.K_RIGHT}: {Key1: nk.KeyRight}, {Code: sdl.K_c, Mod: sdl.KMOD_CTRL}: {Key1: nk.KeyCopy}, {Code: sdl.K_x, Mod: sdl.KMOD_CTRL}: {Key1: nk.KeyCut}, {Code: sdl.K_v, Mod: sdl.KMOD_CTRL}: {Key1: nk.KeyPaste}, {Code: sdl.K_a, Mod: sdl.KMOD_CTRL}: {Key1: nk.KeyTextLineStart}, {Code: sdl.K_e, Mod: sdl.KMOD_CTRL}: {Key1: nk.KeyTextLineEnd}, {Code: sdl.K_z, Mod: sdl.KMOD_CTRL}: {Key1: nk.KeyTextUndo}, {Code: sdl.K_z, Mod: sdl.KMOD_CTRL | sdl.KMOD_SHIFT}: {Key1: nk.KeyTextRedo}, }
var ErrQuit = errQuit{}
ErrQuit is an error sentinel value used to indicate that the application should quit.
Functions ¶
This section is empty.
Types ¶
type ConvertOpts ¶
type ConvertOpts struct { GlobalAlpha float32 LineAA, ShapeAA nk.AntiAliasing CircleSegmentCount uint32 CurveSegmentCount uint32 ArcSegmentCount uint32 }
ConvertOpts contains options used by DefaultNkContext.CreateConvertConfig.
type DefaultNkDriver ¶
type DefaultNkDriver struct { // Font contains options for creating fonts. Font FontOpts // Convert contains options for creating vertex buffer conversion // configurations. Convert ConvertOpts }
DefaultNkDriver is the default implementation of NkDriver. It can be used directly as an NkDriver or extended to patch/override its behavior.
func (*DefaultNkDriver) CreateContext ¶
func (d *DefaultNkDriver) CreateContext() (*nk.Context, error)
func (*DefaultNkDriver) CreateConvertConfig ¶
func (d *DefaultNkDriver) CreateConvertConfig( vertexLayout []nk.DrawVertexLayoutElement, vertexSize, vertexAlignment uint32, null nk.DrawNullTexture, ) *nk.ConvertConfig
func (*DefaultNkDriver) CreateFont ¶
func (d *DefaultNkDriver) CreateFont(atlas *nk.FontAtlas, scale float32) (*nk.Font, error)
func (*DefaultNkDriver) CreateFontAtlas ¶
func (d *DefaultNkDriver) CreateFontAtlas() (*nk.FontAtlas, error)
type DefaultSDLDriver ¶
type DefaultSDLDriver struct { // InitFlags contains flags to pass to sdl.Init. InitFlags uint32 // Hints contains hint keys and values to pass to sdl.SetHint. Hints map[string]string // Window contains options for creating the window. Window WindowOpts // Render contains options for creating the renderer. Render RenderOpts }
DefaultSDLDriver is the default implementation of SDLDriver. It can be used directly as an SDLDriver, or extended to patch/override its behavior.
func (*DefaultSDLDriver) CreateRenderer ¶
func (*DefaultSDLDriver) CreateWindow ¶
func (d *DefaultSDLDriver) CreateWindow() (*sdl.Window, error)
func (*DefaultSDLDriver) InitSDL ¶
func (d *DefaultSDLDriver) InitSDL() error
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is the main focus of NkSDL. It is used to manage SDL resources and Nuklear resources through initial setup, per-frame rendering, and pre-quit teardown. Driver delegates SDL-related setup to SDLDriver and Nuklear-related setup to NkDriver.
func NewDriver ¶
func NewDriver( sdlDriver SDLDriver, nkDriver NkDriver, bindings map[KeyInput]KeyAction, eventListener EventListener, ) *Driver
NewDriver creates a new Driver from the given parameters. The sdlDriver and nkDriver must not be nil, or else NewDriver will panic. The bindings map is used to map keys to Nuklear actions. The eventListener is optional, but if non-nil will be called for every SDL event after it is handled by Nuklear.
func (*Driver) Destroy ¶
Destroy fress resources used by the Driver. Destroy should be called once in the lifetime of a Driver, after the last call to FrameEnd.
func (*Driver) FrameEnd ¶ added in v0.2.0
FrameEnd performs late frame actions, including converting UI draw commands to vertex buffer draw commands, passing the vertex buffers to the renderer, and presenting the renderer. FrameEnd should be called once at the end of every frame.
func (*Driver) FrameStart ¶ added in v0.2.0
FrameStart performs early frame actions, including polling for events, mapping input events to actions, as well as scaling and clearing the renderer. FrameStart should be called once at the beginning of every frame.
func (*Driver) Init ¶
Init initializes the Driver, creating the SDL window and renderer as well as the Nuklear context and fonts. Init should be called once in the lifetime of a Driver, before any calls to FrameStart.
func (*Driver) RenderScale ¶ added in v0.3.0
func (*Driver) SetBGColor ¶
SetBGColor sets the desired background color when clearing the renderer.
func (*Driver) SetRenderScale ¶ added in v0.3.0
SetRenderScale sets the desired rendering scale. To compute the scale automatically (e.g. on a high-DPI display), use a renderScale of 0.
type EventHandler ¶
type EventHandler struct {
// contains filtered or unexported fields
}
EventHandler is used to handle input events from SDL and report them to an nk.Context.
func NewEventHandler ¶
func NewEventHandler(bindings map[KeyInput]KeyAction) EventHandler
NewEventHandler creates a new EventHandler from the given bindings. The map will be copied, and any generic modifier key bindings will be expanded into left and right key bindings. For example, if there is a binding with Ctrl modifier set it will be expanded into separate bindings to the same action for both LCtrl and RCtrl instead. NewEventHandler panics if the resulting bindings conflict.
func (EventHandler) HandleEvent ¶
func (h EventHandler) HandleEvent(nkc *nk.Context, event sdl.Event) (EventType, bool)
HandleEvent handles the given event, reporting its actions to nkc, using the defined bindings. The return value indicates the type of the event and whether the event was used at all.
type EventListener ¶
EventListener is the function signature for the optional event listener, which is called after Nuklear handles an event. See the EventHandler type for a description of the other parameters.
type EventType ¶
type EventType int32
EventType represents the type of a handled event. This is not an exhaustive list of event types, and only represents those that are recognized by EventHandler, with a placeholder (EventTypeUnhandled) for all other types.
type KeyAction ¶
type KeyAction struct { Key1 nk.Key Key2 nk.Key }
KeyAction represents the action(s) to be taken when key input is received. Key2 is optional; if only a single action is needed, leave Key2 unset or set it to KeyNone.
type KeyInput ¶
KeyInput is the reduced form of sdl.Keysym containing only the keycode and modifiers, used to match input events.
type NkDriver ¶
type NkDriver interface { CreateContext() (*nk.Context, error) CreateFontAtlas() (*nk.FontAtlas, error) CreateFont(atlas *nk.FontAtlas, scale float32) (*nk.Font, error) CreateConvertConfig( vertexLayout []nk.DrawVertexLayoutElement, vertexSize, vertexAlignment uint32, null nk.DrawNullTexture, ) *nk.ConvertConfig }
NkDriver is implemented by any type capable of initializing Nuklear and its core resources.
type RenderOpts ¶
RenderOpts sets options for DefaultSDLDriver.CreateRenderer.