mirror of https://github.com/OpenTTD/OpenTTD
Fix: Apply widget's internal padding to scrollbar capacity/position. (#12801)
For non-WWT_MATRIX widgets, scrollbars need to take account of the internal padding used for the widget. This is not normally noticeable as framerect padding is only 2 extra pixelspull/12803/head
parent
e0bcb54a4b
commit
91fd082e93
|
@ -1836,8 +1836,8 @@ public:
|
|||
|
||||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST);
|
||||
this->hscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST);
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST, WidgetDimensions::scaled.framerect.Vertical());
|
||||
this->hscroll->SetCapacityFromWidget(this, WID_ID_INDUSTRY_LIST, WidgetDimensions::scaled.framerect.Horizontal());
|
||||
}
|
||||
|
||||
void OnEditboxChanged(WidgetID wid) override
|
||||
|
@ -3178,7 +3178,7 @@ struct IndustryCargoesWindow : public Window {
|
|||
|
||||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_IC_PANEL, WidgetDimensions::scaled.framerect.top + CargoesField::small_height);
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_IC_PANEL, WidgetDimensions::scaled.framerect.Vertical() + CargoesField::small_height);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -796,8 +796,8 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
|
||||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_NS_FILE_LIST);
|
||||
this->vscroll2->SetCapacityFromWidget(this, WID_NS_AVAIL_LIST);
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_NS_FILE_LIST, WidgetDimensions::scaled.framerect.Vertical());
|
||||
this->vscroll2->SetCapacityFromWidget(this, WID_NS_AVAIL_LIST, WidgetDimensions::scaled.framerect.Vertical());
|
||||
}
|
||||
|
||||
void SetStringParameters(WidgetID widget) const override
|
||||
|
@ -1027,7 +1027,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
case WID_NS_FILE_LIST: { // Select an active GRF.
|
||||
ResetObjectToPlace();
|
||||
|
||||
uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST);
|
||||
uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST, WidgetDimensions::scaled.framerect.top);
|
||||
|
||||
GRFConfig *c;
|
||||
for (c = this->actives; c != nullptr && i > 0; c = c->next, i--) {}
|
||||
|
@ -1090,7 +1090,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
case WID_NS_AVAIL_LIST: { // Select a non-active GRF.
|
||||
ResetObjectToPlace();
|
||||
|
||||
auto it = this->vscroll2->GetScrolledItemFromWidget(this->avails, pt.y, this, WID_NS_AVAIL_LIST);
|
||||
auto it = this->vscroll2->GetScrolledItemFromWidget(this->avails, pt.y, this, WID_NS_AVAIL_LIST, WidgetDimensions::scaled.framerect.top);
|
||||
this->active_sel = nullptr;
|
||||
CloseWindowByClass(WC_GRF_PARAMETERS);
|
||||
if (it != this->avails.end()) {
|
||||
|
@ -1385,7 +1385,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
for (from_prev = &this->actives; *from_prev != this->active_sel; from_prev = &(*from_prev)->next, from_pos++) {}
|
||||
|
||||
/* Gets the drag-and-drop destination offset. Ignore the last dummy line. */
|
||||
int to_pos = std::min(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST), this->vscroll->GetCount() - 2);
|
||||
int to_pos = std::min(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST, WidgetDimensions::scaled.framerect.top), this->vscroll->GetCount() - 2);
|
||||
if (to_pos != from_pos) { // Don't move NewGRF file over itself.
|
||||
/* Get pointer to destination position. */
|
||||
GRFConfig **to_prev = &this->actives;
|
||||
|
@ -1403,7 +1403,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
this->InvalidateData();
|
||||
}
|
||||
} else if (this->avail_sel != nullptr) {
|
||||
int to_pos = std::min(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST), this->vscroll->GetCount() - 1);
|
||||
int to_pos = std::min(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST, WidgetDimensions::scaled.framerect.top), this->vscroll->GetCount() - 1);
|
||||
this->AddGRFToActive(to_pos);
|
||||
}
|
||||
} else if (widget == WID_NS_AVAIL_LIST && this->active_sel != nullptr) {
|
||||
|
@ -1427,7 +1427,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
|||
|
||||
if (widget == WID_NS_FILE_LIST && (this->active_sel != nullptr || this->avail_sel != nullptr)) {
|
||||
/* An NewGRF file is dragged over the active list. */
|
||||
int to_pos = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST);
|
||||
int to_pos = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NS_FILE_LIST, WidgetDimensions::scaled.framerect.top);
|
||||
/* Skip the last dummy line if the source is from the active list. */
|
||||
to_pos = std::min(to_pos, this->vscroll->GetCount() - (this->active_sel != nullptr ? 2 : 1));
|
||||
|
||||
|
@ -2167,7 +2167,7 @@ struct SavePresetWindow : public Window {
|
|||
|
||||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_SVP_PRESET_LIST);
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_SVP_PRESET_LIST, WidgetDimensions::scaled.framerect.Vertical());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1165,7 +1165,7 @@ struct MessageHistoryWindow : Window {
|
|||
* could be invalid, so ensure it's correct now. Potentially this means that item clicked on might be
|
||||
* different as well. */
|
||||
this->vscroll->SetCount(std::size(_news));
|
||||
auto ni = this->vscroll->GetScrolledItemFromWidget(_news, pt.y, this, widget);
|
||||
auto ni = this->vscroll->GetScrolledItemFromWidget(_news, pt.y, this, widget, WidgetDimensions::scaled.framerect.top);
|
||||
if (ni == std::end(_news)) return;
|
||||
|
||||
ShowNewsMessage(ni);
|
||||
|
@ -1174,7 +1174,7 @@ struct MessageHistoryWindow : Window {
|
|||
|
||||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND);
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_MH_BACKGROUND, WidgetDimensions::scaled.framerect.Vertical());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1586,7 +1586,7 @@ public:
|
|||
void OnResize() override
|
||||
{
|
||||
/* Update the scroll bar */
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST, WidgetDimensions::scaled.framerect.Vertical());
|
||||
}
|
||||
|
||||
static inline HotkeyList hotkeys{"order", {
|
||||
|
|
|
@ -1192,7 +1192,7 @@ struct ScriptDebugWindow : public Window {
|
|||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_SCRD_LOG_PANEL, WidgetDimensions::scaled.framerect.Vertical());
|
||||
this->hscroll->SetCapacityFromWidget(this, WID_SCRD_LOG_PANEL);
|
||||
this->hscroll->SetCapacityFromWidget(this, WID_SCRD_LOG_PANEL, WidgetDimensions::scaled.framerect.Horizontal());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -581,7 +581,7 @@ public:
|
|||
{
|
||||
switch (widget) {
|
||||
case WID_STL_LIST: {
|
||||
auto it = this->vscroll->GetScrolledItemFromWidget(this->stations, pt.y, this, WID_STL_LIST);
|
||||
auto it = this->vscroll->GetScrolledItemFromWidget(this->stations, pt.y, this, WID_STL_LIST, WidgetDimensions::scaled.framerect.top);
|
||||
if (it == this->stations.end()) return; // click out of list bound
|
||||
|
||||
const Station *st = *it;
|
||||
|
|
|
@ -235,7 +235,7 @@ struct SubsidyListWindow : Window {
|
|||
|
||||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_SUL_PANEL);
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_SUL_PANEL, WidgetDimensions::scaled.framerect.Vertical());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -587,7 +587,7 @@ void TextfileWindow::AfterLoadMarkdown()
|
|||
/* virtual */ void TextfileWindow::OnResize()
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_TF_BACKGROUND, WidgetDimensions::scaled.frametext.Vertical());
|
||||
this->hscroll->SetCapacityFromWidget(this, WID_TF_BACKGROUND);
|
||||
this->hscroll->SetCapacityFromWidget(this, WID_TF_BACKGROUND, WidgetDimensions::scaled.framerect.Horizontal());
|
||||
|
||||
this->SetupScrollbars(false);
|
||||
}
|
||||
|
|
|
@ -996,7 +996,7 @@ public:
|
|||
|
||||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_TD_LIST);
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_TD_LIST, WidgetDimensions::scaled.framerect.Vertical());
|
||||
}
|
||||
|
||||
void OnEditboxChanged(WidgetID wid) override
|
||||
|
|
Loading…
Reference in New Issue