Re: changing a widget's color at runtime
- From: Patrick Schweiger <pks timing com>
- To: gtk-list gnome org
- Subject: Re: changing a widget's color at runtime
- Date: Mon, 13 Nov 2000 16:29:51 -0700
Paul Barton-Davis wrote:
> gtkmm-main lists sourceforge net
thank you for mailing list name.
>
> but this is a GTK level question, even if the code itself is Gtk--.
>
> >void some_cute_class_name::set_status_lbl_color(const Gdk_Color &color) {
> >
> > /* ugly code here */
> >
> Repeating myself again: please don't do this. Use
>
> status_lbl1->set_name ("StatusLabel");
> status_lbl2->set_name ("StatusLabel");
>
> and then load a GTK RC file with:
>
> style "status_label" {
> fg[NORMAL] = { 0.93, 0.94, 0.23 }
> }
> widget "*StatusLabel" style "status_label"
I've read similar advice (might have been yours for all I know) in previous
messages on this list. I am using a massive GTK rc to set color preferences
for components with "static" color. The reason I resorted to this ugly code
is because I want to change the color at run time ... imagine a status
label that goes shows an application going through different states
const lbl_config_rec lbl_configs[] = {
{ "Stopped", orange_color },
{ "Ready", another_color },
{ "Starting", green_color },
{ "Calibrating", green_color },
{ "Collecting", white_color },
{ "Interrupted", red_color },
};
that is status_lbl_1 and status_lbl_2 could be green now, red in two
seconds and another color three seconds from then.
using resource files, the only way I see to accomplish something like this
would be to create 12 labels, set_naming() each set of two, then hiding the
set that's currently visible, and showing the set that reflects the
application's new state ... this can certainly be done ... but I would
argue that this paradigm isn't much prettier (if at all).
If you find there is a "cleaner" way to accomplish something like this
using RC files I would love to hear from you again - maybe I'm just not
seeing the light ;)
> this allows and your users to change the colors at run time without
> any recompilation. as a side effect, it also removes a bunch of ugly
> code from your app :)
>
> --p
I appreciate your response! I'll subscribe to the list you recommend when I
get done clicking the send button!
Patrick
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]