Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor paths #75

Merged
merged 21 commits into from
Jan 23, 2025
Merged
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: 1 addition & 1 deletion examples/config.nims
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--path:"../"
--path:"../src"
2 changes: 1 addition & 1 deletion examples/hnbrowser.nim
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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":
Expand Down
4 changes: 2 additions & 2 deletions figuro.nimble
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 0 additions & 10 deletions figuro/ui/commons.nim

This file was deleted.

9 changes: 0 additions & 9 deletions figuro/widget.nim

This file was deleted.

5 changes: 0 additions & 5 deletions figuro/widgets/commons.nim

This file was deleted.

39 changes: 0 additions & 39 deletions figuro/widgets/experimental/buttonWrap.nim

This file was deleted.

1 change: 0 additions & 1 deletion figuro/windows.nim

This file was deleted.

10 changes: 5 additions & 5 deletions figuro.nim → src/figuro.nim
Original file line number Diff line number Diff line change
@@ -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".}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,7 +7,7 @@ import pkg/pixie/fonts
import pkg/windy
import pkg/threading/channels

import commons
import glyphs, extras, shared

import pretty

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions figuro/inputs.nim → src/figuro/common/inputs.nim
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cssgrid
import stylus
import patty
import chroma
import ../common/nodes/basics
import basics
import chronicles

variantp CssValue:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ui as ui
import uinodes as ui
import render as render
import ../../shared
import ../shared

type
RenderList* = object
Expand Down
20 changes: 10 additions & 10 deletions figuro/common/nodes/ui.nim → src/figuro/common/nodes/uinodes.nim
Original file line number Diff line number Diff line change
@@ -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.}
Expand Down
21 changes: 10 additions & 11 deletions figuro/shared.nim → src/figuro/common/shared.nim
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,7 +24,7 @@ proc MainThread*() {.tags: [MainThreadEff].} =
proc RenderThread*() {.tags: [RenderThreadEff].} =
discard

template threads*(arg: typed) =
template runtimeThreads*(arg: typed) =
arg()

{.pop.}
Expand All @@ -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
Expand Down
Loading
Loading