mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Use vector/unique_ptr inside widget containers.
This replaces a C-style double-linked-list which required all widgets to have next/prev pointers, and removes the need for manual pointer management.
This commit is contained in:
parent
628092f133
commit
9a3934ae23
|
@ -115,18 +115,18 @@ public:
|
||||||
this->resize_y = 0; // We never resize in this direction
|
this->resize_y = 0; // We never resize in this direction
|
||||||
|
|
||||||
/* First initialise some variables... */
|
/* First initialise some variables... */
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->SetupSmallestSize(w);
|
child_wid->SetupSmallestSize(w);
|
||||||
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
|
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ... then in a second pass make sure the 'current' sizes are set. Won't change for most widgets. */
|
/* ... then in a second pass make sure the 'current' sizes are set. Won't change for most widgets. */
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->current_x = child_wid->smallest_x;
|
child_wid->current_x = child_wid->smallest_x;
|
||||||
child_wid->current_y = this->smallest_y;
|
child_wid->current_y = this->smallest_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->smallest_x = this->head->smallest_x + this->tail->smallest_x; // First and last are always shown, rest not
|
this->smallest_x = this->children.front()->smallest_x + this->children.back()->smallest_x; // First and last are always shown, rest not
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
|
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
|
||||||
|
@ -138,27 +138,38 @@ public:
|
||||||
this->current_x = given_width;
|
this->current_x = given_width;
|
||||||
this->current_y = given_height;
|
this->current_y = given_height;
|
||||||
|
|
||||||
given_width -= this->tail->smallest_x;
|
given_width -= this->children.back()->smallest_x;
|
||||||
/* The first and last widget are always visible, determine which other should be visible */
|
/* The first and last widget are always visible, determine which other should be visible */
|
||||||
for (NWidgetBase *child_wid = this->head->next; child_wid->next != nullptr; child_wid = child_wid->next) {
|
if (this->children.size() > 2) {
|
||||||
if (given_width > ScaleGUITrad(MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER) + child_wid->smallest_x && child_wid->prev->current_x != 0) {
|
auto first = std::next(std::begin(this->children));
|
||||||
given_width -= child_wid->smallest_x;
|
auto last = std::prev(std::end(this->children));
|
||||||
child_wid->current_x = child_wid->smallest_x; /* Make visible. */
|
for (auto it = first; it != last; ++it) {
|
||||||
} else {
|
auto &child_wid = *it;
|
||||||
child_wid->current_x = 0; /* Make invisible. */
|
if (given_width > ScaleGUITrad(MINIMUM_NAME_WIDTH_BEFORE_NEW_HEADER) + child_wid->smallest_x && (*std::prev(it))->current_x != 0) {
|
||||||
|
given_width -= child_wid->smallest_x;
|
||||||
|
child_wid->current_x = child_wid->smallest_x; /* Make visible. */
|
||||||
|
} else {
|
||||||
|
child_wid->current_x = 0; /* Make invisible. */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* All remaining space goes to the first (name) widget */
|
/* All remaining space goes to the first (name) widget */
|
||||||
this->head->current_x = given_width;
|
this->children.front()->current_x = given_width;
|
||||||
|
|
||||||
/* Now assign the widgets to their rightful place */
|
/* Now assign the widgets to their rightful place */
|
||||||
uint position = 0; // Place to put next child relative to origin of the container.
|
uint position = 0; // Place to put next child relative to origin of the container.
|
||||||
for (NWidgetBase *child_wid = rtl ? this->tail : this->head; child_wid != nullptr; child_wid = rtl ? child_wid->prev : child_wid->next) {
|
auto assign_position = [&](const std::unique_ptr<NWidgetBase> &child_wid) {
|
||||||
if (child_wid->current_x != 0) {
|
if (child_wid->current_x != 0) {
|
||||||
child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
|
child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
|
||||||
position += child_wid->current_x;
|
position += child_wid->current_x;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (rtl) {
|
||||||
|
std::for_each(std::rbegin(this->children), std::rend(this->children), assign_position);
|
||||||
|
} else {
|
||||||
|
std::for_each(std::begin(this->children), std::end(this->children), assign_position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1852,8 +1852,9 @@ public:
|
||||||
|
|
||||||
void SetupSmallestSize(Window *w) override
|
void SetupSmallestSize(Window *w) override
|
||||||
{
|
{
|
||||||
NWidgetBase *display = this->head;
|
assert(this->children.size() == 2);
|
||||||
NWidgetBase *bar = display->next;
|
NWidgetBase *display = this->children.front().get();
|
||||||
|
NWidgetBase *bar = this->children.back().get();
|
||||||
|
|
||||||
display->SetupSmallestSize(w);
|
display->SetupSmallestSize(w);
|
||||||
bar->SetupSmallestSize(w);
|
bar->SetupSmallestSize(w);
|
||||||
|
@ -1875,8 +1876,9 @@ public:
|
||||||
this->current_x = given_width;
|
this->current_x = given_width;
|
||||||
this->current_y = given_height;
|
this->current_y = given_height;
|
||||||
|
|
||||||
NWidgetBase *display = this->head;
|
assert(this->children.size() == 2);
|
||||||
NWidgetBase *bar = display->next;
|
NWidgetBase *display = this->children.front().get();
|
||||||
|
NWidgetBase *bar = this->children.back().get();
|
||||||
|
|
||||||
if (sizing == ST_SMALLEST) {
|
if (sizing == ST_SMALLEST) {
|
||||||
this->smallest_x = given_width;
|
this->smallest_x = given_width;
|
||||||
|
|
|
@ -1347,7 +1347,7 @@ public:
|
||||||
|
|
||||||
uint nbuttons = 0;
|
uint nbuttons = 0;
|
||||||
/* First initialise some variables... */
|
/* First initialise some variables... */
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->SetupSmallestSize(w);
|
child_wid->SetupSmallestSize(w);
|
||||||
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
|
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
|
||||||
if (this->IsButton(child_wid->type)) {
|
if (this->IsButton(child_wid->type)) {
|
||||||
|
@ -1359,7 +1359,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ... then in a second pass make sure the 'current' heights are set. Won't change ever. */
|
/* ... then in a second pass make sure the 'current' heights are set. Won't change ever. */
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->current_y = this->smallest_y;
|
child_wid->current_y = this->smallest_y;
|
||||||
if (!this->IsButton(child_wid->type)) {
|
if (!this->IsButton(child_wid->type)) {
|
||||||
child_wid->current_x = child_wid->smallest_x;
|
child_wid->current_x = child_wid->smallest_x;
|
||||||
|
@ -1381,12 +1381,13 @@ public:
|
||||||
uint arrangable_count, button_count, spacer_count;
|
uint arrangable_count, button_count, spacer_count;
|
||||||
const WidgetID *arrangement = GetButtonArrangement(given_width, arrangable_count, button_count, spacer_count);
|
const WidgetID *arrangement = GetButtonArrangement(given_width, arrangable_count, button_count, spacer_count);
|
||||||
|
|
||||||
/* Create us ourselves a quick lookup table */
|
/* Create us ourselves a quick lookup table from WidgetID to slot. */
|
||||||
NWidgetBase *widgets[WID_TN_END];
|
std::map<WidgetID, uint> lookup;
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (auto it = std::begin(this->children); it != std::end(this->children); ++it) {
|
||||||
child_wid->current_x = 0; /* Hide widget, it will be revealed in the next step. */
|
NWidgetBase *nwid = it->get();
|
||||||
if (child_wid->type == NWID_SPACER) continue;
|
nwid->current_x = 0; /* Hide widget, it will be revealed in the next step. */
|
||||||
widgets[((NWidgetCore*)child_wid)->index] = child_wid;
|
if (nwid->type == NWID_SPACER) continue;
|
||||||
|
lookup[dynamic_cast<NWidgetCore *>(nwid)->index] = std::distance(this->children.begin(), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now assign the widgets to their rightful place */
|
/* Now assign the widgets to their rightful place */
|
||||||
|
@ -1397,12 +1398,13 @@ public:
|
||||||
uint button_i = 0;
|
uint button_i = 0;
|
||||||
|
|
||||||
/* Index into the arrangement indices. The macro lastof cannot be used here! */
|
/* Index into the arrangement indices. The macro lastof cannot be used here! */
|
||||||
const WidgetID *cur_wid = rtl ? &arrangement[arrangable_count - 1] : arrangement;
|
const WidgetID *slotp = rtl ? &arrangement[arrangable_count - 1] : arrangement;
|
||||||
for (uint i = 0; i < arrangable_count; i++) {
|
for (uint i = 0; i < arrangable_count; i++) {
|
||||||
NWidgetBase *child_wid = widgets[*cur_wid];
|
uint slot = lookup[*slotp];
|
||||||
/* If we have to give space to the spacers, do that */
|
auto &child_wid = this->children[slot];
|
||||||
if (spacer_space != 0) {
|
/* If we have space to give to the spacers, do that. */
|
||||||
NWidgetBase *possible_spacer = rtl ? child_wid->next : child_wid->prev;
|
if (spacer_space > 0 && slot > 0 && slot < this->children.size() - 1) {
|
||||||
|
const auto &possible_spacer = this->children[slot + (rtl ? 1 : -1)];
|
||||||
if (possible_spacer != nullptr && possible_spacer->type == NWID_SPACER) {
|
if (possible_spacer != nullptr && possible_spacer->type == NWID_SPACER) {
|
||||||
uint add = spacer_space / (spacer_count - spacer_i);
|
uint add = spacer_space / (spacer_count - spacer_i);
|
||||||
position += add;
|
position += add;
|
||||||
|
@ -1423,9 +1425,9 @@ public:
|
||||||
position += child_wid->current_x;
|
position += child_wid->current_x;
|
||||||
|
|
||||||
if (rtl) {
|
if (rtl) {
|
||||||
cur_wid--;
|
slotp--;
|
||||||
} else {
|
} else {
|
||||||
cur_wid++;
|
slotp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1783,7 +1785,7 @@ class NWidgetScenarioToolbarContainer : public NWidgetToolbarContainer {
|
||||||
|
|
||||||
/* Find the size of panel_widths */
|
/* Find the size of panel_widths */
|
||||||
uint i = 0;
|
uint i = 0;
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
if (child_wid->type == NWID_SPACER || this->IsButton(child_wid->type)) continue;
|
if (child_wid->type == NWID_SPACER || this->IsButton(child_wid->type)) continue;
|
||||||
|
|
||||||
assert(i < lengthof(this->panel_widths));
|
assert(i < lengthof(this->panel_widths));
|
||||||
|
|
143
src/widget.cpp
143
src/widget.cpp
|
@ -1275,30 +1275,10 @@ NWidgetCore *NWidgetCore::GetWidgetFromPos(int x, int y)
|
||||||
return (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) ? this : nullptr;
|
return (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) ? this : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor container baseclass.
|
|
||||||
* @param tp Type of the container.
|
|
||||||
*/
|
|
||||||
NWidgetContainer::NWidgetContainer(WidgetType tp) : NWidgetBase(tp)
|
|
||||||
{
|
|
||||||
this->head = nullptr;
|
|
||||||
this->tail = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
NWidgetContainer::~NWidgetContainer()
|
|
||||||
{
|
|
||||||
while (this->head != nullptr) {
|
|
||||||
NWidgetBase *wid = this->head->next;
|
|
||||||
delete this->head;
|
|
||||||
this->head = wid;
|
|
||||||
}
|
|
||||||
this->tail = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
NWidgetBase *NWidgetContainer::GetWidgetOfType(WidgetType tp)
|
NWidgetBase *NWidgetContainer::GetWidgetOfType(WidgetType tp)
|
||||||
{
|
{
|
||||||
if (this->type == tp) return this;
|
if (this->type == tp) return this;
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
NWidgetBase *nwid = child_wid->GetWidgetOfType(tp);
|
NWidgetBase *nwid = child_wid->GetWidgetOfType(tp);
|
||||||
if (nwid != nullptr) return nwid;
|
if (nwid != nullptr) return nwid;
|
||||||
}
|
}
|
||||||
|
@ -1307,7 +1287,7 @@ NWidgetBase *NWidgetContainer::GetWidgetOfType(WidgetType tp)
|
||||||
|
|
||||||
void NWidgetContainer::AdjustPaddingForZoom()
|
void NWidgetContainer::AdjustPaddingForZoom()
|
||||||
{
|
{
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->AdjustPaddingForZoom();
|
child_wid->AdjustPaddingForZoom();
|
||||||
}
|
}
|
||||||
NWidgetBase::AdjustPaddingForZoom();
|
NWidgetBase::AdjustPaddingForZoom();
|
||||||
|
@ -1321,31 +1301,19 @@ void NWidgetContainer::Add(NWidgetBase *wid)
|
||||||
{
|
{
|
||||||
assert(wid != nullptr);
|
assert(wid != nullptr);
|
||||||
wid->parent = this;
|
wid->parent = this;
|
||||||
assert(wid->next == nullptr && wid->prev == nullptr);
|
this->children.emplace_back(wid);
|
||||||
|
|
||||||
if (this->head == nullptr) {
|
|
||||||
this->head = wid;
|
|
||||||
this->tail = wid;
|
|
||||||
} else {
|
|
||||||
assert(this->tail != nullptr);
|
|
||||||
assert(this->tail->next == nullptr);
|
|
||||||
|
|
||||||
this->tail->next = wid;
|
|
||||||
wid->prev = this->tail;
|
|
||||||
this->tail = wid;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NWidgetContainer::FillWidgetLookup(WidgetLookup &widget_lookup)
|
void NWidgetContainer::FillWidgetLookup(WidgetLookup &widget_lookup)
|
||||||
{
|
{
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->FillWidgetLookup(widget_lookup);
|
child_wid->FillWidgetLookup(widget_lookup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NWidgetContainer::Draw(const Window *w)
|
void NWidgetContainer::Draw(const Window *w)
|
||||||
{
|
{
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->Draw(w);
|
child_wid->Draw(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1356,7 +1324,7 @@ NWidgetCore *NWidgetContainer::GetWidgetFromPos(int x, int y)
|
||||||
{
|
{
|
||||||
if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
|
if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
|
||||||
|
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
|
NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
|
||||||
if (nwid != nullptr) return nwid;
|
if (nwid != nullptr) return nwid;
|
||||||
}
|
}
|
||||||
|
@ -1372,7 +1340,7 @@ NWidgetStacked::NWidgetStacked(WidgetID index) : NWidgetContainer(NWID_SELECTION
|
||||||
|
|
||||||
void NWidgetStacked::AdjustPaddingForZoom()
|
void NWidgetStacked::AdjustPaddingForZoom()
|
||||||
{
|
{
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->AdjustPaddingForZoom();
|
child_wid->AdjustPaddingForZoom();
|
||||||
}
|
}
|
||||||
NWidgetContainer::AdjustPaddingForZoom();
|
NWidgetContainer::AdjustPaddingForZoom();
|
||||||
|
@ -1401,11 +1369,11 @@ void NWidgetStacked::SetupSmallestSize(Window *w)
|
||||||
/* First sweep, recurse down and compute minimal size and filling. */
|
/* First sweep, recurse down and compute minimal size and filling. */
|
||||||
this->smallest_x = 0;
|
this->smallest_x = 0;
|
||||||
this->smallest_y = 0;
|
this->smallest_y = 0;
|
||||||
this->fill_x = (this->head != nullptr) ? 1 : 0;
|
this->fill_x = this->IsEmpty() ? 0 : 1;
|
||||||
this->fill_y = (this->head != nullptr) ? 1 : 0;
|
this->fill_y = this->IsEmpty() ? 0 : 1;
|
||||||
this->resize_x = (this->head != nullptr) ? 1 : 0;
|
this->resize_x = this->IsEmpty() ? 0 : 1;
|
||||||
this->resize_y = (this->head != nullptr) ? 1 : 0;
|
this->resize_y = this->IsEmpty() ? 0 : 1;
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->SetupSmallestSize(w);
|
child_wid->SetupSmallestSize(w);
|
||||||
|
|
||||||
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
|
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
|
||||||
|
@ -1424,7 +1392,7 @@ void NWidgetStacked::AssignSizePosition(SizingType sizing, int x, int y, uint gi
|
||||||
|
|
||||||
if (this->shown_plane >= SZSP_BEGIN) return;
|
if (this->shown_plane >= SZSP_BEGIN) return;
|
||||||
|
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
|
uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
|
||||||
uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding.Horizontal(), hor_step);
|
uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding.Horizontal(), hor_step);
|
||||||
uint child_pos_x = (rtl ? child_wid->padding.right : child_wid->padding.left);
|
uint child_pos_x = (rtl ? child_wid->padding.right : child_wid->padding.left);
|
||||||
|
@ -1447,16 +1415,9 @@ void NWidgetStacked::Draw(const Window *w)
|
||||||
{
|
{
|
||||||
if (this->shown_plane >= SZSP_BEGIN) return;
|
if (this->shown_plane >= SZSP_BEGIN) return;
|
||||||
|
|
||||||
int plane = 0;
|
assert(static_cast<size_t>(this->shown_plane) < this->children.size());
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) {
|
this->children[shown_plane]->Draw(w);
|
||||||
if (plane == this->shown_plane) {
|
DrawOutline(w, this);
|
||||||
child_wid->Draw(w);
|
|
||||||
DrawOutline(w, this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NOT_REACHED();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NWidgetCore *NWidgetStacked::GetWidgetFromPos(int x, int y)
|
NWidgetCore *NWidgetStacked::GetWidgetFromPos(int x, int y)
|
||||||
|
@ -1464,13 +1425,9 @@ NWidgetCore *NWidgetStacked::GetWidgetFromPos(int x, int y)
|
||||||
if (this->shown_plane >= SZSP_BEGIN) return nullptr;
|
if (this->shown_plane >= SZSP_BEGIN) return nullptr;
|
||||||
|
|
||||||
if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
|
if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
|
||||||
int plane = 0;
|
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) {
|
if (static_cast<size_t>(this->shown_plane) >= this->children.size()) return nullptr;
|
||||||
if (plane == this->shown_plane) {
|
return this->children[shown_plane]->GetWidgetFromPos(x, y);
|
||||||
return child_wid->GetWidgetFromPos(x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1552,7 +1509,7 @@ void NWidgetHorizontal::SetupSmallestSize(Window *w)
|
||||||
/* 1a. Forward call, collect longest/widest child length. */
|
/* 1a. Forward call, collect longest/widest child length. */
|
||||||
uint longest = 0; // Longest child found.
|
uint longest = 0; // Longest child found.
|
||||||
uint max_vert_fill = 0; // Biggest vertical fill step.
|
uint max_vert_fill = 0; // Biggest vertical fill step.
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->SetupSmallestSize(w);
|
child_wid->SetupSmallestSize(w);
|
||||||
longest = std::max(longest, child_wid->smallest_x);
|
longest = std::max(longest, child_wid->smallest_x);
|
||||||
max_vert_fill = std::max(max_vert_fill, child_wid->GetVerticalStepSize(ST_SMALLEST));
|
max_vert_fill = std::max(max_vert_fill, child_wid->GetVerticalStepSize(ST_SMALLEST));
|
||||||
|
@ -1564,7 +1521,7 @@ void NWidgetHorizontal::SetupSmallestSize(Window *w)
|
||||||
[[maybe_unused]] uint max_smallest = this->smallest_y + 3 * max_vert_fill; // Upper limit to computing smallest height.
|
[[maybe_unused]] uint max_smallest = this->smallest_y + 3 * max_vert_fill; // Upper limit to computing smallest height.
|
||||||
uint cur_height = this->smallest_y;
|
uint cur_height = this->smallest_y;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint step_size = child_wid->GetVerticalStepSize(ST_SMALLEST);
|
uint step_size = child_wid->GetVerticalStepSize(ST_SMALLEST);
|
||||||
uint child_height = child_wid->smallest_y + child_wid->padding.Vertical();
|
uint child_height = child_wid->smallest_y + child_wid->padding.Vertical();
|
||||||
if (step_size > 1 && child_height < cur_height) { // Small step sizes or already fitting children are not interesting.
|
if (step_size > 1 && child_height < cur_height) { // Small step sizes or already fitting children are not interesting.
|
||||||
|
@ -1581,12 +1538,12 @@ void NWidgetHorizontal::SetupSmallestSize(Window *w)
|
||||||
}
|
}
|
||||||
/* 2. For containers that must maintain equal width, extend child minimal size. */
|
/* 2. For containers that must maintain equal width, extend child minimal size. */
|
||||||
if (this->flags & NC_EQUALSIZE) {
|
if (this->flags & NC_EQUALSIZE) {
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
|
if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 3. Compute smallest, fill, and resize values of the container. */
|
/* 3. Compute smallest, fill, and resize values of the container. */
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
this->smallest_x += child_wid->smallest_x + child_wid->padding.Horizontal();
|
this->smallest_x += child_wid->smallest_x + child_wid->padding.Horizontal();
|
||||||
if (child_wid->fill_x > 0) {
|
if (child_wid->fill_x > 0) {
|
||||||
if (this->fill_x == 0 || this->fill_x > child_wid->fill_x) this->fill_x = child_wid->fill_x;
|
if (this->fill_x == 0 || this->fill_x > child_wid->fill_x) this->fill_x = child_wid->fill_x;
|
||||||
|
@ -1609,7 +1566,7 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, int x, int y, uint
|
||||||
|
|
||||||
/* Compute additional width given to us. */
|
/* Compute additional width given to us. */
|
||||||
uint additional_length = given_width - (this->pip_pre + this->gaps * this->pip_inter + this->pip_post);
|
uint additional_length = given_width - (this->pip_pre + this->gaps * this->pip_inter + this->pip_post);
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
if (child_wid->smallest_x != 0 || child_wid->fill_x != 0) additional_length -= child_wid->smallest_x + child_wid->padding.Horizontal();
|
if (child_wid->smallest_x != 0 || child_wid->fill_x != 0) additional_length -= child_wid->smallest_x + child_wid->padding.Horizontal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1631,7 +1588,7 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, int x, int y, uint
|
||||||
*/
|
*/
|
||||||
int num_changing_childs = 0; // Number of children that can change size.
|
int num_changing_childs = 0; // Number of children that can change size.
|
||||||
uint biggest_stepsize = 0;
|
uint biggest_stepsize = 0;
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
||||||
if (hor_step > 0) {
|
if (hor_step > 0) {
|
||||||
if (!(flags & NC_BIGFIRST)) num_changing_childs++;
|
if (!(flags & NC_BIGFIRST)) num_changing_childs++;
|
||||||
|
@ -1646,7 +1603,7 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, int x, int y, uint
|
||||||
|
|
||||||
/* First.5 loop: count how many children are of the biggest step size. */
|
/* First.5 loop: count how many children are of the biggest step size. */
|
||||||
if ((flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
if ((flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
||||||
if (hor_step == biggest_stepsize) {
|
if (hor_step == biggest_stepsize) {
|
||||||
num_changing_childs++;
|
num_changing_childs++;
|
||||||
|
@ -1657,7 +1614,7 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, int x, int y, uint
|
||||||
/* Second loop: Allocate the additional horizontal space over the resizing children, starting with the biggest resize steps. */
|
/* Second loop: Allocate the additional horizontal space over the resizing children, starting with the biggest resize steps. */
|
||||||
while (biggest_stepsize > 0) {
|
while (biggest_stepsize > 0) {
|
||||||
uint next_biggest_stepsize = 0;
|
uint next_biggest_stepsize = 0;
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
||||||
if (hor_step > biggest_stepsize) continue; // Already done
|
if (hor_step > biggest_stepsize) continue; // Already done
|
||||||
if (hor_step == biggest_stepsize) {
|
if (hor_step == biggest_stepsize) {
|
||||||
|
@ -1674,7 +1631,7 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, int x, int y, uint
|
||||||
|
|
||||||
if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
||||||
/* Second.5 loop: count how many children are of the updated biggest step size. */
|
/* Second.5 loop: count how many children are of the updated biggest step size. */
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
uint hor_step = child_wid->GetHorizontalStepSize(sizing);
|
||||||
if (hor_step == biggest_stepsize) {
|
if (hor_step == biggest_stepsize) {
|
||||||
num_changing_childs++;
|
num_changing_childs++;
|
||||||
|
@ -1699,8 +1656,7 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, int x, int y, uint
|
||||||
|
|
||||||
/* Third loop: Compute position and call the child. */
|
/* Third loop: Compute position and call the child. */
|
||||||
uint position = rtl ? this->current_x - pre : pre; // Place to put next child relative to origin of the container.
|
uint position = rtl ? this->current_x - pre : pre; // Place to put next child relative to origin of the container.
|
||||||
NWidgetBase *child_wid = this->head;
|
for (const auto &child_wid : this->children) {
|
||||||
while (child_wid != nullptr) {
|
|
||||||
uint child_width = child_wid->current_x;
|
uint child_width = child_wid->current_x;
|
||||||
uint child_x = x + (rtl ? position - child_width - child_wid->padding.left : position + child_wid->padding.left);
|
uint child_x = x + (rtl ? position - child_width - child_wid->padding.left : position + child_wid->padding.left);
|
||||||
uint child_y = y + child_wid->padding.top;
|
uint child_y = y + child_wid->padding.top;
|
||||||
|
@ -1710,8 +1666,6 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, int x, int y, uint
|
||||||
uint padded_child_width = child_width + child_wid->padding.Horizontal() + inter;
|
uint padded_child_width = child_width + child_wid->padding.Horizontal() + inter;
|
||||||
position = rtl ? position - padded_child_width : position + padded_child_width;
|
position = rtl ? position - padded_child_width : position + padded_child_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
child_wid = child_wid->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1744,7 +1698,7 @@ void NWidgetVertical::SetupSmallestSize(Window *w)
|
||||||
/* 1a. Forward call, collect longest/widest child length. */
|
/* 1a. Forward call, collect longest/widest child length. */
|
||||||
uint highest = 0; // Highest child found.
|
uint highest = 0; // Highest child found.
|
||||||
uint max_hor_fill = 0; // Biggest horizontal fill step.
|
uint max_hor_fill = 0; // Biggest horizontal fill step.
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
child_wid->SetupSmallestSize(w);
|
child_wid->SetupSmallestSize(w);
|
||||||
highest = std::max(highest, child_wid->smallest_y);
|
highest = std::max(highest, child_wid->smallest_y);
|
||||||
max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(ST_SMALLEST));
|
max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(ST_SMALLEST));
|
||||||
|
@ -1756,7 +1710,7 @@ void NWidgetVertical::SetupSmallestSize(Window *w)
|
||||||
[[maybe_unused]] uint max_smallest = this->smallest_x + 3 * max_hor_fill; // Upper limit to computing smallest height.
|
[[maybe_unused]] uint max_smallest = this->smallest_x + 3 * max_hor_fill; // Upper limit to computing smallest height.
|
||||||
uint cur_width = this->smallest_x;
|
uint cur_width = this->smallest_x;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint step_size = child_wid->GetHorizontalStepSize(ST_SMALLEST);
|
uint step_size = child_wid->GetHorizontalStepSize(ST_SMALLEST);
|
||||||
uint child_width = child_wid->smallest_x + child_wid->padding.Horizontal();
|
uint child_width = child_wid->smallest_x + child_wid->padding.Horizontal();
|
||||||
if (step_size > 1 && child_width < cur_width) { // Small step sizes or already fitting children are not interesting.
|
if (step_size > 1 && child_width < cur_width) { // Small step sizes or already fitting children are not interesting.
|
||||||
|
@ -1773,12 +1727,12 @@ void NWidgetVertical::SetupSmallestSize(Window *w)
|
||||||
}
|
}
|
||||||
/* 2. For containers that must maintain equal width, extend children minimal size. */
|
/* 2. For containers that must maintain equal width, extend children minimal size. */
|
||||||
if (this->flags & NC_EQUALSIZE) {
|
if (this->flags & NC_EQUALSIZE) {
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
|
if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 3. Compute smallest, fill, and resize values of the container. */
|
/* 3. Compute smallest, fill, and resize values of the container. */
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
this->smallest_y += child_wid->smallest_y + child_wid->padding.Vertical();
|
this->smallest_y += child_wid->smallest_y + child_wid->padding.Vertical();
|
||||||
if (child_wid->fill_y > 0) {
|
if (child_wid->fill_y > 0) {
|
||||||
if (this->fill_y == 0 || this->fill_y > child_wid->fill_y) this->fill_y = child_wid->fill_y;
|
if (this->fill_y == 0 || this->fill_y > child_wid->fill_y) this->fill_y = child_wid->fill_y;
|
||||||
|
@ -1801,7 +1755,7 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, int x, int y, uint g
|
||||||
|
|
||||||
/* Compute additional height given to us. */
|
/* Compute additional height given to us. */
|
||||||
uint additional_length = given_height - (this->pip_pre + this->gaps * this->pip_inter + this->pip_post);
|
uint additional_length = given_height - (this->pip_pre + this->gaps * this->pip_inter + this->pip_post);
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
if (child_wid->smallest_y != 0 || child_wid->fill_y != 0) additional_length -= child_wid->smallest_y + child_wid->padding.Vertical();
|
if (child_wid->smallest_y != 0 || child_wid->fill_y != 0) additional_length -= child_wid->smallest_y + child_wid->padding.Vertical();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1814,7 +1768,7 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, int x, int y, uint g
|
||||||
/* First loop: Find biggest stepsize, find number of children that want a piece of the pie, handle horizontal size for all children, handle vertical size for non-resizing child. */
|
/* First loop: Find biggest stepsize, find number of children that want a piece of the pie, handle horizontal size for all children, handle vertical size for non-resizing child. */
|
||||||
int num_changing_childs = 0; // Number of children that can change size.
|
int num_changing_childs = 0; // Number of children that can change size.
|
||||||
uint biggest_stepsize = 0;
|
uint biggest_stepsize = 0;
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
||||||
if (vert_step > 0) {
|
if (vert_step > 0) {
|
||||||
if (!(flags & NC_BIGFIRST)) num_changing_childs++;
|
if (!(flags & NC_BIGFIRST)) num_changing_childs++;
|
||||||
|
@ -1829,7 +1783,7 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, int x, int y, uint g
|
||||||
|
|
||||||
/* First.5 loop: count how many children are of the biggest step size. */
|
/* First.5 loop: count how many children are of the biggest step size. */
|
||||||
if ((this->flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
if ((this->flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
||||||
if (vert_step == biggest_stepsize) {
|
if (vert_step == biggest_stepsize) {
|
||||||
num_changing_childs++;
|
num_changing_childs++;
|
||||||
|
@ -1840,7 +1794,7 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, int x, int y, uint g
|
||||||
/* Second loop: Allocate the additional vertical space over the resizing children, starting with the biggest resize steps. */
|
/* Second loop: Allocate the additional vertical space over the resizing children, starting with the biggest resize steps. */
|
||||||
while (biggest_stepsize > 0) {
|
while (biggest_stepsize > 0) {
|
||||||
uint next_biggest_stepsize = 0;
|
uint next_biggest_stepsize = 0;
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
||||||
if (vert_step > biggest_stepsize) continue; // Already done
|
if (vert_step > biggest_stepsize) continue; // Already done
|
||||||
if (vert_step == biggest_stepsize) {
|
if (vert_step == biggest_stepsize) {
|
||||||
|
@ -1857,7 +1811,7 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, int x, int y, uint g
|
||||||
|
|
||||||
if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
|
||||||
/* Second.5 loop: count how many children are of the updated biggest step size. */
|
/* Second.5 loop: count how many children are of the updated biggest step size. */
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
uint vert_step = child_wid->GetVerticalStepSize(sizing);
|
||||||
if (vert_step == biggest_stepsize) {
|
if (vert_step == biggest_stepsize) {
|
||||||
num_changing_childs++;
|
num_changing_childs++;
|
||||||
|
@ -1882,7 +1836,7 @@ void NWidgetVertical::AssignSizePosition(SizingType sizing, int x, int y, uint g
|
||||||
|
|
||||||
/* Third loop: Compute position and call the child. */
|
/* Third loop: Compute position and call the child. */
|
||||||
uint position = pre; // Place to put next child relative to origin of the container.
|
uint position = pre; // Place to put next child relative to origin of the container.
|
||||||
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
|
for (const auto &child_wid : this->children) {
|
||||||
uint child_x = x + (rtl ? child_wid->padding.right : child_wid->padding.left);
|
uint child_x = x + (rtl ? child_wid->padding.right : child_wid->padding.left);
|
||||||
uint child_height = child_wid->current_y;
|
uint child_height = child_wid->current_y;
|
||||||
|
|
||||||
|
@ -1974,7 +1928,7 @@ void NWidgetMatrix::SetCount(int count)
|
||||||
* Then multiply that by the height of a widget, and add the pre
|
* Then multiply that by the height of a widget, and add the pre
|
||||||
* and post spacing "offsets". */
|
* and post spacing "offsets". */
|
||||||
count = CeilDiv(count, this->sb->IsVertical() ? this->widgets_x : this->widgets_y);
|
count = CeilDiv(count, this->sb->IsVertical() ? this->widgets_x : this->widgets_y);
|
||||||
count *= (this->sb->IsVertical() ? this->head->smallest_y : this->head->smallest_x) + this->pip_inter;
|
count *= (this->sb->IsVertical() ? this->children.front()->smallest_y : this->children.front()->smallest_x) + this->pip_inter;
|
||||||
if (count > 0) count -= this->pip_inter; // We counted an inter too much in the multiplication above
|
if (count > 0) count -= this->pip_inter; // We counted an inter too much in the multiplication above
|
||||||
count += this->pip_pre + this->pip_post;
|
count += this->pip_pre + this->pip_post;
|
||||||
this->sb->SetCount(count);
|
this->sb->SetCount(count);
|
||||||
|
@ -2002,15 +1956,14 @@ int NWidgetMatrix::GetCurrentElement() const
|
||||||
|
|
||||||
void NWidgetMatrix::SetupSmallestSize(Window *w)
|
void NWidgetMatrix::SetupSmallestSize(Window *w)
|
||||||
{
|
{
|
||||||
assert(this->head != nullptr);
|
assert(this->children.size() == 1);
|
||||||
assert(this->head->next == nullptr);
|
|
||||||
|
|
||||||
this->head->SetupSmallestSize(w);
|
this->children.front()->SetupSmallestSize(w);
|
||||||
|
|
||||||
Dimension padding = { (uint)this->pip_pre + this->pip_post, (uint)this->pip_pre + this->pip_post};
|
Dimension padding = { (uint)this->pip_pre + this->pip_post, (uint)this->pip_pre + this->pip_post};
|
||||||
Dimension size = {this->head->smallest_x + padding.width, this->head->smallest_y + padding.height};
|
Dimension size = {this->children.front()->smallest_x + padding.width, this->children.front()->smallest_y + padding.height};
|
||||||
Dimension fill = {0, 0};
|
Dimension fill = {0, 0};
|
||||||
Dimension resize = {this->pip_inter + this->head->smallest_x, this->pip_inter + this->head->smallest_y};
|
Dimension resize = {this->pip_inter + this->children.front()->smallest_x, this->pip_inter + this->children.front()->smallest_y};
|
||||||
|
|
||||||
if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
|
if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
|
||||||
|
|
||||||
|
@ -2032,8 +1985,8 @@ void NWidgetMatrix::AssignSizePosition(SizingType, int x, int y, uint given_widt
|
||||||
this->current_y = given_height;
|
this->current_y = given_height;
|
||||||
|
|
||||||
/* Determine the size of the widgets, and the number of visible widgets on each of the axis. */
|
/* Determine the size of the widgets, and the number of visible widgets on each of the axis. */
|
||||||
this->widget_w = this->head->smallest_x + this->pip_inter;
|
this->widget_w = this->children.front()->smallest_x + this->pip_inter;
|
||||||
this->widget_h = this->head->smallest_y + this->pip_inter;
|
this->widget_h = this->children.front()->smallest_y + this->pip_inter;
|
||||||
|
|
||||||
/* Account for the pip_inter is between widgets, so we need to account for that when
|
/* Account for the pip_inter is between widgets, so we need to account for that when
|
||||||
* the division assumes pip_inter is used for all widgets. */
|
* the division assumes pip_inter is used for all widgets. */
|
||||||
|
@ -2072,7 +2025,7 @@ NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y)
|
||||||
this->current_element = (widget_row + start_y) * this->widgets_x + start_x + widget_col;
|
this->current_element = (widget_row + start_y) * this->widgets_x + start_x + widget_col;
|
||||||
if (this->current_element >= this->count) return nullptr;
|
if (this->current_element >= this->count) return nullptr;
|
||||||
|
|
||||||
NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
|
NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->children.front().get());
|
||||||
assert(child != nullptr);
|
assert(child != nullptr);
|
||||||
child->AssignSizePosition(ST_RESIZE,
|
child->AssignSizePosition(ST_RESIZE,
|
||||||
this->pos_x + (rtl ? this->pip_post - widget_col * this->widget_w : this->pip_pre + widget_col * this->widget_w) + base_offs_x,
|
this->pos_x + (rtl ? this->pip_post - widget_col * this->widget_w : this->pip_pre + widget_col * this->widget_w) + base_offs_x,
|
||||||
|
@ -2096,7 +2049,7 @@ NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y)
|
||||||
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
|
||||||
|
|
||||||
/* Get the appropriate offsets so we can draw the right widgets. */
|
/* Get the appropriate offsets so we can draw the right widgets. */
|
||||||
NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
|
NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->children.front().get());
|
||||||
assert(child != nullptr);
|
assert(child != nullptr);
|
||||||
int start_x, start_y, base_offs_x, base_offs_y;
|
int start_x, start_y, base_offs_x, base_offs_y;
|
||||||
this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
|
this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
|
||||||
|
|
|
@ -235,9 +235,6 @@ public:
|
||||||
int pos_x; ///< Horizontal position of top-left corner of the widget in the window.
|
int pos_x; ///< Horizontal position of top-left corner of the widget in the window.
|
||||||
int pos_y; ///< Vertical position of top-left corner of the widget in the window.
|
int pos_y; ///< Vertical position of top-left corner of the widget in the window.
|
||||||
|
|
||||||
NWidgetBase *next; ///< Pointer to next widget in container. Managed by parent container widget.
|
|
||||||
NWidgetBase *prev; ///< Pointer to previous widget in container. Managed by parent container widget.
|
|
||||||
|
|
||||||
RectPadding padding; ///< Padding added to the widget. Managed by parent container widget. (parent container may swap left and right for RTL)
|
RectPadding padding; ///< Padding added to the widget. Managed by parent container widget. (parent container may swap left and right for RTL)
|
||||||
RectPadding uz_padding; ///< Unscaled padding, for resize calculation.
|
RectPadding uz_padding; ///< Unscaled padding, for resize calculation.
|
||||||
|
|
||||||
|
@ -446,8 +443,7 @@ inline bool NWidgetCore::IsDisabled() const
|
||||||
*/
|
*/
|
||||||
class NWidgetContainer : public NWidgetBase {
|
class NWidgetContainer : public NWidgetBase {
|
||||||
public:
|
public:
|
||||||
NWidgetContainer(WidgetType tp);
|
NWidgetContainer(WidgetType tp) : NWidgetBase(tp) { }
|
||||||
~NWidgetContainer();
|
|
||||||
|
|
||||||
void AdjustPaddingForZoom() override;
|
void AdjustPaddingForZoom() override;
|
||||||
void Add(NWidgetBase *wid);
|
void Add(NWidgetBase *wid);
|
||||||
|
@ -457,13 +453,12 @@ public:
|
||||||
NWidgetCore *GetWidgetFromPos(int x, int y) override;
|
NWidgetCore *GetWidgetFromPos(int x, int y) override;
|
||||||
|
|
||||||
/** Return whether the container is empty. */
|
/** Return whether the container is empty. */
|
||||||
inline bool IsEmpty() { return head == nullptr; }
|
inline bool IsEmpty() { return this->children.empty(); }
|
||||||
|
|
||||||
NWidgetBase *GetWidgetOfType(WidgetType tp) override;
|
NWidgetBase *GetWidgetOfType(WidgetType tp) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NWidgetBase *head; ///< Pointer to first widget in container.
|
std::vector<std::unique_ptr<NWidgetBase>> children; ///< Child widgets in contaier.
|
||||||
NWidgetBase *tail; ///< Pointer to last widget in container.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Display planes with zero size for #NWidgetStacked. */
|
/** Display planes with zero size for #NWidgetStacked. */
|
||||||
|
|
Loading…
Reference in New Issue