开发GUI库的文章

时间:2021-05-23 21:03:56

Basically, I'm unable to find any good articles for developing your own GUI, that deal with good practices, the basic structure, event bubbling, tips and avoiding all the usual pitfalls. I'm specifically not interested on how to build some proof-of-concept GUI in 5 minutes that just barely works... nor am I interested in building the next future GUI.

基本上,我找不到任何开发您自己的GUI的好文章,这些文章涉及好的实践、基本结构、事件冒泡、提示和避免所有常见的陷阱。我特别不关心如何在5分钟内构建一些概念验证GUI,而这些GUI几乎不能工作……我也不想构建下一个未来的GUI。

The purpose is to build a reasonably capable GUI to be used for tools for a game, however they will exist within the game itself so I don't want to use existing large scale GUIs, and I find most game GUIs to be rather bloated for what I need. And I enjoy the experience of doing it myself.

它的目的是建立一个相当有能力的图形用户界面,用于游戏的工具,但是它们会在游戏本身中存在,所以我不想使用现有的大型GUI,而且我发现大多数游戏GUI对于我所需要的东西来说是相当臃肿的。我喜欢自己做这件事的经历。

I have done a GUI in the past which worked very well to a point, however, due to some bad design decisions and inexperience it could only do so much (and was built in Flash so it got a lot of stuff for free). So I would like to really understand the basics this time.

我以前做过一个GUI,它在某种程度上运行得非常好,但是,由于一些糟糕的设计决策和缺乏经验,它只能做这么多(并且是在Flash中构建的,所以它得到了很多免费的东西)。所以这次我想要真正理解这些基础知识。

2 个解决方案

#1


1  

A few tips -

一些小技巧,

1) Pick your style the UI will work - will it be stateless? If yes, how are you going to handle the events appropriately? In case it'll be stateless, you'll maybe have to re-evaluate your UI user code twice in order to get up to date event changes from user side. If your UIs store state, then you won't have to care about handling events, but it'll limit your UIs when it comes to rapid mutations and rebuilds.

1)选择你的样式UI将会工作——它是无状态的吗?如果是,您将如何适当地处理这些事件?如果它是无状态的,您可能需要重新评估您的UI用户代码两次,以便从用户端获得最新的事件更改。如果您的ui存储状态,那么您就不必关心处理事件,但是当涉及到快速突变和重新构建时,它将限制您的ui。

2) Do not rely on the OO too much, virtual methods are not the fastest thing in the world so use them with care; having some sort of inheritance based structure might help though. Beware of dynamic_cast and RTTI if you use objects; they will slow you down. Instead, set up an enum, get_type() method for every widget class, and do manual checks for castability.

2)不要过分依赖OO,虚拟方法不是世界上最快的东西,所以要小心使用;不过,拥有某种基于继承的结构可能会有所帮助。如果使用对象,请小心dynamic_cast和RTTI;他们会让你慢下来。相反,为每个小部件类设置一个enum, get_type()方法,并对castability进行手工检查。

3) Try to separate the looks and the UI logic/layout.

3)尽量将外观和UI逻辑和布局分开。

4) If you want dynamic windows, layouts etc. then you'll have to handle aligning, clamping, positions etc. and their updates. If you want just statically positioned widgets, it'll make it much easier.

4)如果你想要动态窗口、布局等等,那么你就必须处理对齐、夹紧、位置等,以及它们的更新。如果您想要静态定位的小部件,它将使它更容易。

5) Do not overdesign, you won't benefit from that.

不要设计过度,你不会从中受益。

There is not really anything too specific I tell you; having some concrete question would help, maybe?

我没有什么特别的东西告诉你;也许问一些具体的问题会有帮助?

#2


0  

Take a look at the docs for existing GUI libraries. That should give you details on proven designs to handle the issues you've run into.

看一下现有GUI库的文档。这将为您提供有关经过验证的设计的详细信息,以处理您遇到的问题。

You might want to start with one you're familiar with, but one that I think is designed quite well is AppKit. Its API is Obj-C so it would require some adjustment if you wanted to copy it, but the docs give all kinds of details about how objects interact to, e.g. handle events, and how layout constraints work, which should be directly applicable to designing an OO GUI in most any language.

您可能想从您熟悉的一个开始,但我认为设计得相当不错的是AppKit。其API是Obj-C所以需要一些调整如果你想复制它,但是医生给各种各样的对象如何交互的细节,如处理事件,和布局约束是如何工作的,应直接适用于大多数任何语言设计一个面向对象的GUI。

#1


1  

A few tips -

一些小技巧,

1) Pick your style the UI will work - will it be stateless? If yes, how are you going to handle the events appropriately? In case it'll be stateless, you'll maybe have to re-evaluate your UI user code twice in order to get up to date event changes from user side. If your UIs store state, then you won't have to care about handling events, but it'll limit your UIs when it comes to rapid mutations and rebuilds.

1)选择你的样式UI将会工作——它是无状态的吗?如果是,您将如何适当地处理这些事件?如果它是无状态的,您可能需要重新评估您的UI用户代码两次,以便从用户端获得最新的事件更改。如果您的ui存储状态,那么您就不必关心处理事件,但是当涉及到快速突变和重新构建时,它将限制您的ui。

2) Do not rely on the OO too much, virtual methods are not the fastest thing in the world so use them with care; having some sort of inheritance based structure might help though. Beware of dynamic_cast and RTTI if you use objects; they will slow you down. Instead, set up an enum, get_type() method for every widget class, and do manual checks for castability.

2)不要过分依赖OO,虚拟方法不是世界上最快的东西,所以要小心使用;不过,拥有某种基于继承的结构可能会有所帮助。如果使用对象,请小心dynamic_cast和RTTI;他们会让你慢下来。相反,为每个小部件类设置一个enum, get_type()方法,并对castability进行手工检查。

3) Try to separate the looks and the UI logic/layout.

3)尽量将外观和UI逻辑和布局分开。

4) If you want dynamic windows, layouts etc. then you'll have to handle aligning, clamping, positions etc. and their updates. If you want just statically positioned widgets, it'll make it much easier.

4)如果你想要动态窗口、布局等等,那么你就必须处理对齐、夹紧、位置等,以及它们的更新。如果您想要静态定位的小部件,它将使它更容易。

5) Do not overdesign, you won't benefit from that.

不要设计过度,你不会从中受益。

There is not really anything too specific I tell you; having some concrete question would help, maybe?

我没有什么特别的东西告诉你;也许问一些具体的问题会有帮助?

#2


0  

Take a look at the docs for existing GUI libraries. That should give you details on proven designs to handle the issues you've run into.

看一下现有GUI库的文档。这将为您提供有关经过验证的设计的详细信息,以处理您遇到的问题。

You might want to start with one you're familiar with, but one that I think is designed quite well is AppKit. Its API is Obj-C so it would require some adjustment if you wanted to copy it, but the docs give all kinds of details about how objects interact to, e.g. handle events, and how layout constraints work, which should be directly applicable to designing an OO GUI in most any language.

您可能想从您熟悉的一个开始,但我认为设计得相当不错的是AppKit。其API是Obj-C所以需要一些调整如果你想复制它,但是医生给各种各样的对象如何交互的细节,如处理事件,和布局约束是如何工作的,应直接适用于大多数任何语言设计一个面向对象的GUI。