webui-dev / nim-webui

Use any web browser as GUI, with Nim in the backend and HTML5 in the frontend.
https://webui.me
MIT License
130 stars 9 forks source link

text_editor.nim says undeclared field: 'rootFolder=' #20

Closed retsyo closed 1 year ago

retsyo commented 1 year ago

I am using nim in MSYS2+MINGW64 on windows 10 64 bits. I installed webui via nimble install webui

$ nim --version
Nim Compiler Version 1.9.3 [Windows: amd64]
Compiled at 2023-06-16
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 77beb152141f0efe4d5c93b784e42f973ba46551
active boot switches: -d:release

I can compile when I try and run nim-webui-main\examples\hello_world.nim without problem. But for nim-webui-main\examples\text_editor\src\text_editor.nim, I get

C:\tmp\candel\src\text_editor.nim(43, 21) Error: undeclared field: 'rootFolder=' for type we
bui.Window [type declared in C:\Users\USER\.nimble\pkgs2\webui-2.3.0.1-4945446001c8ab19a5f
9fbcbf1d771b9da4a324e\webui.nim(13, 3)]
AlbertShown commented 1 year ago

rootFolder() is a function declared here, and the last modification commit is here.

@neroist, any idea?

AlbertShown commented 1 year ago

@retsyo Just to confirm, by using hello_world.nim, can you compile and show the window just fine?

neroist commented 1 year ago

rootFolder() is a function declared here, and the last modification commit is here.

@neroist, any idea?

Nope. I'm working on something else but I'll test the examples using Nim 1.9 soon.

neroist commented 1 year ago

I am using nim in MSYS2+MINGW64 on windows 10 64 bits. I installed webui via nimble install webui

$ nim --version
Nim Compiler Version 1.9.3 [Windows: amd64]
Compiled at 2023-06-16
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 77beb152141f0efe4d5c93b784e42f973ba46551
active boot switches: -d:release

I can compile when I try and run nim-webui-main\examples\hello_world.nim without problem. But for nim-webui-main\examples\text_editor\src\text_editor.nim, I get

C:\tmp\candel\src\text_editor.nim(43, 21) Error: undeclared field: 'rootFolder=' for type we
bui.Window [type declared in C:\Users\USER\.nimble\pkgs2\webui-2.3.0.1-4945446001c8ab19a5f
9fbcbf1d771b9da4a324e\webui.nim(13, 3)]

Weird, using 1.9.5 text_editor compiles and runs fine. Does your webui.nim define (and export) the rootFolder= proc?

AlbertShown commented 1 year ago

Probably the Nim WebUI package does not have the latest commit?

neroist commented 1 year ago

Oh, yeah you're right it doesn't 😅. I'll also put a note that the examples use the HEAD of the gh repo, not the most recent release.

AlbertShown commented 1 year ago

Excellent! Thank you, @neroist for the quick fix 👍

Please, @retsyo, re-test using the latest Nim-WebUI package and let us know if it gets fixed.

retsyo commented 1 year ago

now text_editor.nim can be compiled to run without problem.

but one more thing, ctrl+s open a dialog to save as html file. Can we bind ctrl+s to the following code?

  window.bind("Save") do (e: Event):
    writeFile(filePath, e.data)
neroist commented 1 year ago

@retsyo

You'd probably have to do something with JavaScript code to bind webui_fn('Save') to ctrl+s. Maybe something like this:

document.addEventListener('keydown', e => {
  if (e.ctrlKey && e.key === 's') {
    e.preventDefault();
    webui_fn('Save')
  }
});

Unfortunately, you can't do this purely using the Nim wrapper, though it would be cool.

AlbertShown commented 1 year ago

Yes, you can do it in the UI using JavaScript as @neroist mentioned 👍