开发者

What are some good ways of managing settings in gui applications?

开发者 https://www.devze.com 2022-12-17 11:49 出处:网络
If I have a setting that is accessible via a menu item or configuration window that can change at runtime, for example \"bold text on/off\"; what are some good ways of ensuring that all applicable com

If I have a setting that is accessible via a menu item or configuration window that can change at runtime, for example "bold text on/off"; what are some good ways of ensuring that all applicable components a开发者_运维百科re aware the value of this setting?


You didn't provide specifics of an implementation language, so the asnwer will be somewhat generic. Assuming your GUI is in a language which supports even model (e.g. Java), simply have an event handler for any component which should be affected by settings and which gets triggered on an event "setting changed". Then call such event from the setting config window. Don't forget to redraw when all components are done updating (ore redraw as each component is updated).

An additional point is to hopefully have generic sub-components used. As an example, if you are using label text with a certain font which is configurable, then use a common "label with configurable font" class which ensures you never need to assign the above event listener to every label you create.


If there will be a lot of setting I have implemented a sqlite DB to hold the changes for smaller amount of changes key value pair in a file is good enough. Then implement a observer design pattern so when any changes are done a list of gui classes are called to do the change.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号