Results 1 to 7 of 7

Thread: Vala: TextView background/foreground colors

  1. #1
    Join Date
    Apr 2008
    Beans
    320
    Distro
    Xubuntu 17.10 Artful Aardvark

    Vala: TextView background/foreground colors

    In Vala, using a GTK GUI, how do I change the background and foreground colors of a TextView widget without using a color chooser?

    It would be nice if I could just put in a hexadecimal value or something.

    I tried this, but it didn't seem to work:
    Code:
    var mybgcolor=Gdk.Color();
    mybgcolor.red=0;
    mybgcolor.blue=0;
    mybgcolor.green=0;
    this.text_view = new TextView();
    this.text_view.modify_bg(Gtk.StateType.NORMAL, mybgcolor);
    Also, if you can give similar help on how to set the font, let me know.

    It's easy enough to do these things with WxPython (in Python), however, but Python won't suffice well for what I'm making. It'd be nice if they had WxWidgets for Vala.
    Last edited by kumoshk; November 21st, 2009 at 05:45 AM.

  2. #2
    Join Date
    Dec 2007
    Location
    .
    Beans
    Hidden!
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Vala: TextView background/foreground colors


  3. #3
    Join Date
    Apr 2008
    Beans
    320
    Distro
    Xubuntu 17.10 Artful Aardvark

    Re: Vala: TextView background/foreground colors

    Quote Originally Posted by days_of_ruin View Post
    Hmm. It seems that no matter what color I put in with this method, it always turns out black. It's better than white, but, I like options. Any advice?

    Here's the code I used:
    Code:
    var mybgcolor=Gdk.Color();
    mybgcolor.red=0;
    mybgcolor.blue=255;
    mybgcolor.green=0;        
    this.text_view.modify_base(Gtk.StateType.NORMAL, mybgcolor);

  4. #4
    Join Date
    Apr 2008
    Beans
    320
    Distro
    Xubuntu 17.10 Artful Aardvark

    Re: Vala: TextView background/foreground colors

    I must be setting the color incorrectly, or something. Any ideas on how to set it without a color chooser dialog? I can see ways to do it with one.

  5. #5
    Join Date
    Apr 2008
    Beans
    320
    Distro
    Xubuntu 17.10 Artful Aardvark

    Re: Vala: TextView background/foreground colors

    Quote Originally Posted by kumoshk View Post
    I must be setting the color incorrectly, or something. Any ideas on how to set it without a color chooser dialog? I can see ways to do it with one.
    I see my problem. The types for red, blue and green aren't supposed to be between 0 and 255, but rather between 0 and 65535. The type is a struct called uint16.

    Hmm. This is kind of wild. Any idea how to do 6-digit hexadecimal input? e.g. #35F3EA

    I've tried doing this through parse, but that seems to require a colormap or something, and that seems to require alloc_color to be initialized, but it won't initialize.
    Last edited by kumoshk; November 21st, 2009 at 07:30 AM.

  6. #6
    Join Date
    Apr 2008
    Beans
    320
    Distro
    Xubuntu 17.10 Artful Aardvark

    Re: Vala: TextView background/foreground colors

    Quote Originally Posted by kumoshk View Post
    Any idea how to do 6-digit hexadecimal input? e.g. #35F3EA
    Hooray! I've found out how to do this:

    Code:
    Gdk.Color.parse("#FFFFFF", out mybgcolor);
    The whole out thing threw me off (still not used to that), otherwise I would have figured this out sooner, probably.

    It doesn't work if I do the non-hex method before this in the same code, however. But, multiple calls of this seem to work fine. I'm guessing it's because they use different ranges of numbers.

    Thanks for all the help!

    If anyone's curious, modify_text works like modify_base for the font color.

    Now I need to figure out how to set fonts.
    Last edited by kumoshk; November 21st, 2009 at 08:10 AM.

  7. #7
    Join Date
    Apr 2008
    Beans
    320
    Distro
    Xubuntu 17.10 Artful Aardvark

    Re: Vala: TextView background/foreground colors

    Quote Originally Posted by kumoshk View Post
    Now I need to figure out how to set fonts.
    Here's an example of how:
    Code:
    var docfont=new Pango.FontDescription();
    docfont.set_family("Gentium");
    docfont.set_size(18000);
    this.text_view.modify_font(docfont);

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •