简体   繁体   English

HTML + JavaScript GUI建议

[英]HTML+JavaScript GUI Advice

I'm working on a music editor/sequencer app that will be written in JavaScript+HTML5 and will make use of the canvas element and Chrome's Web Audio API (I already have a simple prototype working ). 我正在开发一个用JavaScript + HTML5编写的音乐编辑器/音序器应用程序,它将使用canvas元素和Chrome的Web Audio API(我已经有一个简单的原型工作 )。

One of the things I'm not so sure about is how to implement the GUI for this. 我不太确定的一件事是如何为此实现GUI。 It will need to have many different views, and I'd like to perhaps have each view in a different clickable "tab", with one tab in the foreground at a given time and all the others hidden. 它需要有许多不同的视图,我想将每个视图放在一个不同的可点击“选项卡”中,在给定时间前景中有一个选项卡,其他所有隐藏。 I'm just not sure how to go about implementing all these tabs. 我只是不确定如何实现所有这些选项卡。

Would it be better to implement each tab as a different HTML layer and have buttons control which layer shows up on top? 将每个标签实现为不同的HTML图层并使用按钮控制哪个图层显示在顶部会更好吗? Would it be better instead to (re)generate HTML on the fly when the tab buttons are pressed? 当按下标签按钮时,是否更好地(重新)生成HTML?

Your advice is appreciated. 您的建议表示赞赏。

Would it be better to implement each tab as a different HTML layer and have buttons control which layer shows up on top? 将每个标签实现为不同的HTML图层并使用按钮控制哪个图层显示在顶部会更好吗? Would it be better instead to (re)generate HTML on the fly when the tab buttons are pressed? 当按下标签按钮时,是否更好地(重新)生成HTML?

I would lean towards generating the content once and showing/hiding it on demand especially if the majority of work is done in the browser and there are no synchronous requests being made to a server when interacting with elements on the page. 我倾向于生成一次内容并按需显示/隐藏它,特别是如果大多数工作是在浏览器中完成的,并且在与页面上的元素交互时没有向服务器发出同步请求。 See footnote 1 见脚注1

When showing a tab's contents... 显示标签的内容时...
Assuming the content of each tab generates quickly, you can make your application more efficient by only creating the content for the tab when it is requested the first time. 假设每个选项卡的内容生成速度很快,只需在第一次请求时为选项卡创建内容,就可以提高应用程序的效率。 This way, if the tab is never accessed no resources are used. 这样,如果从不访问该选项卡,则不使用任何资源。

When hiding a tab's contents... 隐藏标签的内容时......
When working with multimedia you may need to perform additional actions when you hide content. 使用多媒体时,您可能需要在隐藏内容时执行其他操作。 For example, a video won't stop playing just because you hide it. 例如,视频不会因为您隐藏而停止播放。 For your audio application you may need to stop playback of the current sequence. 对于音频应用程序,您可能需要停止播放当前序列。

There are many tab controls available such as jQuery UI tabs (free) and Sliding Tabs (licensed but inexpensive). 有许多选项卡控件可用,例如jQuery UI选项卡 (免费)和滑动选项卡 (许可但价格便宜)。

Other Scenarios 其他情景
Tabs should be used for switching between major blocks of content like documents (eg browser tabs) and/or regularly used functionality (eg a personnel form which has a tab for contact information and another for employment history). 标签应该用于在主要内容块之间切换,例如文档(例如浏览器标签)和/或常规使用的功能(例如,具有用于联系信息的标签和用于雇用历史的另一个标签的人员表格)。 Other scenarios may be better suited to a dialog (modal or non-modal). 其他场景可能更适合对话(模态或非模态)。

Using the audio example, if you had a button labeled "tempo", I would expect it to open a small dialog window on top of my current view rather than taking me to a new tab. 使用音频示例,如果你有一个标有“tempo”的按钮,我希望它在我当前视图的顶部打开一个小对话窗口,而不是带我到一个新标签。 Roland's workstation keyboards use this paradigm. Roland的工作站键盘使用这种模式。 Major content replaces the current view, but settings/configuration windows usually popup atop the existing view. 主要内容替换当前视图,但设置/配置窗口通常会弹出现有视图的顶部。

jQuery UI also has a dialog plugin for this purpose. jQuery UI还有一个用于此目的的对话框插件。 If you are JavaScript savvy and targeting newer browsers, it's not that hard to write your own simple dialog. 如果您精通JavaScript并针对较新的浏览器,那么编写自己的简单对话框并不困难。


1 Generating content on the fly may still be perfectly acceptable with an interactive client-server relationship, but it introduces additional considerations, such as the synchronization of what is in the browser with the data model on the server (if any), the submission of unneeded form fields (increasing the size of the request), overall page size, etc. 1动态生成内容仍然可以通过交互式客户端 - 服务器关系完全接受,但它引入了其他注意事项,例如浏览器中的内容与服务器上的数据模型(如果有)的同步,提交不需要的表单字段(增加请求的大小),整体页面大小等。

I would suggest checking out the JQuery UI library. 我建议查看JQuery UI库。 More specifically, the tabs functionality that it provides, http://jqueryui.com/demos/tabs/ . 更具体地说,它提供的选项卡功能, http://jqueryui.com/demos/tabs/

Simple rule of thumb for loading data into your tabs. 将数据加载到选项卡中的简单经验法则。 Small and Simple , load it up front. 小而简单 ,预先加载它。 Large and Complex , load it on demand. 大而复杂 ,按需加载。 When in doubt , load it on demand. 如有疑问 ,请按需加载。

if you're looking for a complex UI, I recommend you check out Dojo or Ext JS . 如果您正在寻找复杂的UI,我建议您查看DojoExt JS They both provide you with a UI framework closer to Java's Swing framework. 它们都为您提供了更接近Java Swing框架的UI框架。

However, if you're looking for tabs, and tabs only, jQuery UI is great. 但是,如果您只查找选项卡和选项卡, jQuery UI非常棒。

If you're working on a canvas, do your GUI on your canvas. 如果您正在使用画布,请在画布上执行GUI。 Seriously. 认真。 Using divs in front of a canvas is just boring. 在画布前使用div很无聊。 I tried both, and I prefer using canvas. 我试过两个,我更喜欢使用帆布。

The easiest way is to create a "button" class which will take an image and define a clickable zone on your canvas for this image (if you want pixel-detect there is a way which uses offscreen canvas and getpixel to check colors under the mouse and stuff, too long to explain here). 最简单的方法是创建一个“按钮”类,它将拍摄图像并在画布上为此图像定义可点击区域(如果您想要像素检测,有一种方法可以使用屏幕外画布和getpixel来检查鼠标下的颜色和东西,这里解释太长了)。

Then once you have your button or whatever gui class, you can put them on your canvas and you won't have to manage multiple html elements. 然后,一旦你有你的按钮或任何gui类,你可以将它们放在画布上,你不必管理多个html元素。 Also, some html elements in front of a canvas often have weird behaviours. 此外,画布前面的一些html元素通常具有奇怪的行为。 That's why I prefer creating my gui directly on the canvas. 这就是为什么我更喜欢直接在画布上创建我的gui。 Harder at the beginning but proper. 在开始时更难但正确。

Of and please, make it possible to place multiple squares without having to reclick (just use a mouseDown variable) 并且请,可以放置多个正方形而不必重新点击(只需使用mouseDown变量)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM