Closed kcvinker closed 5 years ago
As part of the Standard Library, no, at least not yet. In the meantime, you can import your favorite C Gui library for use in Zig.
Thanks for the reply. Oh, then i think i can use win API functions like CreateWindowEx in Zig. Can i get any guidance on that topic ?
You're welcome.
Maybe this may get you started in terms of the basic structure.
const windows_api = @import("std").os.windows;
usingnamespace windows_api;
extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCSTSTR, uType: UINT) c_int;
export fn WinMain(hInstance: HINSTANCE, hPrevInstace: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) INT {
MessageBoxA(null, c"Hello", c"title", 0);
}
@JesseRMeyer, I just copied this code and compiled in vs code. But the error message says that """ invalid carriage return, only '\n' line endings are supported const windows_api = @import("std").os.windows; "" ^
@vinodvinu Have you had a look at the documentation? https://ziglang.org/documentation/0.5.0/
@dimenus Thanks for the reply. Actually no. I thought it is good to spend time on reading the documentation only if this sample code works perfectly. Sorry for that. I don't expect the line ending character problem.
@dimenus Thanks for the reply. Actually no. I thought it is good to spend time on reading the documentation only if this sample code works perfectly. Sorry for that. I don't expect the line ending character problem.
tl;dr: Zig intentionally only supports Unix line endings meaning \n
(line feed). Windows uses \r\n
(carriage return, line feed). in vscode, in the bottom right you'll see LF
or CRLF.
Switch to LF
for your zig project.
You should also set up vscode to use spaces instead of hard tabs (\t
) as the latter are not supported in Zig.
Okay, but what if i want to code in Go, D & Nim on the other day ? Do i need to change the line ending setup then ? Or is there any pre-fixed line ending setup for individual languages ?
@vinodvinu most (probably all) languages support unix line endings.
Probably those languages are not intended for windows OS.
My question was, do i need to change the line ending style when i use other languages.
https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=85b883ea-a45c-4762-9f04-138824e0fff0 I’m protected online with Avast Free Antivirus. Get it here — it’s free forever. https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=85b883ea-a45c-4762-9f04-138824e0fff0 <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
On Wed, 6 Nov 2019 at 03:46, Andrew Kelley notifications@github.com wrote:
What if you want to type D, Go, & Nim into your zig code? You can't. They are different languages. You will have to use the D, Go, and Nim compilers to compile D, Go, and Nim code.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ziglang/zig/issues/3590?email_source=notifications&email_token=ACDONS5HX4HOSHJFVL7JQHLQSHWE5A5CNFSM4JIX36O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDEQ7WI#issuecomment-550047705, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDONS3DHD2E67G4IHTEQ5TQSHWE5ANCNFSM4JIX36OQ .
in most cases no,unless the language you are using is white space sensitive and sensitive to the type of white space that you are using, i.e. Makefiles. as for line endings, Zig is the only language that i can think of that enforces Unix line endings, so in most (if not all) cases you should be fine.
Maybe this may get you started~
I was hoping/expecting an example with a single window and its event loop responding to a click on a button gadget? MessageBox() is far short of a gui.
You can probably use e.g. SDL / Sokol / ImGUI / etc via @cImport
May be that https://github.com/andlabs/libui can be used for this.
Slint may be an interesting UI lib for ziglang https://github.com/slint-ui/slint Ping @tronical @ogoffart
I've been following ziglang with great interest. In principle this should be possible, but it's a bit of work.
We have a run-time library that's written in Rust but that has a low-level C FFI. It's not designed to be a nice C API, but rather a tool to implement nicer C++ API on top. We use cbindgen to generate that and it has some C++ sprinkled in it.
We also have a DSL for the UI and generate Rust or C++ code. A ziglang generator is technically doable though, we've designed our compiler to support multiple languages.
So either one implements a nice C API for Slint and it's used with ziglang via @cImport
, or goes straight for for ziglang.
I wonder though how to break this into smaller pieces. One way would be to focus on the run-time library C/zig support first, skip the DSL to Zig/C compilation step and instead have bindings for our run-time interpreter. We have those also for C++ and a C/Zig binding is a smaller API surface probably.
Currently the most viable solution is this project: https://github.com/capy-ui/capy
I've been working on a minimal solution to support QML with ziglang. However, it needs to be reworked for the best possible support (no warranty).
Not being perhaps too different from slint-ui (ffi) @tronical
When it comes to rust, I didn't finalize my PR to cbindgen either, allowing (rust -> zig) in which I will have to review the ty coupling when inserting comptime and distinguish anyopaque
and callconv(.C) void
support.
Hi, Is there any Gui library for Zig ? Especially for Windows, but cross platform is ok.