On 6/25/26 21:27 Dibo wrote:
> After writting bindings for Free Pascal:
>
https://github.com/dibok/PasFLTK
> ... I'm now practicing in this framework and migrating my apps from
> Qt. I'm very excited about that.
Great! Welcome to the FLTK world, and thank you very much for the Pascal
bindings, although I personally don't use Pascal. I used it a very, very
long time ago in a project during my studies, but never again.
> After few evenings of reading about Fl_Flex, Fl_Group, Fl_Grid,
> Fl_Pack and analyzing demos, I can't figure out one thing. Is there
> any functionality which "squash" container into its content by
> scalling all childs to its "preferred" size? For example if button has
> label / caption then it doesn't allow set button's bounds smaller than
> text? Or anything like expanding spacer (Fl_Flex has only Fixed
> spacer)? Seems like I must set fixed sizes everywhere even on layouts
> by itself. That is fine until you use locales in your app and some
> words are longer in other languages or user use non-standard font size
> in OS (people with deteriorated eyesight). One video is worth a
> thousand words so I made one which explain what I want to retrieve:
>
https://drive.google.com/file/d/1qPwlED5KfWv2Mdu6PwjxBOCQ7wtdNk7-/view?usp=sharing
We don't have "spacer" widgets or other widgets that shrink to a size
determined by their contents (text). As Greg wrote, you can determine
the bounds of text yourself. If you localize your app you need to
measure the text with the localized strings, obviously. This should be
doable, but it needs some coding.
Note also that FLTK is written in C++ for good reasons. This allows the
user to derive their own classes that do specialized things like
My_Shrink_Button, My_Text_Box, etc. which can do what you want to
achieve, but you must still arrange them in (flexible) container
widgets. I'm not sure if you can do that with your Pascal bindings which
are based on the C bindings of FLTK. But maybe you can, somehow?
Anyway, talking further about pure (C++) FLTK.
Fl_Pack exists and has some "shrinking" behavior, but I don't recommend
to use it in new software. This has been an early contribution but has
some issues with resizing etc.. If you try it, it may work well, but at
some time you may encounter issues.
Fl_Flex is a new widget since FLTK 1.4 and can be used like Fl_Pack, but
it integrates better with FLTK's resizing. Fl_Flex widgets can be nested
to produce more complex layouts, e.g. one horizontal Fl_Flex as
container of columns which can contain vertical Fl_Flex widgets for the
contents of columns. Since each Fl_Flex can either be one column or one
row, its use is limited. Also, its flexibility is kind of "all or
nothing", i.e. the free space is divided evenly among all non-fixed widgets.
Fl_Grid is the most flexible container widget provided by FLTK. As its
name says, it is based on a grid (aka table) layout, where you can put
widgets at any (x, y) position in the grid. Of course you can also limit
it only to one column (vertical) or own row (horizontal) of widgets.
There are also many attributes you can set for most flexibility,
particularly a "weight" per row or column that determines how much of
the free space is distributed to this particular cell of the grid.
Finally, Fl_Grid widgets can also be nested, and they can also contain
Fl_Flex widgets if needed. As I said, this is the most flexible layout
(container) widget you can use in FLTK. I recommend it for all kinds of
flexible layouts.
Besides that, normal Fl_Group widgets can also be used, but their
resizable() widget is limited in its way to determine the final layout.
It's also hard to understand how it works (at a first glance), and
flexible layouts may often need nested Fl_Group widgets. You may want to
make a basic layout of some normal Fl_Group widgets that contain Fl_Grid
widgets and so on.
If you like, you may compare test/cube.cxx before and after commit
38871c5b3192bccd508f3686413d4e56041ab091 to get an impression of the
complexity of Fl_Group based layouts vs. Fl_Grid based ones. Although
the number of lines of code didn't change significantly, the new code is
much simpler and clearer.
I hope this helps. Have fun!