diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -95,6 +95,8 @@ this->vscroll.cap = this->nested_array[SLW_LIST]->current_y / this->resize.step_height; this->resize.height -= this->height % this->resize.step_height; // minimum height +>>>> Don't touch this height variable, the nested widget system takes care of it. For minimal size setting, use UpdateWidgetSize(). +>>>> Most likely some or all of these variables will become obsolete. /* Create initial list */ this->signs.ForceRebuild(); @@ -113,6 +115,8 @@ { switch (widget) { case SLW_LIST: { // The list has to be drawn +>>>> Comment has little added value, it seems. + /* No signs? */ uint y = r.top + 2; // Offset from top of widget if (this->vscroll.count == 0) { @@ -121,6 +125,9 @@ } /* Start drawing the signs */ +>>>> Comment is unclear, I'd expect something "At least one sign available." to state it is a next case w.r.t. the "No signs?" above. +>>>> Lika above, 'start drawing' is a bit obvious in a DrawWdidget function. + for (uint16 i = this->vscroll.pos; i < this->vscroll.cap + this->vscroll.pos && i < this->vscroll.count; i++) { const Sign *si = this->signs[i]; @@ -144,6 +151,7 @@ { if (widget == SLW_LIST) { uint32 id_v = (pt.y - this->nested_array[SLW_LIST]->pos_y - 1) / this->resize.step_height; +>>>> just 'uint' would be enough, I think. (not a real problem though) if (id_v >= this->vscroll.cap) return; id_v += this->vscroll.pos; @@ -162,12 +170,21 @@ virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize) { if (widget == SLW_LIST) resize->height = max(FONT_HEIGHT_NORMAL, GetSpriteSize(SPR_PLAYER_ICON).height); +>>>> 1. By changing *size, you can set minimal size of the widget, and thus of the window. (upon entering it has the value of SetMinimalSize() +>>>> and/or some basic size calculation results). +>>>> With most widgets, there is a small gap between the box around the content of a widget, and the widget border. +>>>> That distance is fixed and provided to you as 'padding'. Be sure to add it to the widget content before returning the maxdim() in *size. +>>>> 2. I don't see a width calculation of the list widget to estimate the longest possible sign. +>>>> If that is intentional, it can be considered ok. If it is not intentional, plz consider what the best solution is. +>>>> If the answer is not to do it, a short comment with a reasoning is probably beneficial. } virtual void OnInvalidateData(int data) { if (data == 0) { // New or deleted sign // Rebuild the list +>>>> 1. Code style violation of comment. +>>>> 2. Comment and code kind of say the same thing, so the former doesn't add much imho. this->signs.ForceRebuild(); this->BuildSignsList(); this->InvalidateWidget(SLW_CAPTION); @@ -177,6 +194,7 @@ } this->SortSignsList(); // Try to sort the list after each change +>>>> Comment does not add much, } }; @@ -188,6 +206,7 @@ EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(WWT_PANEL, COLOUR_GREY, SLW_LIST), SetMinimalSize(346, 124), SetResize(1, 10), SetFill(true, true), EndContainer(), +>>>> No whitespace at the end of a line! NWidget(NWID_VERTICAL), NWidget(WWT_SCROLLBAR, COLOUR_GREY, SLW_SCROLLBAR), NWidget(WWT_RESIZEBOX, COLOUR_GREY, SLW_RESIZE),