diff --git a/examples/config.nims b/examples/config.nims index 28cc8e2a..e36139c2 100644 --- a/examples/config.nims +++ b/examples/config.nims @@ -1 +1 @@ ---path:"../" \ No newline at end of file +--path:"../src" \ No newline at end of file diff --git a/examples/hnbrowser.nim b/examples/hnbrowser.nim index 0ba80c03..c73208d0 100644 --- a/examples/hnbrowser.nim +++ b/examples/hnbrowser.nim @@ -1,7 +1,6 @@ # Compile with nim c -d:ssl import figuro/widgets/[button] import figuro/widgets/[scrollpane, vertical, horizontal] -import figuro/widget import figuro import hnloader @@ -102,6 +101,7 @@ proc draw*(self: Main) {.slot.} = Button.new "story": with node: size 1'fr, 60'ux + fill blueColor.lighten(0.2) # connect(node, doHover, self, Main.hover) # echo "story: ", story.link.title Text.new "text": diff --git a/figuro.nimble b/figuro.nimble index 5c655210..2b144646 100644 --- a/figuro.nimble +++ b/figuro.nimble @@ -1,8 +1,8 @@ -version = "0.9.0" +version = "0.9.1" author = "Jaremy Creechley" description = "UI Engine for Nim" license = "MIT" -srcDir = "." +srcDir = "src" # Dependencies diff --git a/figuro/ui/commons.nim b/figuro/ui/commons.nim deleted file mode 100644 index 0e9c1a65..00000000 --- a/figuro/ui/commons.nim +++ /dev/null @@ -1,10 +0,0 @@ -import ../shared -import ../internal -import ../common/uimaths -import ../common/nodes/ui -import ../common/nodes/csstheme -# import sigils - -export shared, ui, internal, uimaths, csstheme - -type FiguroError* = object of CatchableError diff --git a/figuro/widget.nim b/figuro/widget.nim deleted file mode 100644 index 04a8657b..00000000 --- a/figuro/widget.nim +++ /dev/null @@ -1,9 +0,0 @@ -import common/nodes/ui -import sigils -import inputs -import ui/core -import ui/apis -import ui/utils - -export sigils -export apis, core, ui, inputs, utils diff --git a/figuro/widgets/commons.nim b/figuro/widgets/commons.nim deleted file mode 100644 index 863abff3..00000000 --- a/figuro/widgets/commons.nim +++ /dev/null @@ -1,5 +0,0 @@ -import ../../figuro -import ../widget - -export figuro -export widget diff --git a/figuro/widgets/experimental/buttonWrap.nim b/figuro/widgets/experimental/buttonWrap.nim deleted file mode 100644 index 25305cff..00000000 --- a/figuro/widgets/experimental/buttonWrap.nim +++ /dev/null @@ -1,39 +0,0 @@ -import commons -import ../ui/utils - -type Button*[T] = ref object of StatefulFiguro[T] - label*: string - isActive*: bool - disabled*: bool - -# proc hover*[T](self: Button[T], kind: EventKind) {.slot.} = -# echo "button:hovered: ", kind, " :: ", self.getId, -# " buttons: ", self.events.mouse - -proc clicked*[T](self: Button[T], kind: EventKind, buttons: UiButtonView) {.slot.} = - echo nd(), "button:clicked: ", buttons, " kind: ", kind, " :: ", self.getId - - if not self.isActive: - refresh(self) - self.isActive = true - -proc draw*[T](self: Button[T]) {.slot.} = - ## button widget! - var node = self - with node: - clipContent true - cornerRadius 10.0 - - if self.disabled: - fill node, css"#F0F0F0" - else: - fill node, css"#2B9FEA" - onHover: - echo "on hover" - fill node, node.fill.spin(15) - rectangle "btnBody": - bubble(doClick) - boxSizeOf node, node.parent[] - WidgetContents(self) - -exportWidget(button, Button) diff --git a/figuro/windows.nim b/figuro/windows.nim deleted file mode 100644 index 641b47e6..00000000 --- a/figuro/windows.nim +++ /dev/null @@ -1 +0,0 @@ -import common diff --git a/figuro.nim b/src/figuro.nim similarity index 61% rename from figuro.nim rename to src/figuro.nim index 22abe112..3d6d8788 100644 --- a/figuro.nim +++ b/src/figuro.nim @@ -1,19 +1,19 @@ -import figuro/shared +import figuro/commons import figuro/ui/apis import figuro/widget import sigils import chronicles export chronicles -export shared, apis, widget, sigils +export commons, apis, widget, sigils when defined(compilervm) or defined(nimscript): - import figuro/wrappers + import figuro/runtime/wrappers export wrappers else: - import figuro/execApps - export execApps + import figuro/runtime/runtimeNative + export runtimeNative when defined(macosx): {.passc: "-Wno-incompatible-function-pointer-types".} diff --git a/figuro/common/extras.nim b/src/figuro/common/extras.nim similarity index 100% rename from figuro/common/extras.nim rename to src/figuro/common/extras.nim diff --git a/figuro/renderer/opengl/fontutils.nim b/src/figuro/common/fontutils.nim similarity index 81% rename from figuro/renderer/opengl/fontutils.nim rename to src/figuro/common/fontutils.nim index b79bea6d..455eb6cd 100644 --- a/figuro/renderer/opengl/fontutils.nim +++ b/src/figuro/common/fontutils.nim @@ -1,4 +1,4 @@ -import std/[os, unicode, strutils, sets, hashes] +import std/[os, unicode, sequtils, tables, strutils, sets, hashes] import std/isolation import pkg/vmath @@ -7,7 +7,7 @@ import pkg/pixie/fonts import pkg/windy import pkg/threading/channels -import commons +import glyphs, extras, shared import pretty @@ -37,12 +37,8 @@ proc hash*(glyph: GlyphPosition): Hash {.inline.} = proc getId*(typeface: Typeface): TypefaceId = TypefaceId typeface.hash() -# proc getId*(font: Font): FontId = -# FontId font.hash() - iterator glyphs*(arrangement: GlyphArrangement): GlyphPosition = var idx = 0 - # if arrangement != nil: var mlh = 0.0 # maximum line height per row (though this does in total?) for f in arrangement.fonts: @@ -76,16 +72,16 @@ iterator glyphs*(arrangement: GlyphArrangement): GlyphPosition = break var - typefaceTable*: Table[TypefaceId, Typeface] + typefaceTable*: Table[TypefaceId, Typeface] ## holds the table of parsed fonts fontTable* {.threadvar.}: Table[FontId, Font] -proc generateGlyphImage*(arrangement: GlyphArrangement) = +proc generateGlyphImage(arrangement: GlyphArrangement) = ## returns Glyph's hash, will generate glyph if needed ## ## Font Glyphs are generated with Bottom vAlign and Center hAlign ## this puts the glyphs in the right position ## so that the renderer doesn't need to figure out adjustments - threads: + runtimeThreads: MainThread for glyph in arrangement.glyphs(): @@ -128,8 +124,31 @@ proc generateGlyphImage*(arrangement: GlyphArrangement) = except PixieError: discard -proc getTypeface*(name: string): FontId = - threads: +type + TypeFaceKinds* = enum + TTF + OTF + SVG + +proc readTypefaceImpl(name, data: string, kind: TypeFaceKinds): Typeface {.raises: [PixieError].} = + ## Loads a typeface from a buffer + try: + result = + case kind + of TTF: + parseTtf(data) + of OTF: + parseOtf(data) + of SVG: + parseSvgFont(data) + except IOError as e: + raise newException(PixieError, e.msg, e) + + result.filePath = name + +proc getTypefaceImpl*(name: string): FontId = + ## loads a font from a file and adds it to the font index + runtimeThreads: MainThread let @@ -139,19 +158,27 @@ proc getTypeface*(name: string): FontId = typefaceTable[id] = typeface result = id - # echo "typefaceTable:addr: ", getThreadId() - # echo "getTypeFace: ", result - # echo "getTypeFace:res: ", typefaceTable[id].hash() + +proc getTypefaceImpl*(name, data: string, kind: TypeFaceKinds): FontId = + ## loads a font from buffer and adds it to the font index + runtimeThreads: + MainThread + + let + typeface = readTypefaceImpl(name, data, kind) + id = typeface.getId() + + typefaceTable[id] = typeface + result = id proc convertFont*(font: UiFont): (FontId, Font) = - threads: + ## does the typesetting using pixie, then converts to Figuro's internal + ## types + runtimeThreads: MainThread - # echo "convertFont: ", font.typefaceId - # echo "typefaceTable:addr: ", getThreadId() let id = font.getId() typeface = typefaceTable[font.typefaceId] - # echo "convertFont:res: ", typeface.hash if not fontTable.hasKey(id): var pxfont = newFont(typeface) @@ -171,20 +198,21 @@ proc convertFont*(font: UiFont): (FontId, Font) = fontTable[id] = pxfont result = (id, pxfont) - # echo "getFont:input: " - # print font else: result = (id, fontTable[id]) import sugar -proc getTypeset*( +proc getTypesetImpl*( box: Box, uiSpans: openArray[(UiFont, string)], hAlign = FontHorizontal.Left, vAlign = FontVertical.Top, ): GlyphArrangement = - threads: + ## does the typesetting using pixie, then converts the typeseet results + ## into Figuro's own internal types + ## Primarily done for thread safety + runtimeThreads: MainThread var @@ -222,10 +250,6 @@ proc getTypeset*( let arrangement = pixie.typeset(spans, bounds = wh, hAlign = ha, vAlign = va) - # echo "getTypeset:" - # echo "getTypeset:wh: ", wh - # print arrangement - var lines = newSeqOfCap[Slice[int]](arrangement.lines.len()) spanSlices = newSeqOfCap[Slice[int]](arrangement.spans.len()) diff --git a/figuro/common/glyphs.nim b/src/figuro/common/glyphs.nim similarity index 100% rename from figuro/common/glyphs.nim rename to src/figuro/common/glyphs.nim diff --git a/figuro/inputs.nim b/src/figuro/common/inputs.nim similarity index 98% rename from figuro/inputs.nim rename to src/figuro/common/inputs.nim index a6b3ce2c..b7641f01 100644 --- a/figuro/inputs.nim +++ b/src/figuro/common/inputs.nim @@ -1,8 +1,8 @@ import std/[unicode, sequtils] import pkg/vmath -import common/nodes/basics -import common/uimaths +import nodes/basics +import uimaths export uimaths when defined(nimscript): diff --git a/figuro/ui/basiccss.nim b/src/figuro/common/nodes/basiccss.nim similarity index 99% rename from figuro/ui/basiccss.nim rename to src/figuro/common/nodes/basiccss.nim index 5558a09c..f7e7f4a1 100644 --- a/figuro/ui/basiccss.nim +++ b/src/figuro/common/nodes/basiccss.nim @@ -5,7 +5,7 @@ import cssgrid import stylus import patty import chroma -import ../common/nodes/basics +import basics import chronicles variantp CssValue: diff --git a/figuro/common/nodes/basics.nim b/src/figuro/common/nodes/basics.nim similarity index 100% rename from figuro/common/nodes/basics.nim rename to src/figuro/common/nodes/basics.nim diff --git a/figuro/common/nodes/render.nim b/src/figuro/common/nodes/render.nim similarity index 100% rename from figuro/common/nodes/render.nim rename to src/figuro/common/nodes/render.nim diff --git a/figuro/common/nodes/transfer.nim b/src/figuro/common/nodes/transfer.nim similarity index 99% rename from figuro/common/nodes/transfer.nim rename to src/figuro/common/nodes/transfer.nim index fb96381e..d50aa245 100644 --- a/figuro/common/nodes/transfer.nim +++ b/src/figuro/common/nodes/transfer.nim @@ -1,6 +1,6 @@ -import ui as ui +import uinodes as ui import render as render -import ../../shared +import ../shared type RenderList* = object diff --git a/figuro/common/nodes/ui.nim b/src/figuro/common/nodes/uinodes.nim similarity index 96% rename from figuro/common/nodes/ui.nim rename to src/figuro/common/nodes/uinodes.nim index 0fcae6b3..a541a73d 100644 --- a/figuro/common/nodes/ui.nim +++ b/src/figuro/common/nodes/uinodes.nim @@ -1,18 +1,18 @@ import std/unicode import std/monotimes import std/hashes +import pkg/stack_strings +import pkg/sigils/weakrefs +import pkg/sigils +import pkg/cssgrid + import basics -import sigils -import ../../inputs -import ../../ui/basiccss -import cssgrid -import stack_strings -import sigils/weakrefs - -export basics, inputs, cssgrid, stack_strings +import basiccss +import ../inputs + export unicode, monotimes -export weakrefs -export basiccss +export cssgrid, stack_strings, weakrefs +export basics, inputs, basiccss when defined(nimscript): {.pragma: runtimeVar, compileTime.} diff --git a/figuro/shared.nim b/src/figuro/common/shared.nim similarity index 86% rename from figuro/shared.nim rename to src/figuro/common/shared.nim index e38798ef..210bbede 100644 --- a/figuro/shared.nim +++ b/src/figuro/common/shared.nim @@ -1,18 +1,17 @@ import std/[sequtils, tables, hashes] import std/[options, unicode, strformat] import std/paths -import pkg/[variant] +import std/os +import pkg/variant +export paths, sequtils, strformat, tables, hashes +export variant -import common/[extras, uimaths] -import inputs +import extras, uimaths, inputs +export extras, uimaths, inputs -export sequtils, strformat, tables, hashes -export variant -export extras, uimaths -export inputs -export paths +import pkg/chroma -import chroma +type FiguroError* = object of CatchableError type MainThreadEff* = object of RootEffect ## MainThr effect @@ -25,7 +24,7 @@ proc MainThread*() {.tags: [MainThreadEff].} = proc RenderThread*() {.tags: [RenderThreadEff].} = discard -template threads*(arg: typed) = +template runtimeThreads*(arg: typed) = arg() {.pop.} @@ -42,7 +41,7 @@ const blueColor* = color(0, 0, 1, 1) const DataDirPath* {.strdefine.} = - Path(currentSourcePath()).splitPath().head /../ "data".Path + Path(currentSourcePath()).splitPath().head / Path(".." / ".." / ".." / "data") type ScaleInfo* = object x*: float32 diff --git a/figuro/internal.nim b/src/figuro/common/system.nim similarity index 59% rename from figuro/internal.nim rename to src/figuro/common/system.nim index c5da733c..590806b8 100644 --- a/figuro/internal.nim +++ b/src/figuro/common/system.nim @@ -1,5 +1,6 @@ -import std/locks -import common/glyphs + +import glyphs +export glyphs when defined(nimscript): {.pragma: runtimeVar, compileTime.} @@ -8,8 +9,6 @@ else: type MainCallback* = proc() {.closure.} -type UiEvent* = tuple[cond: Cond, lock: Lock] - when defined(nimscript): proc setWindowTitle*(title: string) = discard @@ -27,7 +26,8 @@ when defined(nimscript): discard else: - from renderer/opengl/fontutils import getTypeface, getTypeset + import fontutils + export TypeFaceKinds ## these are set at runtime by the opengl window proc setWindowTitle*(title: string) = @@ -38,25 +38,12 @@ else: proc getTypeface*(name: string): TypefaceId = ## loads typeface from pixie - fontutils.getTypeface(name) + getTypefaceImpl(name) + + proc getTypeface*(name, data: string, kind: TypeFaceKinds): TypefaceId = + getTypefaceImpl(name, data, kind) proc getTypeset*( box: Box, spans: openArray[(UiFont, string)], hAlign = Left, vAlign = Top ): GlyphArrangement = - fontutils.getTypeset(box, spans, hAlign, vAlign) - - var - uiAppEvent* {.runtimeVar.}: UiEvent - uiRenderEvent* {.runtimeVar.}: UiEvent - -proc initUiEvent*(): UiEvent = - result.lock.initLock() - result.cond.initCond() - -proc trigger*(evt: var UiEvent) = - withLock(evt.lock): - signal(evt.cond) - -proc wait*(evt: var UiEvent) = - withLock(evt.lock): - wait(evt.cond, evt.lock) + getTypesetImpl(box, spans, hAlign, vAlign) diff --git a/src/figuro/common/uievents.nim b/src/figuro/common/uievents.nim new file mode 100644 index 00000000..ca9819a9 --- /dev/null +++ b/src/figuro/common/uievents.nim @@ -0,0 +1,25 @@ +import std/locks + +type UiEvent* = tuple[cond: Cond, lock: Lock] + +when defined(nimscript): + {.pragma: runtimeVar, compileTime.} +else: + {.pragma: runtimeVar, global.} + + +var + uiAppEvent* {.runtimeVar.}: UiEvent + uiRenderEvent* {.runtimeVar.}: UiEvent + +proc initUiEvent*(): UiEvent = + result.lock.initLock() + result.cond.initCond() + +proc trigger*(evt: var UiEvent) = + withLock(evt.lock): + signal(evt.cond) + +proc wait*(evt: var UiEvent) = + withLock(evt.lock): + wait(evt.cond, evt.lock) \ No newline at end of file diff --git a/figuro/common/uimaths.nim b/src/figuro/common/uimaths.nim similarity index 100% rename from figuro/common/uimaths.nim rename to src/figuro/common/uimaths.nim diff --git a/src/figuro/commons.nim b/src/figuro/commons.nim new file mode 100644 index 00000000..7570109b --- /dev/null +++ b/src/figuro/commons.nim @@ -0,0 +1,10 @@ +import common/shared +import common/system +import common/uimaths +import common/nodes/uinodes +import common/nodes/basiccss +import pkg/sigils + +export shared, uinodes, uimaths, basiccss +export system +export sigils diff --git a/figuro/renderer/blank.nim b/src/figuro/renderer/blank.nim similarity index 100% rename from figuro/renderer/blank.nim rename to src/figuro/renderer/blank.nim diff --git a/figuro/renderer/opengl.nim b/src/figuro/renderer/opengl.nim similarity index 98% rename from figuro/renderer/opengl.nim rename to src/figuro/renderer/opengl.nim index 48ae9ce6..9b948741 100644 --- a/figuro/renderer/opengl.nim +++ b/src/figuro/renderer/opengl.nim @@ -5,8 +5,8 @@ import pkg/pixie import pkg/windy import pkg/sigils/weakrefs -import ../shared -import ../inputs +import ../commons +# import ../inputs import ./opengl/utils import ./opengl/window import ./opengl/renderer diff --git a/figuro/renderer/opengl/buffers.nim b/src/figuro/renderer/opengl/buffers.nim similarity index 100% rename from figuro/renderer/opengl/buffers.nim rename to src/figuro/renderer/opengl/buffers.nim diff --git a/figuro/renderer/opengl/context.nim b/src/figuro/renderer/opengl/context.nim similarity index 100% rename from figuro/renderer/opengl/context.nim rename to src/figuro/renderer/opengl/context.nim diff --git a/figuro/renderer/opengl/formatflippy.nim b/src/figuro/renderer/opengl/formatflippy.nim similarity index 100% rename from figuro/renderer/opengl/formatflippy.nim rename to src/figuro/renderer/opengl/formatflippy.nim diff --git a/figuro/renderer/opengl/commons.nim b/src/figuro/renderer/opengl/glcommons.nim similarity index 50% rename from figuro/renderer/opengl/commons.nim rename to src/figuro/renderer/opengl/glcommons.nim index 81da11a0..034b7612 100644 --- a/figuro/renderer/opengl/commons.nim +++ b/src/figuro/renderer/opengl/glcommons.nim @@ -1,11 +1,11 @@ import std/hashes -import ../../shared -# import ../../internal +import ../../commons import ../../common/nodes/render import ../../common/nodes/transfer -import ../../timers +import ../../runtime/utils/timers import ../../common/glyphs +import ../../common/fontutils export timers, hashes -export shared, render, transfer, glyphs +export shared, render, transfer, glyphs, fontutils diff --git a/figuro/renderer/opengl/glsl/410/atlas.frag b/src/figuro/renderer/opengl/glsl/410/atlas.frag similarity index 100% rename from figuro/renderer/opengl/glsl/410/atlas.frag rename to src/figuro/renderer/opengl/glsl/410/atlas.frag diff --git a/figuro/renderer/opengl/glsl/410/atlas.vert b/src/figuro/renderer/opengl/glsl/410/atlas.vert similarity index 100% rename from figuro/renderer/opengl/glsl/410/atlas.vert rename to src/figuro/renderer/opengl/glsl/410/atlas.vert diff --git a/figuro/renderer/opengl/glsl/410/mask.frag b/src/figuro/renderer/opengl/glsl/410/mask.frag similarity index 100% rename from figuro/renderer/opengl/glsl/410/mask.frag rename to src/figuro/renderer/opengl/glsl/410/mask.frag diff --git a/figuro/renderer/opengl/glsl/atlas.frag b/src/figuro/renderer/opengl/glsl/atlas.frag similarity index 100% rename from figuro/renderer/opengl/glsl/atlas.frag rename to src/figuro/renderer/opengl/glsl/atlas.frag diff --git a/figuro/renderer/opengl/glsl/atlas.vert b/src/figuro/renderer/opengl/glsl/atlas.vert similarity index 100% rename from figuro/renderer/opengl/glsl/atlas.vert rename to src/figuro/renderer/opengl/glsl/atlas.vert diff --git a/figuro/renderer/opengl/glsl/emscripten/atlas.frag b/src/figuro/renderer/opengl/glsl/emscripten/atlas.frag similarity index 100% rename from figuro/renderer/opengl/glsl/emscripten/atlas.frag rename to src/figuro/renderer/opengl/glsl/emscripten/atlas.frag diff --git a/figuro/renderer/opengl/glsl/emscripten/atlas.vert b/src/figuro/renderer/opengl/glsl/emscripten/atlas.vert similarity index 100% rename from figuro/renderer/opengl/glsl/emscripten/atlas.vert rename to src/figuro/renderer/opengl/glsl/emscripten/atlas.vert diff --git a/figuro/renderer/opengl/glsl/emscripten/mask.frag b/src/figuro/renderer/opengl/glsl/emscripten/mask.frag similarity index 100% rename from figuro/renderer/opengl/glsl/emscripten/mask.frag rename to src/figuro/renderer/opengl/glsl/emscripten/mask.frag diff --git a/figuro/renderer/opengl/glsl/mask.frag b/src/figuro/renderer/opengl/glsl/mask.frag similarity index 100% rename from figuro/renderer/opengl/glsl/mask.frag rename to src/figuro/renderer/opengl/glsl/mask.frag diff --git a/figuro/renderer/opengl/perf.nim b/src/figuro/renderer/opengl/perf.nim similarity index 100% rename from figuro/renderer/opengl/perf.nim rename to src/figuro/renderer/opengl/perf.nim diff --git a/figuro/renderer/opengl/renderer.nim b/src/figuro/renderer/opengl/renderer.nim similarity index 98% rename from figuro/renderer/opengl/renderer.nim rename to src/figuro/renderer/opengl/renderer.nim index 66371899..82cdfe36 100644 --- a/figuro/renderer/opengl/renderer.nim +++ b/src/figuro/renderer/opengl/renderer.nim @@ -1,4 +1,5 @@ import std/[hashes, os, strformat, tables, times, unicode] +export tables import pkg/threading/atomics import pkg/chroma @@ -8,12 +9,7 @@ from pixie import Image import pkg/sigils import pkg/sigils/threads -import window - -import commons, fontutils, context, formatflippy, utils - -export tables -export getTypeface, getTypeset +import window, glcommons, context, formatflippy, utils import std/locks diff --git a/figuro/renderer/opengl/shaders.nim b/src/figuro/renderer/opengl/shaders.nim similarity index 100% rename from figuro/renderer/opengl/shaders.nim rename to src/figuro/renderer/opengl/shaders.nim diff --git a/figuro/renderer/opengl/textures.nim b/src/figuro/renderer/opengl/textures.nim similarity index 100% rename from figuro/renderer/opengl/textures.nim rename to src/figuro/renderer/opengl/textures.nim diff --git a/figuro/renderer/opengl/utils.nim b/src/figuro/renderer/opengl/utils.nim similarity index 100% rename from figuro/renderer/opengl/utils.nim rename to src/figuro/renderer/opengl/utils.nim diff --git a/figuro/renderer/opengl/window.nim b/src/figuro/renderer/opengl/window.nim similarity index 97% rename from figuro/renderer/opengl/window.nim rename to src/figuro/renderer/opengl/window.nim index 5b98b2a6..5986f612 100644 --- a/figuro/renderer/opengl/window.nim +++ b/src/figuro/renderer/opengl/window.nim @@ -5,8 +5,8 @@ import pkg/opengl import pkg/windy import utils -import commons -import ../../common/nodes/ui +import glcommons +import ../../common/nodes/uinodes import pkg/sigils/weakrefs diff --git a/figuro/exec.nim b/src/figuro/runtime/runtimeCore.nim similarity index 93% rename from figuro/exec.nim rename to src/figuro/runtime/runtimeCore.nim index 1889b9c1..7f9cbae6 100644 --- a/figuro/exec.nim +++ b/src/figuro/runtime/runtimeCore.nim @@ -5,7 +5,7 @@ elif defined(blank): import engine/blank export blank else: - import renderer/opengl + import ../renderer/opengl export opengl import pkg/chronicles @@ -15,12 +15,12 @@ import std/os import sigils import sigils/threads -import shared, internal -import ui/[core, events] -import runtime/cssMonitor -import common/nodes/ui -import widget -import timers +import ../commons +import ../ui/[core, events] +import ../common/nodes/uinodes +import ../widget +import utils/cssMonitor +import utils/timers export core, events @@ -120,8 +120,8 @@ proc run*(frame: var AppFrame, frameRunner: AgentProcTy[tuple[]]) = appFrames[frameRef] = renderer frame.frameRunner = frameRunner - uiRenderEvent = initUiEvent() - uiAppEvent = initUiEvent() + # uiRenderEvent = initUiEvent() + # uiAppEvent = initUiEvent() appThread = newSigilThread() let frameProxy = frame.moveToThread(ensureMove appThread) diff --git a/figuro/execApps.nim b/src/figuro/runtime/runtimeNative.nim similarity index 92% rename from figuro/execApps.nim rename to src/figuro/runtime/runtimeNative.nim index 6cf2cfb6..66793580 100644 --- a/figuro/execApps.nim +++ b/src/figuro/runtime/runtimeNative.nim @@ -5,9 +5,10 @@ import pkg/sigils import pkg/sigils/threads import pkg/chronicles -import widget, shared, exec -import ui/core, ui/layout -import common/nodes/[transfer, ui, render] +import runtimeCore +import ../widget, ../commons +import ../ui/[core, layout] +import ../common/nodes/[transfer, uinodes, render] when not compileOption("threads"): {.error: "This module requires --threads:on compilation flag".} diff --git a/figuro/execScripts.nim b/src/figuro/runtime/runtimeVm.nim similarity index 99% rename from figuro/execScripts.nim rename to src/figuro/runtime/runtimeVm.nim index a108a508..93afda45 100644 --- a/figuro/execScripts.nim +++ b/src/figuro/runtime/runtimeVm.nim @@ -1,4 +1,4 @@ -import common/nodes/render +import nodes/render import shared import exec import runtime/jsonutils_lite diff --git a/figuro/runtime/cssMonitor.nim b/src/figuro/runtime/utils/cssMonitor.nim similarity index 95% rename from figuro/runtime/cssMonitor.nim rename to src/figuro/runtime/utils/cssMonitor.nim index 37a34467..66408618 100644 --- a/figuro/runtime/cssMonitor.nim +++ b/src/figuro/runtime/utils/cssMonitor.nim @@ -2,10 +2,8 @@ import std/paths, std/os import sigils import sigils/threads -import ../ui/basiccss - -import ../shared -import ../ui/[core] +import ../../commons +import ../../ui/core when defined(figuroFsMonitor): import libfswatch diff --git a/figuro/runtime/jsonutils_lite.nim b/src/figuro/runtime/utils/jsonutils_lite.nim similarity index 100% rename from figuro/runtime/jsonutils_lite.nim rename to src/figuro/runtime/utils/jsonutils_lite.nim diff --git a/figuro/timers.nim b/src/figuro/runtime/utils/timers.nim similarity index 100% rename from figuro/timers.nim rename to src/figuro/runtime/utils/timers.nim diff --git a/figuro/ui/animations.nim b/src/figuro/ui/animations.nim similarity index 100% rename from figuro/ui/animations.nim rename to src/figuro/ui/animations.nim diff --git a/figuro/ui/apis.nim b/src/figuro/ui/apis.nim similarity index 97% rename from figuro/ui/apis.nim rename to src/figuro/ui/apis.nim index 0c9ac142..0e47137b 100644 --- a/figuro/ui/apis.nim +++ b/src/figuro/ui/apis.nim @@ -1,19 +1,19 @@ -import std/[algorithm, macros, tables, os] -import std/with -import chroma, bumpy, stack_strings -import cssgrid -import chronicles +import std/[algorithm, macros, tables, os, hashes, with] +from std/sugar import capture +export with, capture -import std/[hashes] +import pkg/[chroma, bumpy, stack_strings, cssgrid, chronicles] +export cssgrid, stack_strings, constraints -import commons, core +import ../commons +import ../common/system +import ../common/system +import ../common/nodes/[uinodes, basics] +export commons, system, uinodes -from std/sugar import capture +import core +export core -export core, cssgrid, stack_strings -export with -export capture -export constraints # template nodes*[T](fig: T, blk: untyped): untyped = # ## begin drawing nodes @@ -276,7 +276,7 @@ proc cornerRadius*(current: Figuro, radius: float | float32) = proc loadTypeFace*(name: string): TypefaceId = ## Sets all radius of all 4 corners. - internal.getTypeface(name) + system.getTypeface(name) proc newFont*(typefaceId: TypefaceId): UiFont = result = UiFont() @@ -295,7 +295,7 @@ proc setText*( let thash = getContentHash(current.box, spans, hAlign, vAlign) if thash != current.textLayout.contentHash: trace "setText: ", nodeName = current.name, thash = thash, contentHash = current.textLayout.contentHash - current.textLayout = internal.getTypeset(current.box, spans, hAlign, vAlign) + current.textLayout = system.getTypeset(current.box, spans, hAlign, vAlign) refresh(current) ## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/figuro/ui/core.nim b/src/figuro/ui/core.nim similarity index 96% rename from figuro/ui/core.nim rename to src/figuro/ui/core.nim index 9d4e930a..5d9c65df 100644 --- a/figuro/ui/core.nim +++ b/src/figuro/ui/core.nim @@ -1,12 +1,15 @@ import std/[tables, unicode, os, strformat] import std/terminal import std/times -import sigils +import pkg/chronicles -import basiccss -import commons +# import basiccss +import ../commons +import ../common/system export commons -import pkg/chronicles +export system + +import csstheme when defined(nimscript): {.pragma: runtimeVar, compileTime.} @@ -41,8 +44,17 @@ var scrollBarFill* {.runtimeVar.} = rgba(187, 187, 187, 162).color scrollBarHighlight* {.runtimeVar.} = rgba(137, 137, 137, 162).color +const DefTypefaceName* = "IBMPlexSans-Regular.ttf" +const DefTypefaceRaw* = block: + let path = DataDirPath.string / DefTypefaceName + let data = readfile(path) + data + +static: + echo "DefTypefaceRaw: ", DefTypefaceRaw.len + var - defaultTypeface* {.runtimeVar.} = internal.getTypeface("IBMPlexSans-Regular.ttf") + defaultTypeface* {.runtimeVar.} = getTypeface(DefTypefaceName, DefTypefaceRaw, TTF) defaultFont* {.runtimeVar.} = UiFont(typefaceId: defaultTypeface, size: 14'ui) proc setSize*(frame: AppFrame, size: (UICoord, UICoord)) = diff --git a/figuro/common/nodes/csstheme.nim b/src/figuro/ui/csstheme.nim similarity index 99% rename from figuro/common/nodes/csstheme.nim rename to src/figuro/ui/csstheme.nim index e1d1b28c..325f4971 100644 --- a/figuro/common/nodes/csstheme.nim +++ b/src/figuro/ui/csstheme.nim @@ -1,5 +1,4 @@ -import ../../ui/basiccss -import ui +import ../commons import pkg/pretty import pkg/sigils/weakrefs diff --git a/figuro/ui/events.nim b/src/figuro/ui/events.nim similarity index 99% rename from figuro/ui/events.nim rename to src/figuro/ui/events.nim index fd36a1ea..3531468e 100644 --- a/figuro/ui/events.nim +++ b/src/figuro/ui/events.nim @@ -1,5 +1,5 @@ import pkg/sigils -import commons +import ../commons import core, utils diff --git a/figuro/ui/layout.nim b/src/figuro/ui/layout.nim similarity index 99% rename from figuro/ui/layout.nim rename to src/figuro/ui/layout.nim index 7c0457f4..10807943 100644 --- a/figuro/ui/layout.nim +++ b/src/figuro/ui/layout.nim @@ -3,9 +3,7 @@ import std/terminal import std/times import sigils -import basiccss -import commons -export commons +import ../commons import pkg/chronicles proc computeScreenBox*(parent, node: Figuro, depth: int = 0) = diff --git a/figuro/ui/textboxes.nim b/src/figuro/ui/textboxes.nim similarity index 99% rename from figuro/ui/textboxes.nim rename to src/figuro/ui/textboxes.nim index 61bd15dd..faeef4f1 100644 --- a/figuro/ui/textboxes.nim +++ b/src/figuro/ui/textboxes.nim @@ -1,6 +1,6 @@ import std/unicode -import commons +import ../commons import utils type @@ -51,7 +51,7 @@ proc updateLayout*(self: var TextBox, box = self.box, font = self.font) = self.box = box self.font = font let spans = {self.font: $self.runes(), self.font: "."} - self.layout = internal.getTypeset(self.box, spans) + self.layout = getTypeset(self.box, spans) self.runes().setLen(self.runes().len() - 1) iterator slices(selection: Slice[int], lines: seq[Slice[int]]): Slice[int] = diff --git a/figuro/ui/utils.nim b/src/figuro/ui/utils.nim similarity index 99% rename from figuro/ui/utils.nim rename to src/figuro/ui/utils.nim index 91124f01..a38039c1 100644 --- a/figuro/ui/utils.nim +++ b/src/figuro/ui/utils.nim @@ -1,7 +1,7 @@ from sugar import capture import std/sets import macros -import commons +import ../commons type State*[T] = object diff --git a/src/figuro/widget.nim b/src/figuro/widget.nim new file mode 100644 index 00000000..984a57ff --- /dev/null +++ b/src/figuro/widget.nim @@ -0,0 +1,8 @@ +import commons +export commons + +import ui/core +import ui/apis +import ui/utils + +export apis, core, inputs, utils diff --git a/figuro/widgets/button.nim b/src/figuro/widgets/button.nim similarity index 97% rename from figuro/widgets/button.nim rename to src/figuro/widgets/button.nim index 676c3369..53b01350 100644 --- a/figuro/widgets/button.nim +++ b/src/figuro/widgets/button.nim @@ -1,5 +1,4 @@ -import commons -import ../ui/utils +import ../widget type ButtonClicks* = enum diff --git a/figuro/widgets/horizontal.nim b/src/figuro/widgets/horizontal.nim similarity index 90% rename from figuro/widgets/horizontal.nim rename to src/figuro/widgets/horizontal.nim index 6602c74f..28f140d3 100644 --- a/figuro/widgets/horizontal.nim +++ b/src/figuro/widgets/horizontal.nim @@ -1,7 +1,4 @@ -import commons -import ../ui/utils import ../widget -export widget type Horizontal* = ref object of Figuro diff --git a/figuro/widgets/input.nim b/src/figuro/widgets/input.nim similarity index 99% rename from figuro/widgets/input.nim rename to src/figuro/widgets/input.nim index a7a65dc8..ae96a0b9 100644 --- a/figuro/widgets/input.nim +++ b/src/figuro/widgets/input.nim @@ -1,8 +1,7 @@ import std/unicode - -import commons -import ../ui/utils +import ../widget import ../ui/textboxes +import pkg/chronicles type Input* = ref object of Figuro isActive*: bool diff --git a/figuro/widgets/scrollpane.nim b/src/figuro/widgets/scrollpane.nim similarity index 99% rename from figuro/widgets/scrollpane.nim rename to src/figuro/widgets/scrollpane.nim index d91aef82..337191f5 100644 --- a/figuro/widgets/scrollpane.nim +++ b/src/figuro/widgets/scrollpane.nim @@ -1,7 +1,6 @@ -import commons import std/hashes - -import chronicles +import pkg/chronicles +import ../widget type ScrollPane* = ref object of Figuro diff --git a/figuro/widgets/vertical.nim b/src/figuro/widgets/vertical.nim similarity index 90% rename from figuro/widgets/vertical.nim rename to src/figuro/widgets/vertical.nim index 26735ff2..75f4e00d 100644 --- a/figuro/widgets/vertical.nim +++ b/src/figuro/widgets/vertical.nim @@ -1,7 +1,4 @@ -import commons -import ../ui/utils import ../widget -export widget type Vertical* = ref object of Figuro diff --git a/figuro/wrappers.nim b/src/figuro/wrappers.nim similarity index 100% rename from figuro/wrappers.nim rename to src/figuro/wrappers.nim diff --git a/tests/config.nims b/tests/config.nims index 28cc8e2a..e36139c2 100644 --- a/tests/config.nims +++ b/tests/config.nims @@ -1 +1 @@ ---path:"../" \ No newline at end of file +--path:"../src" \ No newline at end of file diff --git a/tests/tanimate.nim b/tests/tanimate.nim index cd7eb86d..3f2e5c3e 100644 --- a/tests/tanimate.nim +++ b/tests/tanimate.nim @@ -2,7 +2,6 @@ ## This minimal example shows 5 blue squares. import figuro/widgets/button -import figuro/widget import figuro import std/sugar diff --git a/tests/tbind.nim b/tests/tbind.nim index 7c461e60..97e13947 100644 --- a/tests/tbind.nim +++ b/tests/tbind.nim @@ -1,5 +1,4 @@ import figuro/widgets/button -import figuro/widget import figuro diff --git a/tests/tbutton.nim b/tests/tbutton.nim index a8a1e2c3..5619e8c5 100644 --- a/tests/tbutton.nim +++ b/tests/tbutton.nim @@ -1,5 +1,4 @@ import figuro/widgets/button -import figuro/widget import figuro let diff --git a/tests/tclick.nim b/tests/tclick.nim index 4063bcb5..4936cd3d 100644 --- a/tests/tclick.nim +++ b/tests/tclick.nim @@ -1,5 +1,4 @@ import figuro/widgets/[button, horizontal] -import figuro/widget import figuro/ui/animations import figuro diff --git a/tests/tcsstheme.nim b/tests/tcsstheme.nim index aeb036aa..5f562e8a 100644 --- a/tests/tcsstheme.nim +++ b/tests/tcsstheme.nim @@ -5,9 +5,8 @@ import cssgrid import pretty import chronicles -import figuro/ui/basiccss import figuro/widget -import figuro/common/nodes/ui +import figuro/common/nodes/uinodes import figuro/common/nodes/render import figuro/widgets/button diff --git a/tests/tdrag.nim b/tests/tdrag.nim index bdc3429b..1975f1a1 100644 --- a/tests/tdrag.nim +++ b/tests/tdrag.nim @@ -1,6 +1,5 @@ import figuro/widgets/button import figuro/ui/animations -import figuro/widget import figuro let diff --git a/tests/test_script_ui_nodes.nims b/tests/test_script_ui_nodes.nims deleted file mode 100644 index 772264e6..00000000 --- a/tests/test_script_ui_nodes.nims +++ /dev/null @@ -1,8 +0,0 @@ - -## This minimal example shows 5 blue squares. - -import figuro/common/nodes/ui - -type - Main* = ref object of Figuro - value: float diff --git a/tests/tfade.nim b/tests/tfade.nim index fadd454d..8c99dbce 100644 --- a/tests/tfade.nim +++ b/tests/tfade.nim @@ -2,7 +2,6 @@ ## This minimal example shows 5 blue squares. import figuro/widgets/[horizontal, button] import figuro/ui/animations -import figuro/widget import figuro import sugar diff --git a/tests/tfadeAlt.nim b/tests/tfadeAlt.nim index b85bb358..8927cda3 100644 --- a/tests/tfadeAlt.nim +++ b/tests/tfadeAlt.nim @@ -1,8 +1,6 @@ ## This minimal example shows 5 blue squares. -import figuro/widgets/button -import figuro/widgets/horizontal -import figuro/widget +import figuro/widgets/[button, horizontal] import figuro type diff --git a/tests/tfontutils.nim b/tests/tfontutils.nim index e3b357f7..fc921f83 100644 --- a/tests/tfontutils.nim +++ b/tests/tfontutils.nim @@ -1,7 +1,7 @@ import unittest import figuro -import figuro/renderer/opengl/fontutils +import figuro/common/fontutils let typeface = loadTypeFace("IBMPlexSans-Regular.ttf") @@ -17,7 +17,7 @@ suite "fontutils": let spans = {font: "hi", smallFont: "AA", font: "AA"} - let textLayout = internal.getTypeset(box, spans, + let textLayout = getTypeset(box, spans, hAlign = FontHorizontal.Left, vAlign = FontVertical.Top) diff --git a/tests/tgrid.nim b/tests/tgrid.nim index 19145cfa..1dc78bc8 100644 --- a/tests/tgrid.nim +++ b/tests/tgrid.nim @@ -1,9 +1,7 @@ import std/[math, strformat] import figuro/widgets/button -import figuro/widget import figuro -import std/with type GridApp = ref object of Figuro diff --git a/tests/tgridautoflow.nim b/tests/tgridautoflow.nim index 4cf1c876..f8424bd6 100644 --- a/tests/tgridautoflow.nim +++ b/tests/tgridautoflow.nim @@ -1,6 +1,5 @@ import figuro/widgets/button -import figuro/widget import figuro type diff --git a/tests/tinput.nim b/tests/tinput.nim index 9e3cc641..8d24b9eb 100644 --- a/tests/tinput.nim +++ b/tests/tinput.nim @@ -2,7 +2,6 @@ ## This minimal example shows 5 blue squares. import figuro/widgets/input import figuro/widgets/button -import figuro/widget import figuro let diff --git a/tests/tlayers.nim b/tests/tlayers.nim index cbcd84d8..65212074 100644 --- a/tests/tlayers.nim +++ b/tests/tlayers.nim @@ -1,7 +1,6 @@ ## This minimal example shows 5 blue squares. import figuro/widgets/button -import figuro/widget import figuro let diff --git a/tests/tminimal.nim b/tests/tminimal.nim index 65a7cbaf..fededf18 100644 --- a/tests/tminimal.nim +++ b/tests/tminimal.nim @@ -1,7 +1,6 @@ ## This minimal example shows 5 blue squares. import figuro/widgets/[button] -import figuro/widget import figuro import std/sugar diff --git a/tests/tscroll.nim b/tests/tscroll.nim index a3beec0b..899900d9 100644 --- a/tests/tscroll.nim +++ b/tests/tscroll.nim @@ -1,9 +1,6 @@ ## This minimal example shows 5 blue squares. -import figuro/widgets/button -import figuro/widgets/scrollpane -import figuro/widgets/vertical -import figuro/widget +import figuro/widgets/[button, scrollpane, vertical] import figuro let diff --git a/tests/ttext.nim b/tests/ttext.nim index 81eb130a..70dd7831 100644 --- a/tests/ttext.nim +++ b/tests/ttext.nim @@ -1,7 +1,6 @@ ## This minimal example shows 5 blue squares. import figuro/widgets/button -import figuro/widget import figuro let diff --git a/tests/unittests/config.nims b/tests/unittests/config.nims new file mode 100644 index 00000000..cf9b2a26 --- /dev/null +++ b/tests/unittests/config.nims @@ -0,0 +1 @@ +--path:"../../src" \ No newline at end of file diff --git a/tests/unittests/ttransfer.nim b/tests/unittests/ttransfer.nim index b82704a1..5c70353f 100644 --- a/tests/unittests/ttransfer.nim +++ b/tests/unittests/ttransfer.nim @@ -8,7 +8,7 @@ import pkg/pretty import figuro/ui/layout import figuro/widget -import figuro/common/nodes/ui +import figuro/common/nodes/uinodes import figuro/common/nodes/render import figuro/common/nodes/transfer