Fl_Browser - how to properly scale icon to the row size?

24 views
Skip to first unread message

Dibo

unread,
Jul 23, 2026, 1:26:16 PM (3 days ago) Jul 23
to fltk.general
Hi,
I'm using CFLTK (actualy, PasFLTK binding). For icons in Fl_Browser I'm using SVG icons which by default are huge. I want to resize icon to the row size using Fl_SVG_Image_scale but I don't know how to get row size in pixels. Fl_Browser_text_size return font size, not pixels. And fl_height is working only in drawing context.
Regards

Dibo

unread,
Jul 23, 2026, 1:52:13 PM (3 days ago) Jul 23
to fltk.general
I have tried this code:

var
  win: Pointer;
  w, h: LongInt;
begin
  w := 0;
  h := 0;
  win := Fl_Widget_window(FWidgetHandle);
  if win<>nil then
  begin
    Fl_Window_make_current(win);
    Fl_set_font(0, 14);
    Fl_measure(PChar('Ag'), @x, @h, 0);
  end;

When first call then h=0 (even if win<>nil) but another calls result with correct h=20. Don't know why. The same when I use fl_height instead of Fl_measure

Greg Ercolano

unread,
Jul 23, 2026, 4:54:16 PM (3 days ago) Jul 23
to fltkg...@googlegroups.com

On 7/23/26 10:52, Dibo wrote:

I have tried this code:

[..non-c++ code snipped..]

When first call then h=0 (even if win<>nil) but another calls result with correct h=20. Don't know why. The same when I use fl_height instead of Fl_measure

    Not sure, but I think the font functions (on some platforms if not all) might not work until the window is actually mapped to the screen.
    So to get reliable results, you may have to do that kind of stuff after the window has actually opened on the display.

    However, I'm pretty sure you can size the svg image to the same value as the font size, as both values I /think/ are in "fltk units" (which used to be pixels, before the display scaling stuff was added). I think you'll find everything xywh and font sizes are all in fltk units, so if the font size is 100, the svg w/h size should also be 100. There might be a small offset having to do with font descenders and such, but there's probably a way to figure that out without a round trip through the underlying font manager code.

Dibo

unread,
Jul 24, 2026, 1:42:27 AM (3 days ago) Jul 24
to fltk.general
Ehhh, my bad. That is the evidence that you have verify everything what AI is proposing, even Claude. Code above was from AI. I was pretty sure that  Fl_set_font(0, 14); set font Fl_Font_Helvetica (id=0) and its size 14 (that is also what fl_font_size return) but FLTK doc says that Fl_set_font copy one font face to another. If I remove Fl_set_font then fl_measure and fl_height work like a charm and return size 20. So this is against answer above - units are not the same, for text size 14, height is 20

Matthias Melcher

unread,
Jul 24, 2026, 6:19:48 AM (3 days ago) Jul 24
to fltk.general
Before you call any graphics call, you need to either show a window or explicitly open the connection to the display by calling `fl_open_display()`, see: https://www.fltk.org/doc-1.5/Fl_8cxx.html#a94ee21d83137569a6730e3e2e7305cbc

The C++ call to set the current font is `fl_font(face, size)`. See:  https://www.fltk.org/doc-1.5/group__fl__attributes.html#ga80203d2dd1e06550e7a35d6bb72f9bd6
Reply all
Reply to author
Forward
0 new messages