Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ nakefile
test/main
*.exe
build/
.debug
.vscode
17 changes: 17 additions & 0 deletions doc/context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Context
=======

WindowView
----------

Interfaces with window and graphics backend.

Each view has a graphics context.

TODO: The context may be unique or shared between windows depending on backend.

A view may need app data and backend data to properly initialize itself.

Some backends (js) do not currently support sharing between opengl contexts.


6 changes: 6 additions & 0 deletions editor/nakefile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ preprocessResources = proc(b: Builder) =
let sf = f.splitFile()
if sf.ext == ".nimx":
b.copyResourceAsIs(f.replace("res/", ""))

task "debug", "Build for debugging":
let b = newBuilder()
b.additionalNimFlags.add "--debugger:on"
b.runAfterBuild = false
b.build()
16 changes: 2 additions & 14 deletions editor/nimxedit.nim
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import tables

import nimx/matrixes
import nimx/system_logger
import nimx/animation
import nimx/image
import nimx/window
import nimx/autotest
import nimx/button, nimx/text_field
import nimx/all_views
import nimx/editor/edit_view

const isMobile = defined(ios) or defined(android)
import nimx

proc runAutoTestsIfNeeded() =
uiTest generalUITest:
Expand All @@ -22,7 +10,7 @@ proc runAutoTestsIfNeeded() =
startRegisteredTests()

proc startApplication() =
when isMobile:
when mobile:
var mainWindow = newFullscreenWindow()
else:
var mainWindow = newWindow(newRect(40, 40, 1200, 600))
Expand Down
1 change: 1 addition & 0 deletions kiwi
Submodule kiwi added at 64d1c6
6 changes: 6 additions & 0 deletions nakefile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ task "docs", "Build documentation":
direShell "nim rst2html " & f & " &>/dev/null"

copyDir "../js", "./livedemo"

task "debug", "Build for debugging":
let b = newBuilder()
b.additionalNimFlags.add "--debugger:on"
b.runAfterBuild = false
b.build()
1 change: 1 addition & 0 deletions nim_emscripten_tutorial
Submodule nim_emscripten_tutorial added at 0640d4
1 change: 1 addition & 0 deletions nimsl
Submodule nimsl added at 491120
31 changes: 31 additions & 0 deletions nimx.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import nimx / [
backends,
window,
autotest,
]

# Views
import nimx / [
button,
text_field,
image_view,
slider,
segmented_control,
collection_view,
editor/edit_view,
]

export
# core
backends,
window,
autotest,

# views
button,
text_field,
image_view,
slider,
segmented_control,
collection_view,
edit_view
2 changes: 1 addition & 1 deletion nimx.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.1"
version = "0.2"
author = "Yuriy Glukhov"
description = "GUI framework"
license = "MIT"
Expand Down
25 changes: 13 additions & 12 deletions nimx/abstract_window.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ method drawWindow*(w: Window) {.base.} =
w.needsDisplay = false

w.recursiveDrawSubviews()
let c = currentContext()
template c: untyped = w.gfx

let profiler = sharedProfiler()
if profiler.enabled:
updateFps()
profiler["Overdraw"] = GetOverdrawValue()
profiler["DIPs"] = GetDIPValue()
profiler["Overdraw"] = getOverdrawValue(w.gfx)
profiler["DIPs"] = getDIPValue(w.gfx)
profiler["Animations"] = totalAnims

const fontSize = 14
const profilerWidth = 110
var font = systemFont()
var font = systemFont(c.fontCtx)
let old_size = font.size
font.size = fontSize
`size=`(font, c.fontCtx, fontSize)
var rect = newRect(w.frame.width - profilerWidth, 5, profilerWidth - 5, Coord(profiler.len) * font.height)
c.fillColor = newGrayColor(1, 0.8)
c.strokeWidth = 0
Expand All @@ -108,9 +108,9 @@ method drawWindow*(w: Window) {.base.} =
pt.x = w.frame.width - profilerWidth
c.drawText(font, pt, k & ": " & v)
pt.y = pt.y + fontSize
font.size = old_size
ResetOverdrawValue()
ResetDIPValue()
`size=`(font, c.fontCtx, old_size)
resetOverdrawValue(c)
resetDIPValue(c)

let dc = currentDragSystem()
if not dc.pItem.isNil:
Expand All @@ -125,8 +125,7 @@ method drawWindow*(w: Window) {.base.} =
c.drawRect(rect)

method draw*(w: Window, rect: Rect) =
let c = currentContext()
let gl = c.gl
template gl: untyped = w.gfx.gl
if w.mActiveBgColor != w.backgroundColor:
gl.clearColor(w.backgroundColor.r, w.backgroundColor.g, w.backgroundColor.b, w.backgroundColor.a)
w.mActiveBgColor = w.backgroundColor
Expand Down Expand Up @@ -203,12 +202,14 @@ proc onFocusChange*(w: Window, inFocus: bool)=
sharedNotificationCenter().postNotification(AW_FOCUS_LEAVE)

var newWindow*: proc(r: Rect): Window
var newWindowWithGfxContext*: proc(gfx: GraphicsContext, r: Rect): Window
var newFullscreenWindow*: proc(): Window
var newFullscreenWindowWithGfxContext*: proc(gfx: GraphicsContext): Window
var newWindowWithNative*: proc(handle: pointer, r: Rect): Window
var newFullscreenWindowWithNative*: proc(handle: pointer): Window

method init*(w: Window, frame: Rect) =
procCall w.View.init(frame)
method init*(w: Window, gfx: GraphicsContext, frame: Rect) =
procCall w.View.init(gfx, frame)
w.window = w
w.needsDisplay = true
w.mCurrentTouches = newTable[int, View]()
Expand Down
4 changes: 1 addition & 3 deletions nimx/autotest.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import macros, logging, strutils
import nimx / [ timer, app, event, abstract_window, button ]
import nimx / [ backends, timer, app, event, window, button ]

type UITestSuiteStep* = tuple
code : proc()
Expand All @@ -10,8 +10,6 @@ type UITestSuite* = ref object
name: string
steps: seq[UITestSuiteStep]

const web = defined(js) or defined(emscripten) or defined(wasm)

when web:
when defined(emscripten) or defined(wasm):
import jsbind/emscripten
Expand Down
70 changes: 70 additions & 0 deletions nimx/backends.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
type OsApi* {.pure.} = enum
web
android
ios
macosx
linux
windows

type WindowApi* {.pure.} = enum
web
sdl
x11
appkit
winapi

type InputApi* {.pure.} = enum
web
sdl
x11
appkit
winapi

type GraphicApi* {.pure.} = enum
opengles2

type AudioApi* {.pure.} = enum
web
sdl
appkit
winapi
alsa

type Backend* = tuple
os: OsApi
win: WindowApi
input: InputApi
gfx: GraphicApi
audio: AudioApi

const backend*: Backend =
when defined js:
(OsApi.web, WindowApi.web, InputApi.web, GraphicApi.opengles2, AudioApi.web)
elif defined emscripten:
(OsApi.web, WindowApi.web, InputApi.web, GraphicApi.opengles2, AudioApi.web)
elif defined wasm:
(OsApi.web, WindowApi.web, InputApi.web, GraphicApi.opengles2, AudioApi.web)
elif defined ios:
(OsApi.ios, WindowApi.sdl, InputApi.sdl, GraphicApi.opengles2, AudioApi.sdl)
elif defined android:
(OsApi.android, WindowApi.sdl, InputApi.sdl, GraphicApi.opengles2, AudioApi.sdl)
elif defined macosx:
when defined nimxAvoidSDL:
(OsApi.macosx, WindowApi.appkit, InputApi.appkit, GraphicApi.opengles2, AudioApi.appkit)
else:
(OsApi.macosx, WindowApi.sdl, InputApi.sdl, GraphicApi.opengles2, AudioApi.sdl)
elif defined linux:
when defined nimxAvoidSDL:
(OsApi.linux, WindowApi.xll, InputApi.xll, GraphicApi.opengles2, AudioApi.alsa)
else:
(OsApi.linux, WindowApi.sdl, InputApi.sdl, GraphicApi.opengles2, AudioApi.sdl)
elif defined windows:
when defined nimxAvoidSDL:
(OsApi.windows, WindowApi.winapi, InputApi.winapi, GraphicApi.opengles2, AudioApi.winapi)
else:
(OsApi.windows, WindowApi.sdl, InputApi.sdl, GraphicApi.opengles2, AudioApi.sdl)
else: {.error: "unknown backend".}

const web* = backend.os == OsApi.web
const mobile* = defined(ios) or defined(android)
const desktop* = not web and not mobile
Loading