Skip to content

Commit

Permalink
HorizontalLayout: minor fix for witgets with specific height
Browse files Browse the repository at this point in the history
The size hint for HorizontalLayout also taks under consideration the
height of the widget. You can ask for a speciic height and it will be
honored.

Problems:
 - Tried the same fix for vertical layout, and things get borked. Might
be the hints of the widgets.
 - Popup list of Combobox is borked.
 - Buttons on the main demo, as off slightly outside the window.
  • Loading branch information
diegoiast committed Jan 1, 2024
1 parent 1f30812 commit 9232a75
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
23 changes: 19 additions & 4 deletions src/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ auto HorizontalLayout ::relayout(Position position, const Size size) -> void {
} else {
recommended_size.width = hint.width;
}
if (hint.height > 0) {
recommended_size.height = hint.height;
}
position.x += padding.start;
if (auto item = item_iterator.lock()) {
item->relayout(position, recommended_size);
Expand All @@ -77,8 +80,12 @@ auto HorizontalLayout::size_hint() const -> Size {
}
found++;
auto item_hint = item->size_hint();
hint.height = std::max(item_hint.height, hint.height);
hint.width = std::max(item_hint.width, hint.width);
if (hint.height > 0) {
hint.height = std::max(item_hint.height, hint.height);
}
if (hint.width > 0) {
hint.width = std::max(item_hint.width, hint.width);
}
}
}

Expand Down Expand Up @@ -144,6 +151,10 @@ auto VerticalLayout::relayout(Position position, const Size size) -> void {
} else {
recommended_size.height = hint.height;
}
// TODO - this breaks the display. I think the type hints is borked.
if (hint.width > 0) {
// recommended_size.width = hint.width;
}
position.y += padding.top;
if (auto item = item_iterator.lock()) {
item->relayout(position, recommended_size);
Expand All @@ -161,8 +172,12 @@ auto VerticalLayout::size_hint() const -> Size {
if (auto item = item_iterator.lock()) {
found++;
auto item_hint = item->size_hint();
hint.height = std::max(item_hint.height, hint.height);
hint.width = std::max(item_hint.width, hint.width);
if (hint.height > 0) {
hint.height = std::max(item_hint.height, hint.height);
}
if (hint.width > 0) {
hint.width = std::max(item_hint.width, hint.width);
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ int main() {
spdlog::info("Selected item {} with text {}", index, button.text);
};
rb->radio_buttons[1]->is_enabled = false;
w1->add_new<Combobox>(Position{10, 280}, 200,
std::vector<std::string>{
"Spring",
"Summer",
"Autumn/Fall",
"Winter",
});
w1->add_new_to_layout<Combobox>(l1, Position{10, 280}, 200,
std::vector<std::string>{
"Spring",
"Summer",
"Autumn/Fall",
"Winter",
});

// w1->add_new_to_layout<Label>(l_right, Position{10, 10}, Size{300, 20}, "12331");

Expand Down

0 comments on commit 9232a75

Please sign in to comment.