Make Beautiful Desktop Applications in C++
0:00
大约一年半前,我制作了一些视频,讨论用C++制作桌面应用程序的最佳方法。
So about a year and a half ago, I made a couple of videos talking about the best way to make desktop applications in C++.
0:05
这就是其中之一,这是最初的版本,基本上谈论了我认为GUI对很多人来说是一个很好的选择。
There's this one, this is the OG, basically talking about how I think I'm GUI is a really good choice for a lot of people.
0:10
但随后我进一步发展,制作了自己的应用程序框架,叫做Walnut。
But then I kind of took it a little bit further and I made my own kind of application framework called Walnut.
0:16
我想要一个干净、简洁但轻量的平台,可以用来制作C++桌面UI应用。
I wanted a nice, clean kind of, but lightweight platform that you could use to make UI apps for desktop in C++.
0:25
我真的认为这源于我们需要一个启动器,以便我们可以用Hazel分发游戏,并有一个启动器让你选择图形设置并点击播放。
And I think really this stemmed from us needing to have a launcher so that we could like distribute games with Hazel and have a launcher that like lets you pick your graphics settings and all of that and hit play.
0:34
我希望它看起来不错,几乎像Hazel的UI,但我绝对不想让它使用Hazel。
I kind of wanted it to look nice almost like Hazel's UI but I definitely didn't want it to use Hazel.
0:38
我不想让启动器依赖Hazel,因为那太疯狂了。想象一下,一个3D游戏引擎驱动你的小启动器。
I didn't want launcher to have Hazel as a dependency because that's just crazy. Imagine having a 3D game engine powering your little launcher.
0:46
我相信有些人已经这样做了。所以是的,这就是Walnut,它在github上免费提供。
I'm sure some people have done that. So yeah that's Walnut and it's just available on github for free.
0:51
除了UI方面,我还想把它构建成一个有用的C++应用程序框架,配有实用的库。
Aside from UI stuff I also wanted to kind of you know just build it into just a nice useful C++ application framework with just like a useful library.
0:59
它完全基于硬件渲染。它使用Vulkan来渲染所有图形,这使得它在图形兼容性上非常出色。
And it's all based on hardware rendering. It uses Vulkan to render all of the graphics, which makes it super graphicsy compatible.
1:05
所以如果你正在构建一个需要在GPU上渲染图形的应用程序,那么它就是一个完美的选择。
So if you're building an application that needs to render graphics on the GPU, then it's kind of a perfect fit.
1:11
但即使你不是,它仍然可以工作。它的兼容性不完全等同于不需要Vulkan图形驱动的本地应用程序。
But again, even if you're not, it still works. It doesn't quite have the same compatibility as just a native application that wouldn't require, you know, like a Vulkan graphics driver.
1:20
但对于大多数在良好系统上的人来说,它工作得很好。我认为Hazel的
But for most people on decent systems, it works fine. I think Hazel's
1:23
UI可能很好地表明了我对Walnut的目标,我基本上想要
UI is probably a good indication of my goals for walnut like i'd essentially
1:26
能够制作一个像Hazel编辑器那样的应用程序,
want to be able to make an app like hazel's editor in
1:29
最近我使用Walnut制作了一个叫Walnut Chat的应用程序,
it more recently i made an app using walnut called walnut chat
1:33
这就像一个使用Walnut的即时消息聊天应用。
it's like an instant messaging kind of chat application using walnut
1:36
网络模块,Walnut的网络模块实际上有一个
networking a networking module for walnut there's actually a
1:39
关于这个的大视频,我会把它链接在上面,C++中的网络。
big video all about that i'll leave it linked up there networking in c plus plus
1:42
无论如何,我的意思是我在Walnut上一直很顺利,
anyway basically my point is i've been kind of on a roll with walnut
1:45
我真的很享受在上面工作,并不断扩展它,添加人们请求的功能,实际上我从Hazel中提取了很多代码。
i've been really enjoying working on it and just extending it adding features that people have been requesting kind of taking a lot of the code from hazel and effectively i guess
1:54
以Walnut的形式开源,而不仅仅是UI,
open sourcing it in the form of walnut and not just UI
1:57
例如Hazel的序列化库被放入Walnut,以便我们可以使Walnut
stuff like for example Hazel's serialization library
2:00
被放入胡桃中,以便我们可以制作那个胡桃
was put into walnut so that we could make that walnut
2:03
聊天类应用程序工作,但这是最受欢迎的功能之一
chat kind of application work but one of the most requested
2:06
自胡桃一开始就存在,因为那是
features since the very beginning of walnut because that's
2:09
我展示它使用的方式,尽管它还没有正式发布
kind of how I showed it being used even though it wasn't officially released yet
2:12
自定义标题栏,所以能够制作
was custom title bars so being able to make
2:16
我展示的启动器,如何制作自定义标题栏,很多人似乎认为这又是iam GUI的一个限制,因此也许你应该使用一个真正的GUI库或其他。
that launcher that I showed you how does one make a custom title bar lots of people seem to think that again that's a limitation of iam GUI, thus maybe you should use like a real GUI library or whatever.
2:28
现在,如果你不知道自定义标题栏到底是什么,通常本地Windows应用程序看起来是这样的。
Now if you don't know exactly what a custom title bar is, usually native Windows applications look like this.
2:32
你有这种标题栏,你有最小化、最大化、关闭按钮在那边。
You have this kind of like you know title bar, you have like the minimize, maximize, close buttons over there.
2:38
这就是在这个操作系统上应用程序的本地外观和感觉,顺便说一下,在我的例子中是Windows 11。
That's kind of the native look and feel of applications on this operating system, which by the way in my examples is Windows 11.
2:45
但是很多应用程序喜欢自己掌控事情。例如,Visual Studio看起来是这样的。
But lots of applications like to take matters into their own hands. Like Visual Studio for example looks like this.
2:52
虚幻引擎也有这种自定义外观,看起来非常流畅,非常现代。真的有什么功能上的区别吗?
Unreal Engine also has this kind of custom look and it just looks really sleek, it just looks really modern. Is there any functional difference really?
2:59
实际上可能有,因为如果需要,你可以在实际的标题栏中放置更多的控件。
Well actually yeah there might be because you can position more kind of controls in your actual title bar if you need to.
3:06
例如,Microsoft Office就有整个功能区系统,保存图标等都在上面。
Microsoft Office for example has that whole kind of ribbon system and the save icon and stuff is up there.
3:11
甚至有一篇文章讨论如何实现这样的功能,因为这可能非常有用。那么你能用I Am GUI做到这一点吗?
There's an article even talking about how you can achieve stuff like that because it can be quite useful. So can you get that done with I Am GUI?
3:18
当然可以!关于I Am GUI的事情,我每次听到有人说,哦,你不能用I Am GUI做到这一点,或者哦,我没想到这是一个I Am GUI应用程序时,我都会有一种感觉。
Of course! The thing with I Am GUI that I still, like this is why I just get like I feel something every time someone says that, oh you can't do that with I Am GUI, or oh I didn't think that was an I Am GUI application.
3:29
你到底不明白什么呢,我在这里有点生气,你的窗口实际上就是一个画布。
Like what do you not understand about the fact, I'm just getting angry here, your window is literally a canvas.
3:36
像I Am GUI这样的东西,你可以控制在那种客户端区域内渲染的每一个像素。
Like with something like I Am GUI, you can control every single pixel that gets rendered within that kind of client area.
3:44
而且,最终我们使用像GLFW这样的库来实际使用Win32 API创建窗口,我们可以例如扩展客户端区域到标题栏上。
And since at the end of the day we use a library like GLFW to actually make the window using like the Win32 API, we can for example expand the client area over the title bar.
3:54
我们也可以不装饰窗口,但我更喜欢我的窗口有装饰,但我们稍后会讨论这个。关键是当然是可能的。容易吗?
We could also not decorate the window but I prefer to leave my windows decorated but we'll talk about that later. The point is of course it's possible. Is it easy?
4:01
嗯,有是有,但也不完全。我觉得有些事情可能比你想的要简单,但也有很多边缘情况让人烦恼。
Well yes and no. I feel like some things might be easier than you think but then there's all these edge cases that kind of are annoying.
4:08
但显然这是可能的。我们在Hazel中已经有了自定义标题栏好几年了。这实际上是由Jay首次引入的。
But yeah obviously it's possible. We've had a custom title bar in Hazel for like years now. This was actually first introduced by Jay.
4:14
Jay是我们的志愿音频人员,他为Hazel编写了整个音频引擎。
Jay is like our volunteer audio person who wrote the entire audio engine for Hazel.
4:20
他也非常喜欢UI,所以他花时间制作了Hazel使用的这个漂亮设计。
He also really likes UI so he took the time to actually make this beautiful design that Hazel uses.
4:24
不过,长话短说,胡桃现在也有这个自定义标题栏。
But anyway, long story short, Walnut now also has this custom title bar.
4:28
我从Hazel中借用了它,我把它做得更通用,稍微改动了一下,使其更本地化。
I've taken it from Hazel, I've kind of made it more generic, changed it a little bit so that it's a little bit more kind of native.
4:35
我们稍后会在这个视频中讨论细节。其实只需将自定义标题栏设置为true就可以了,就这样。
We'll talk about the details later in this video. It's really as simple as just setting custom title bar to true and that's it.
4:42
所以在这个视频中,我将向你展示如何使用胡桃制作一个使用这个自定义标题栏的应用程序。
So in this video, I'm going to show you how you can make an application using walnut that uses this custom title bar.
4:48
在这个视频中,我将向您展示如何使用胡桃制作一个应用程序,该应用程序使用这个自定义标题栏。
And then I'll also go through some of the code of how it actually works and what it takes to make a custom title bar using iMGUI on Windows.
4:56
如果您想下载并玩一个实际上使用这个自定义标题栏的应用程序,
And if you want to just download and play with an application that actually uses this custom title bar and just walnut in
Only the first 5 minutes are free. Install the app or extension to keep watching.
DownloadRequest another language





