GTK+ -- from knowing nothing to knowing something (3)
来源:互联网 发布:淘宝和京东用户人群 编辑:程序博客网 时间:2024/05/23 00:00
About layout
We usually have more than just one widget on out interface, so using gtk_container_add() to pack into the window is obviously not sufficient (the function may only be called once for a window). In this case, layout containers should be used. There are a few such containers, the three ones that I used most are box, table and fixed.
Let's do a little comparison:
- GtkBox - easy to use (just need to call a simple function gtk_box_pack_start or gtk_box_pack_end to pack the widgets into it), automatically resizable (that is, when you maximize or resize the window, it resizes accordingly), but not convenient when some widgets should be larger or smaller than others. Therefore better used on a series of widgets that share the same size.
- GtkTable - a little bit more difficult than box (when packing, shoud specify the column and row where the widget starts and the number of column and row that widget extends to), but this also create the possibility to control how large a widget should be (for example, taking up only one "block" or four "block" of the table). Also, widgets inside table are also auto-resizable. But still, unless you define a table with MANY columns and rows, it's still not easy to pack the widget like exactly what you want.
- GtkFixed - even more difficult to use if you decide to write it manually, for it requires the x, y coordinators of the top-left corner of the widget to be set. However, if you are using something with WYSWYG function (such as Glade), it won't be a problem anymore. After that, the size of the widget may be set using gtk_widget_set_size_request (). In this way, the widget will be pack exactly on the position where you want it to be and with the size you set. In addition, one function of GtkFixed, gtk_fixed_move is also interesting. With this function, you may change the position of your widget dynamically (ex. a button clicked, the widget will move to a new place). There is only one thing - widgets inside GtkFixed are not auto-resizable. If using on widows that do not need to be resized, it would be fine, but when you resize a windwo using it, you can image the ugly look of your interface. Although there may be some ways to "cause" the widgets resize accordingly (ex. catch the resize event of the window, set the size and position of every widget accordingly), they are usually troublesome and inconvenient. At least I don't know an easy way to do it, if you have a solution, comments are warmly welcome and thanks in advance.
After understanding the layout related issues, we may start to write our own interface while getting ourselves familiar to various widgets. But don't forget a few references are always helpful on our way. Let me list a few here.
Useful Resources
- www.gtk.org - the official website, you can't miss it. Tutorial section has an easy-to-follow guide, with sample code, though some of the functions used are outdated. Therefore you should always check the api reference for newest stable version or the version you are coding with. The api reference has some sample code as well, though they are very limited. And remember, the hiararchy of the widgets is also something you want to check frequently, because many functions you want to use may appear on the widget's parent and parent's parent.
- http://scentric.net/tutorial/ - Gtk+ 2.0 Tree View Tutorial. A tutorial on treeview, a very powerful but very complicated widget in GTK.
- http://203.64.187.41/gtk/GTK-Index.html - a tutorial written in Traditional Chinese, with sample code that may be newer than the tutorial on the official website
While some widgets are a bit more trickier than others, I will discuss them more in the upcoming posts from a witness also new leaner's perspective.
- GTK+ -- from knowing nothing to knowing something (3)
- GTK+ -- from knowing nothing to knowing something (1)
- GTK+ -- from knowing nothing to knowing something (2)
- GTK+ -- from knowing nothing to knowing something (4)
- GTK+ -- from knowing nothing to knowing something (5)
- knowing
- Knowing yourself -- From Beyond Feeling
- Knowing MTD
- Knowing+NTLM
- Knowing Your Team
- Knowing makefile in linux
- Methods, Not Methodology (3): Knowing Everything at the Beginning?
- How to reset windows local user passwd, without knowing its current passwd
- <Effective Mordern C++>笔记:Item 4:Knowing how to view deduced types .
- Goodbye Forefront, it was nice knowing you
- 9 uses for cURL worth knowing
- 神的启示(一):Knowing John
- Creating something from nothing [Developer-friendly virtual file implementation for .NET!]
- mysql存储过程学习总结
- 快速应用JDBC控件访问数据库资源
- Ajax使用XML异步加载数据
- 求多段线的长度
- 从原理上解决Tomcat中文问题
- GTK+ -- from knowing nothing to knowing something (3)
- TOMCAT用https替换http的方法
- JSP中基于Session的在线用户统计分析
- 随即抽奖
- C# rijndae算法实现不标准?!
- Qiang 烈建议您不要创建以 sp_ 为前缀的存储过程
- CSS 库 2007-06-30 06:55
- Windows API一日一练(3)使用命令行参数
- 第三部分 类型设计-----《Microsoft.NET框架程序设计》