diff options
| author | Matthias Melcher <github@matthiasm.com> | 2022-11-01 13:30:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-01 13:30:05 +0100 |
| commit | 93ea93ee2b424ded25358d87529b1160cdb4f80c (patch) | |
| tree | a0a445a21ac71c72e4983a5ed8bf854a70dec3a8 /src/Fl_Flex.cxx | |
| parent | 31ec6f623ab76d3f1107af9782237b8d7a089026 (diff) | |
Fluid support for Fl_Flex (#523) and some Fl_Flex improvements
* Adding Fluid support for Fl_Flex, margins, and gap.
* Fluid Fl_Flex mostly working. Fixed in Fl_Flex::set_size().
* Fluid Flex live mode works, interactive dragging works
* Fluid Flex: adding check box for fixed children
* Fluid Flex: visual flexibility indicator in guides.
* Fluid Flex: bug in generated code.
* Fix formatting
* Fixing Tooltip, fixing resize issue PR #518.
* Removing unused variables.
Co-authored-by: Albrecht Schlosser <albrechts.fltk@online.de>
Diffstat (limited to 'src/Fl_Flex.cxx')
| -rw-r--r-- | src/Fl_Flex.cxx | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/Fl_Flex.cxx b/src/Fl_Flex.cxx index 028c08d1f..74e9ed13d 100644 --- a/src/Fl_Flex.cxx +++ b/src/Fl_Flex.cxx @@ -236,41 +236,50 @@ void Fl_Flex::end() { If \p size is 0 (zero) or negative the widget size is reset to flexible size. - \param[in] w widget to be affected + \param[in] child widget to be affected \param[in] size width (Fl_Flex::HORIZONTAL) or height (Fl_Flex::VERTICAL) */ -void Fl_Flex::set_size(Fl_Widget *w, int size) { +void Fl_Flex::set_size(Fl_Widget *child, int size) { if (size <= 0) size = 0; - w->resize(0, 0, size, size); + // find w in our fixed size list int idx = -1; for (int i = 0; i < set_size_size_; i++) { - if (set_size_[i] == w) { + if (set_size_[i] == child) { idx = i; break; } } - // remove from array ? + // remove from array, if we want the widget to be flexible, but an entry was found if (size == 0 && idx >= 0) { - for (int i = idx; i < set_size_size_ - 2; i++) { + for (int i = idx; i < set_size_size_ - 1; i++) { set_size_[i] = set_size_[i+1]; } set_size_size_--; return; } + // if w is meant to be flexible, we are done now if (size == 0) return; - // add to array of fixed size widgets - if (set_size_size_ == set_size_alloc_) { - set_size_alloc_ = alloc_size(set_size_alloc_); - set_size_ = (Fl_Widget **)realloc(set_size_, set_size_alloc_ * sizeof(Fl_Widget *)); + // if we have no entry yet, add to array of fixed size widgets + if (idx == -1) { + if (set_size_size_ == set_size_alloc_) { + set_size_alloc_ = alloc_size(set_size_alloc_); + set_size_ = (Fl_Widget **)realloc(set_size_, set_size_alloc_ * sizeof(Fl_Widget *)); + } + set_size_[set_size_size_] = child; + set_size_size_++; } - set_size_[set_size_size_] = w; - set_size_size_++; + + // if the child size is meant to be fixed, set its new size + if (horizontal()) + child->size(size, h()-margin_top_-margin_bottom_-Fl::box_dh(box())); + else + child->size(w()-margin_left_-margin_right_-Fl::box_dw(box()), size); } /** |
