FLTK logo

Re: [fltk.general] font property manipulation in FLTK label text

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: font property manipulation in FLTK label text Greg Ercolano Oct 10, 2020  
 
On 2020-10-10 10:01, Paul Hahn wrote:
> In many situations, I would like a way to change font properties for different sections of text in widget labels. Primarily, I would like to manipulate font size and weight, but color would be grea, too.
> 
> Has anyone created a custom label type supporting this? Or for example, support for (at least a limited subset of) markdown syntax?

	Might be overkill, but you could (ab)use Fl_Help_View for text labels
	so that you can use HTML tags to control this.

	Here I'm showing setting the attributes individually, but you could derive
	a class from HtmlLabel that does this stuff so it's easier to use.

____________________________________________________________________________
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Help_View.H>

int main(int argc, char **argv) {
  Fl_Window *window = new Fl_Window(340,180);
  Fl_Help_View *label1 = new Fl_Help_View(10,10,200,30);

  label1->color(label1->parent()->color());
  label1->box(FL_FLAT_BOX);
  label1->value("Test <font color=#f00>red</font> <font color=#0f0>green </font><font color=#00f>blue</font>");
  label1->child(0)->hide();	// XXX: hacky way to hide private scrollbar

  Fl_Help_View *label2 = new Fl_Help_View(10,40,200,30);
  label2->color(label2->parent()->color());
  label2->box(FL_FLAT_BOX);
  label2->value("Test <b>bold </b><i>italic</i> normal.");
  label2->child(0)->hide();	// XXX: hacky way to hide private scrollbar

  window->end();
  window->show(argc, argv);
  return Fl::run();
}
____________________________________________________________________________

CAVEATS

    BOX TYPE
    --------
	Seems Fl_Help_View won't let me set the box() type to FL_NO_BOX,
	so I had to use FL_FLAT_BOX to hide the borders, which means the
	bgcolor has to match the parent widget, which is why I had to use parent()->color()
	to make the label "seamless".

        The reason for this apparent requirement is probably because text can have
	different bgcolors.

    SCROLLBARS
    ----------
	Sucks that there isn't a clean way to access the scrollbars through the API
	to disable them (see XXX markers above), as they come on unconditionally.

	Had to hack disabling the vertical scrollbar by using child(0).

	The Fl_Help_View class should really allow access to the internal scrollbars,
	either as public methods that return pointers (other widgets do this),
	or at least make them protected so derived classes can access and manipulate them.

	Maybe this can be done for 1.4 .. dev vote?

-- 
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/75313779-f72b-c3c1-a9c1-5a1228a0a68f%40seriss.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.