From 23ab07304a66bacedf7267232f4b420969cfbaf5 Mon Sep 17 00:00:00 2001 From: Patitotective Date: Wed, 10 Jan 2024 17:20:21 -0500 Subject: [PATCH] Actual v2 (the previous commit saying v2 was v1) --- ImExample.nimble | 26 ++--- README.md | 268 ++++++++++++++++++++++----------------------- resources.nim | 2 +- src/configtype.nim | 49 +++++++++ src/types.nim | 114 +------------------ 5 files changed, 196 insertions(+), 263 deletions(-) create mode 100644 src/configtype.nim diff --git a/ImExample.nimble b/ImExample.nimble index c8b2abd..209dff5 100644 --- a/ImExample.nimble +++ b/ImExample.nimble @@ -17,7 +17,7 @@ requires "tinydialogs >= 1.0.0" requires "constructor >= 1.2.0" import std/[strformat, options] -import src/types +import src/configtype const config = initConfig() @@ -28,13 +28,12 @@ let arch = getEnv("ARCH", "amd64") let outPath = getEnv("OUTPATH", toExe &"{config.name}-{version}-{arch}") let flags = getEnv("FLAGS") -let args = &"--app:gui --out:{outPath} --cpu:{arch} -d:configPath={configPath} {flags}" +let args = &"--app:gui --out:{outPath} --cpu:{arch} {flags}" task buildr, "Build the application for release": - exec "nimble install -d -y" - exec &"nim c -d:release {args} main.nim" + exec &"nimble c -d:release {args} main.nim" -const desktop = """ +const desktopTemplate = """ [Desktop Entry] Name=$name Exec=AppRun @@ -52,14 +51,13 @@ task buildapp, "Build the AppImage": let appimagePath = &"{config.name}-{version}-{arch}.AppImage" # Compile applicaiton executable - if not existsDir("AppDir"): mkDir("AppDir") - exec "nimble install -d -y" - exec &"nim c -d:release -d:appimage {args} --out:AppDir/AppRun main.nim" + if not dirExists("AppDir"): mkDir("AppDir") + exec &"nimble c -d:release -d:appimage {args} --out:AppDir/AppRun main.nim" # Make desktop file writeFile( &"AppDir/{config.name}.desktop", - desktop % [ + desktopTemplate % [ "name", config.name, "categories", config.categories.join(";"), "version", config.version, @@ -71,9 +69,9 @@ task buildapp, "Build the AppImage": cpFile(config.iconPath, "AppDir/.DirIcon") cpFile(config.svgIconPath, &"AppDir/{config.name}.svg") - if config.appstreamPath.isSome: + if config.appstreamPath.len > 0: mkDir("AppDir/usr/share/metainfo") - cpFile(config.appstreamPath.get, &"AppDir/usr/share/metainfo/{config.name}.appdata.xml") + cpFile(config.appstreamPath, &"AppDir/usr/share/metainfo/{config.name}.appdata.xml") # Get appimagetool var appimagetoolPath = "appimagetool" @@ -82,15 +80,15 @@ task buildapp, "Build the AppImage": exec(&"{appimagetoolPath} --help") except OSError: appimagetoolPath = "./appimagetool-x86_64.AppImage" - if not existsFile(appimagetoolPath): + if not fileExists(appimagetoolPath): echo &"Downloading {appimagetoolPath}" - exec &"wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O ", appimagetoolPath + exec &"wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O {appimagetoolPath}" exec &"chmod +x {appimagetoolPath}" # Actually use appimagetool to build the AppImage if config.ghRepo.isSome: echo "Building updateable AppImage" - exec &"{appimagetoolPath} -u \"gh-releases-zsync|{config.ghRepo.get[0]}|{config.ghRepo.get[0]}|latest|{config.name}-*-{arch}.AppImage.zsync\" AppDir {appimagePath}" + exec &"{appimagetoolPath} -u \"gh-releases-zsync|{config.ghRepo.get.user}|{config.ghRepo.get.repo}|latest|{config.name}-*-{arch}.AppImage.zsync\" AppDir {appimagePath}" else: echo &"ghRepo not defined. Skipping updateable AppImage" exec &"{appimagetoolPath} AppDir {appimagePath}" diff --git a/README.md b/README.md index 5604a15..9f251eb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ImTemplate -Template for making a single-windowed (or not) Dear ImGui application in Nim. +Template for making a single-windowed Dear ImGui application in Nim. ![Main Window](https://user-images.githubusercontent.com/79225325/170889620-d1b3ce74-c92d-440c-9144-92b068973651.png) @@ -7,12 +7,14 @@ Template for making a single-windowed (or not) Dear ImGui application in Nim. ## Features - Icon font support. -- Simple about modal. -- Preferences system (with preferences modal). +- About modal. +- Preferences system. +- Settings modal. - AppImage support (Linux). - Updateable AppImage support (with [gh-releases-zsync](https://github.com/AppImage/AppImageSpec/blob/master/draft.md#github-releases)). -- Simple data resources support. +- Simple data resources support (embed files into the binary). - GitHub workflow for building and uploading the AppImage and `.exe` as assets. +- Non-blocking (using a [`std/threadpool`](https://nim-lang.org/docs/threadpool.html)) native system dialogs using [`tinydialogs`](https://github.com/Patitotective/tinydialogs). (To use NimGL in Ubuntu you might need some libraries `sudo apt install libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libgl-dev`) @@ -20,25 +22,27 @@ Template for making a single-windowed (or not) Dear ImGui application in Nim. - `README.md`: Project's description. - `LICENSE`: Project's license. - `main.nim`: Application's logic. -- `resourcesdata.nim`: To bundle data resources (see [Bundling](#bundling)). -- `nakefile.md`: [Nakefile](https://github.com/fowlmouth/nake) to build the AppImage (see [Building](#building)). +- `resources.nim`: To bundle data resources (see [Bundling](#bundling)). - `config.nims`: Nim compile configuration. -- `config.toml`: Application's configuration (see [Config](#config)). - `ImExample.nimble`: [Nimble file](https://github.com/nim-lang/nimble#creating-packages). -- `assets`: +- `assets`: - `icon.png`, `icon.svg`: App icons. - - `style.toml`: Style (using [ImStyle](https://github.com/Patitotective/ImStyle)). + - `style.kdl`: Style (using [ImStyle](https://github.com/Patitotective/ImStyle)). - `Cousine-Regular.ttf`, `Karla-Regular.ttf`, `Roboto-Regular.ttf`, `ProggyVector Regular.ttf`: Multiple fonts so you can choose the one you like the most. - `forkawesome-webfont.ttf`: ForkAwesome icon font (see https://forkaweso.me/). - `src`: + - `types.nim`: Type definitions used by other modules. - `icons.nim`: Helper module with [ForkAwesome](https://forkaweso.me) icons unicode points. - `utils.nim`: Useful procedures, general types or anything used by more than one module. - - `settingsmodal.nim`: Draw the preferences modal (called in `main.nim`) + - `settingsmodal.nim`: Draw the settings modal ## Icon Font -ImTemplate uses [ForkAwesome](https://forkaweso.me)'s icon font to be able to display icon in labes, to do it you only need to import [`icons.nim`](https://github.com/Patitotective/ImTemplate/blob/main/src/icons.toml) (where the unicode points for each icon are defined), browse https://forkaweso.me/Fork-Awesome/icons, choose the one you want and, for example, if you want to use [`fa-floppy-o`](https://forkaweso.me/Fork-Awesome/icon/floppy-o/), you will write `FA_FloppyO` in a string: +ImTemplate uses [ForkAwesome](https://forkaweso.me)'s icon font to be able to display icon in labels, to do it you only need to import [`icons.nim`](https://github.com/Patitotective/ImTemplate/blob/main/src/icons.nim) (where the unicode points for each icon are defined), browse https://forkaweso.me/Fork-Awesome/icons, choose the one you want and, for example, if you want to use [`fa-floppy-o`](https://forkaweso.me/Fork-Awesome/icon/floppy-o/), you will write `FA_FloppyO` in a string: ```nim ... +# main.nim +import src/icons + if igButton("Open Link " & FA_ExternalLink): openURL("https://forkaweso.me") ``` @@ -47,158 +51,144 @@ if igButton("Open Link " & FA_ExternalLink): The code is designed to rely on the `App` type (defined in [`utils.nim`](https://github.com/Patitotective/ImTemplate/blob/main/src/utils.nim)), you may want to store anything that your program needs inside it. ```nim type - App* = ref object + App* = object win*: GLFWWindow - font*: ptr ImFont - prefs*: Prefs - cache*: TomlValueRef # Settings cache - config*: TomlValueRef # Prefs table + config*: Config + prefs*: KdlPrefs[Prefs] + fonts*: array[Config.fonts.len, ptr ImFont] + resources*: Table[string, string] + maxLabelWidth*: float32 + messageBoxResult*: FlowVar[Button] # Add your variables here ... ``` - `win`: GLFW window. -- `font`: Default app font (you may want to add more fonts). -- `prefs`: App preferences (using [niprefs](https://patitotective.github.io/niprefs/)). -- `cache`: Preferences modal cache settings (to discard or apply them). +- `fonts`: An array containing the loaded fonts from `Config.fonts`. +- `prefs`: See [Prefs](#prefs). - `config`: Configuration file (loaded from `config.toml`). +- `resources`: Data resources where the key is the filename and the value is the binary data. +- `maxLabelWidth`: This is a value that's used to draw the settingsmodal (see https://github.com/Patitotective/ImTemplate/blob/main/src/settingsmodal.nim) +- `messageBoxResult`: This variable stores the result to a message box dialog opened by [`tinydialogs`](https://github.com/Patitotective/tinydialogs), it uses the `FlowVar` type since it's the result of a spawned thread. ## Config -The application's configuration will store information about the app that you may want to change after compiled and before deployed (like the name or version). -It is stored using [niprefs](https://patitotective.github.io/niprefs/) and by default at [`config.toml`](https://github.com/Patitotective/ImTemplate/blob/main/config.toml): +The configuration stores data like name and version of the application, it is stored in its type definition in `src/configtype.nim` using `constructor/defaults` to define the default values: ```nim -# App -name = "ImExample" -comment = "ImExample is a simple Dear ImGui application example" -version = "0.4.0" -website = "https://github.com/Patitotective/ImTemplate" -authors = ["Patitotective ", "Cristobal ", "Omar Cornut ", "Beef, Yard, Rika", "and the Nim community :]", "Inu147"] -categories = ["Utility"] - -# AppImage -ghRepo = "Patitotective/ImTemplate" - -stylePath = "assets/style.toml" -iconPath = "assets/icon.png" -svgIconPath = "assets/icon.svg" -iconFontPath = "assets/forkawesome-webfont.ttf" -fontPath = "assets/ProggyVector Regular.ttf" # Other options are Roboto-Regular.ttf, Cousine-Regular.ttf or Karla-Regular.ttf -fontSize = 16.0 - -# Window -minSize = [200, 200] # Width, height - -# Settings for the preferences window -[settings.input] -type = "input" -default = "Hello World" -max = 100 -flags = "None" # See https://nimgl.dev/docs/imgui.html#ImGuiInputTextFlags -help = "Help message" -... +type + Config* {.defaults: {defExported}.} = object + name* = "ImExample" + comment* = "ImExample is a simple Dear ImGui application example" + version* = "2.0.0" + website* = "https://github.com/Patitotective/ImTemplate" + authors* = [ + (name: "Patitotective", url: "https://github.com/Patitotective"), + ("Cristobal", "mailto:cristobalriaga@gmail.com"), + ("Omar Cornut", "https://github.com/ocornut"), + ("Beef, Yard, Rika", ""), + ("and the Nim community :]", ""), + ("Inu147", ""), + ] + categories* = "Utility" + + stylePath* = "assets/style.kdl" + iconPath* = "assets/icon.png" + svgIconPath* = "assets/icon.svg" + + iconFontPath* = "assets/forkawesome-webfont.ttf" + fonts* = [ + font("assets/ProggyVector Regular.ttf", 16f), # Other options are Roboto-Regular.ttf, Cousine-Regular.ttf or Karla-Regular.ttf + font("assets/NotoSansJP-Regular.otf", 16f, GlyphRanges.Japanese), + ] + + # AppImage + ghRepo* = (user: "Patitotective", repo: "ImTemplate").some + appstreamPath* = "" + + # Window + minSize* = (w: 200i32, h: 200i32) # < 0: don't care ``` - -### About Modal -Using the information from the config file, ImTemplate creates a simple about modal. - -![About Modal](https://user-images.githubusercontent.com/79225325/170889730-8cba620b-3d6d-4574-8228-5c45930821d1.png) - -### Keys Explanation -- `name`: App name. -- `comment`: App description. -- `version`: App version. +### Fields Explanation +- `name`: App's name. +- `comment`: App's description. +- `version`: App's version. - `website`: A link where you can find more information about the app. -- `authors`: A sequence of strings to display in the about modal, a link for the author can be specified inside `<>`, e.i.: `@["Patitotective ", "Cristobal "]`. +- `authors`: An array containing information about the authors. - `categories`: Sequence of [registered categories](https://specifications.freedesktop.org/menu-spec/latest/apa.html) (for the AppImage). - -(AppImage) -- `ghRepo`: GitHub repo to fetch releases from (including this key will generate an `AppImage.zsync` file, include it in your releases for [updates](https://docs.appimage.org/packaging-guide/optional/updates.html#using-appimagetool), skip it to disable). -- `appstreamPath`: Path to the [AppStream metadata](https://docs.appimage.org/packaging-guide/optional/appstream.html) (optional). - -(Paths) -- `stylePath`: App style path (using https://github.com/Patitotective/ImStyle). -- `iconPath`: Icon path. +- `stylePath`: App's ImStyle path (using https://github.com/Patitotective/ImStyle). +- `iconPath`: PNG icon path. - `svgIconPath`: Scalable icon path - `iconFontPath`: [ForkAwesome](https://forkaweso.me)'s font path. -- `fontPath`: Font path. -- `fontSize`: Font size. +- `fonts`: An array of `Font` objects containing the font's path, size and range of glyphs for japanese, korean, chinese, etc. +- `ghRepo`: GitHub repo to fetch releases from (if it's some it will generate an `AppImage.zsync` file, include it in your releases for [AppImage updates](https://docs.appimage.org/packaging-guide/optional/updates.html#using-appimagetool)). +- `appstreamPath`: Path to the [AppStream metadata](https://docs.appimage.org/packaging-guide/optional/appstream.html). +- `minSize`: Window's minimum size, use numbers less than zero to disable a limit. -- `minSize`: Window's minimum size. -- `settings`: See [`settings`](#settings). - -### `settings` -Define the preferences that the user can modify through the preferences modal. - -These preferences will be stored at `getCacheDir(config["name"])` along with the window size and position using [niprefs](https://patitotective.github.io/niprefs/). To acces them you only need to do `app.prefs["name"]` +### About Modal +Using the information from the config object, ImTemplate creates a simple about modal. -![Prefs Modal](https://user-images.githubusercontent.com/79225325/170889748-316c4b7a-47d0-4a65-82b3-d4e50b9252ea.png) +![About Modal](https://user-images.githubusercontent.com/79225325/170889730-8cba620b-3d6d-4574-8228-5c45930821d1.png) -Each child key has to have the `type` key, and depending on it the required keys may change so go check [config.toml](https://github.com/Patitotective/ImTemplate/blob/main/config.toml) to see which keys which types do require. +## Prefs +The preferences are data can change during runtime and data that you want to store for the future like the position and size of the window, this includes the settings like the language and theme. +The preferences are saved in a KDL file (using [kdl/prefs](https://patitotective.github.io/kdl-nim/kdl/prefs.html)). +You just have to provide an object including all the data you want to store as fields: ```nim -[settings.combo] -type = "combo" -default = 2 # Or "c" -items = ["a", "b", "c"] -flags = "None" # See https://nimgl.dev/docs/imgui.html#ImGuiComboFlags +type + Prefs* {.defaults: {defExported}.} = object + maximized* = false # Was the window maximized when the app was closed? + winpos* = (x: -1i32, y: -1i32) # Window position + winsize* = (w: 600i32, h: 650i32) # Window size + settings* = initSettings() ``` -There are two special keys, `display` and `help`, `display` replaces the name to display and `help` shows a help marker with help information (`help` does not work for `Section`s). -To access `combo`'s value in your program you should do `app.prefs["combo"]` - -#### Setting types -- `Input`: Input text. -- `Check`: Checkbox. -- `Slider`: Integer slider. -- `FSlider`: Float slider. -- `Spin`: Integer spin. -- `FSpin`: Float spin. -- `Combo`: Combo. -- `Radio`: Radio button. -- `Color3`: Color edit RGB. -- `Color4`: Color edit RGBA. -- `Section`: See [`Section`](#section) - -#### `Section` -![Setting Section](https://user-images.githubusercontent.com/79225325/170889758-b7845c4a-df3a-4a06-a0c9-e64b0659097e.png) - -Section types are useful to group similar settings. -It fits the settings at `content` inside a [collapsing header](https://nimgl.dev/docs/imgui.html#igCollapsingHeader%2Ccstring%2CImGuiTreeNodeFlags). + +### Settings +The settings are preferences that the user can modify through the settings modal. + +![Settings Modal](https://user-images.githubusercontent.com/79225325/170889748-316c4b7a-47d0-4a65-82b3-d4e50b9252ea.png) + +You can define all the settings' settings (i.e.: combobox, checkbox, input, etc.) through the `Settings` object: ```nim -[settings.colors] -display = "Color pickers" -type = "section" -flags = "None" # See https://nimgl.dev/docs/imgui.html#ImGuiTreeNodeFlags -[settings.colors.content.color] -display = "RGB color" -type = "color3" # RGB -default = "#000000" # Or [0, 0, 0] or rgb(0, 0, 0) or black -flags = "None" # See https://nimgl.dev/docs/imgui.html#ImGuiColorEditFlags -[settings.colors.content.alphaColor] -display = "RGBA color" -type = "color4" # RGBA -default = "rgba(17, 209, 194, 0.64)" # Or [0.06666667014360428, 0.8196078538894653, 0.7607843279838562, 0.6392157077789307] -flags = "None" # See https://nimgl.dev/docs/imgui.html#ImGuiColorEditFlags +type + Os* {.defaults: {}.} = object + file* = fileSetting(display = "Text File", filterPatterns = @["*.txt", "*.nim", "*.kdl", "*.json"]) + files* = filesSetting(display = "Multiple files", singleFilterDescription = "Anything", default = @[".bashrc", ".profile"]) + folder* = folderSetting(display = "Folder") + + Numbers* {.defaults: {}.} = object + spin* = spinSetting(display = "Int Spinner", default = 4, range = 0i32..10i32) + fspin* = fspinSetting(display = "Float Spinner", default = 3.14, range = 0f..10f) + slider* = sliderSetting(display = "Int Slider", default = 40, range = -100i32..100i32) + fslider* = fsliderSetting(display = "Float Slider", default = -2.5, range = -10f..10f) + + Colors* {.defaults: {}.} = object + rgb* = rgbSetting(default = [1f, 0f, 0.2f]) + rgba* = rgbaSetting(default = [0.4f, 0.7f, 0f, 0.5f], flags = @[AlphaBar, AlphaPreviewHalf]) + + Sizes* = enum + None, Huge, Big, Medium, Small, Mini ``` -To access `alphaColor` you will need to do `app.prefs["colors"]["alphaColor"]` or `app.prefs{"colors", "alphaColor"}`. ## Building -To build your app you may want to run `nimble buildApp` task. +To build your app you may want to run `nimble buildr` task. +You can set the following environment variables to change the building process: +- `ARCH`: the architecture used to compile the binary, by default `amd64`. +- `OUTPATH`: the path of the binary file (or exe file on Windows), by default "name-version-arch" +- `FLAGS`: any other flags you want to pass to the compiler, optional. -_Note: Unfortunately on Window most of the times Nim binaries are flagged as virus, see https://github.com/nim-lang/Nim/issues/17820._ +**_Note: Unfortunately on Window most of the times Nim binaries are flagged as virus, see https://github.com/nim-lang/Nim/issues/17820._** ### Bundling -To bundle your app resources inside the compiled binary, you only need to go to `resourcesdata.nim` file and define their paths in the `resources` array. -After that `resourcesdata` is imported in `main.nim`. So when you compile it, it statically reads those files and creates a table with `[path, data]`. -To access them use `path.getData()`. -[`resourcesdata.nim`](https://github.com/Patitotective/ImTemplate/blob/main/resourcesdata.nim) +To bundle your app resources inside the compiled binary, you only need to go to [`resources.nim`](https://github.com/Patitotective/ImTemplate/blob/main/resources.nim) file and define their paths in the `resourcesPaths` array. +After that `resources` is imported in `main.nim`. So when you compile it, it statically reads those files and creates a table with the binary data. +To access them use `app.resources["path"]`. +By default this is how `resourcesPaths` looks like: ```nim ... -const resourcesPaths = [ - configPath, - config["iconPath"].getString(), - config["stylePath"].getString(), - config["fontPath"].getString(), - config["iconFontPath"].getString() -] +const resourcesPaths = @[ + config.stylePath, + config.iconPath, + config.iconFontPath, +] & config.fonts.mapIt(it.path) # Add the paths of each font ... ``` @@ -206,13 +196,13 @@ const resourcesPaths = [ You can publish your application as a [binary package](https://github.com/nim-lang/nimble#binary-packages) with nimble. ### AppImage (Linux) -To build your app as an AppImage you will need to run `nake build`, it will install the dependencies, compile the app, check for `appimagetool` (and install it if its not found in the `$PATH`), generate the `AppDir` directory and finally build the AppImage. -If you included the `ghRepo` key in the config file, it will generate also an `AppImage.zsync` file. You should attach this file along with the `AppImage` to your GitHub release. -If you included the `appstreamPath` key, it will get copied to `AppDir/usr/share/shareinfo/{config["name"]}.appdata.xml` (see https://docs.appimage.org/packaging-guide/optional/appstream.html). +To build your app as an AppImage you will need to run `nimble buildapp`, it will install the dependencies, compile the app, check for `appimagetool` (and install it if its not found in the `$PATH`), generate the `AppDir` directory and finally build the AppImage. +If you included `ghRepo` in the config, it will also generate an `AppImage.zsync` file. You should attach this file along with the `AppImage` to your GitHub release. +If you included `appstreamPath`, it will get copied to `AppDir/usr/share/shareinfo/{config.name}.appdata.xml` (see https://docs.appimage.org/packaging-guide/optional/appstream.html). ### Creating a release -ImTemplate has a [`build.yml` workflow](https://github.com/Patitotective/ImTemplate/blob/main/.github/workflows/build.yml) that automatically when you publish a release, builds an AppImage and an `.exe` file to then upload them as assets to the release. -This can take several minutes. +ImTemplate has a [`build.yml` workflow](https://github.com/Patitotective/ImTemplate/blob/main/.github/workflows/build.yml) that automatically when you publish a release, builds an AppImage and an `.exe` file to then upload them as assets to the release. +This can take several minutes. ## Generated from ImTemplate Apps using this template: diff --git a/resources.nim b/resources.nim index 7c48bb8..b48c59b 100644 --- a/resources.nim +++ b/resources.nim @@ -1,6 +1,6 @@ import std/[sequtils, tables] import kdl -import src/types +import src/configtype const config = initConfig() diff --git a/src/configtype.nim b/src/configtype.nim new file mode 100644 index 0000000..45936ea --- /dev/null +++ b/src/configtype.nim @@ -0,0 +1,49 @@ +import std/options +import constructor/defaults + +type + + GlyphRanges* = enum + Default, ChineseFull, ChineseSimplified, Cyrillic, Japanese, Korean, Thai, Vietnamese + + Font* = object + path*: string + size*: float32 + glyphRanges*: GlyphRanges + +proc font*(path: string, size: float32, glyphRanges = GlyphRanges.Default): Font = + Font(path: path, size: size, glyphRanges: glyphRanges) + +type + Config* {.defaults: {defExported}.} = object + name* = "ImExample" + comment* = "ImExample is a simple Dear ImGui application example" + version* = "2.0.0" + website* = "https://github.com/Patitotective/ImTemplate" + authors* = [ + (name: "Patitotective", url: "https://github.com/Patitotective"), + ("Cristobal", "mailto:cristobalriaga@gmail.com"), + ("Omar Cornut", "https://github.com/ocornut"), + ("Beef, Yard, Rika", ""), + ("and the Nim community :]", ""), + ("Inu147", ""), + ] + categories* = ["Utility"] + + stylePath* = "assets/style.kdl" + iconPath* = "assets/icon.png" + svgIconPath* = "assets/icon.svg" + + iconFontPath* = "assets/forkawesome-webfont.ttf" + fonts* = [ + font("assets/ProggyVector Regular.ttf", 16f), # Other options are Roboto-Regular.ttf, Cousine-Regular.ttf or Karla-Regular.ttf + font("assets/NotoSansJP-Regular.otf", 16f, GlyphRanges.Japanese), + ] + + # AppImage + ghRepo* = (user: "Patitotective", repo: "ImTemplate").some + appstreamPath* = "" + + # Window + minSize* = (w: 200i32, h: 200i32) # < 0: don't care + diff --git a/src/types.nim b/src/types.nim index c739dc9..32b2b86 100644 --- a/src/types.nim +++ b/src/types.nim @@ -6,6 +6,10 @@ import tinydialogs import kdl, kdl/[types, utils] import constructor/defaults +import configtype + +export configtype + type SettingType* = enum stInput # Input text @@ -221,17 +225,6 @@ type numbers* = sectionSetting(display = "Spinners and sliders", content = initNumbers()) colors* = sectionSetting(display = "Color pickers", content = initColors()) - GlyphRanges* = enum - Default, ChineseFull, ChineseSimplified, Cyrillic, Japanese, Korean, Thai, Vietnamese - - Font* = object - path*: string - size*: float32 - glyphRanges*: GlyphRanges - -proc font*(path: string, size: float32, glyphRanges = GlyphRanges.Default): Font = - Font(path: path, size: size, glyphRanges: glyphRanges) - proc decodeSettingsObj*(a: KdlNode, v: var object) = # echo "decoding settings ", a for fieldName, field in v.fieldPairs: @@ -346,45 +339,7 @@ proc encodeSettingsObj(a: object): KdlDoc = proc encodeKdl*(a: Settings, v: var KdlNode, name: string) = v = initKNode(name, children = encodeSettingsObj(a)) -# var s = initSettings() -# s.input.inputVal = "Bye world >:C" -# let k = s.encodeKdlNode("settings") -# let sk = k.decodeKdl(Settings) - -# echo sk - type - Config* {.defaults: {defExported}.} = object - name* = "ImExample" - comment* = "ImExample is a simple Dear ImGui application example" - version* = "2.0.0" - website* = "https://github.com/Patitotective/ImTemplate" - authors* = [ # [name, url] - ("Patitotective", "https://github.com/Patitotective"), - ("Cristobal", "mailto:cristobalriaga@gmail.com"), - ("Omar Cornut", "https://github.com/ocornut"), - ("Beef, Yard, Rika", ""), - ("and the Nim community :]", ""), - ("Inu147", ""), - ] - categories* = "Utility" - - stylePath* = "assets/style.kdl" - iconPath* = "assets/icon.png" - svgIconPath* = "assets/icon.svg" - - iconFontPath* = "assets/forkawesome-webfont.ttf" - fonts* = [ - font("assets/ProggyVector Regular.ttf", 16f), # Other options are Roboto-Regular.ttf, Cousine-Regular.ttf or Karla-Regular.ttf - font("assets/NotoSansJP-Regular.otf", 16f, GlyphRanges.Japanese), - ] - - # AppImage - ghRepo* = ["Patitotective", "ImTemplate"] # [username, repository] - - # Window - minSize* = (w: 200i32, h: 200i32) # < 0: don't care - Prefs* {.defaults: {defExported}.} = object maximized* = false winpos* = (x: -1i32, y: -1i32) # < 0: center the window @@ -394,7 +349,7 @@ type App* = object win*: GLFWWindow config*: Config - prefs*: KdlPrefs[Prefs] # These are the values that will be saved in the config file + prefs*: KdlPrefs[Prefs] # These are the values that will be saved in the prefs file fonts*: array[Config.fonts.len, ptr ImFont] resources*: Table[string, string] @@ -403,62 +358,3 @@ type ImageData* = tuple[image: seq[byte], width, height: int] -# proc renameHook*(_: typedesc[Setting], fieldName: var string) = -# fieldName = -# case fieldName -# of "type": -# "kind" -# else: -# fieldName - -# proc enumHook*(a: string, v: var SettingType) = -# try: -# v = parseEnum[SettingType]("st" & a) -# except ValueError: -# raise newException(ValueError, &"invalid enum value {a} for {$typeof(v)}") - -# proc decodeHook*(a: KdlNode, v: var Fonts) = -# if "iconFontPath" in a.props: -# v.iconFontPath = a["iconFontPath"].getString() - -# for child in a.children: -# assert child.args.len == 2 -# v.fonts.add (child.args[0].getString(), child.args[1].get(float32)) - -# proc decodeHook*(a: KdlNode, v: var (ImVec2 or tuple[x, y: int32])) = -# assert a.args.len == 2 -# when v is ImVec2: -# v.x = a.args[0].get(float32) -# v.y = a.args[1].get(float32) -# else: -# v.x = a.args[0].get(int32) -# v.y = a.args[1].get(int32) - -# proc decodeHook*(a: KdlNode, v: var tuple[name, url: string]) = -# assert a.args.len in 1..2 -# v.name = a.args[0].getString() -# if a.args.len > 1: -# v.url = a.args[1].getString() - -# proc decodeHook*(a: KdlNode, v: var tuple[r, g, b: float32]) = -# assert a.args.len == 3 -# v.r = a.args[0].get(float32) -# v.g = a.args[1].get(float32) -# v.b = a.args[2].get(float32) - -# proc decodeHook*(a: KdlNode, v: var tuple[r, g, b, a: float32]) = -# assert a.args.len == 4 -# v.r = a.args[0].get(float32) -# v.g = a.args[1].get(float32) -# v.b = a.args[2].get(float32) -# v.a = a.args[3].get(float32) - -# proc encodeHook*(a: tuple[r, g, b: float32], v: var KdlNode, name: string) = -# v = initKNode(name, args = toKdlArgs(a.r, a.g, a.b)) - -# proc encodeHook*(a: tuple[r, g, b, a: float32], v: var KdlNode, name: string) = -# v = initKNode(name, args = toKdlArgs(a.r, a.g, a.b, a.a)) - -# proc encodeHook*(a: ImVec2 or tuple[x, y: int32], v: var KdlNode, name: string) = -# v = initKNode(name, args = toKdlArgs(a.x, a.y)) -