* Set focus within this window to the given widget. The function however doesn't change which window has focus. * @param widget_index Index of the widget in the window to set the focus to. * @return Focus has changed. */
| 485 | * @return Focus has changed. |
| 486 | */ |
| 487 | bool Window::SetFocusedWidget(WidgetID widget_index) |
| 488 | { |
| 489 | NWidgetCore *widget = this->GetWidget<NWidgetCore>(widget_index); |
| 490 | assert(widget != nullptr); /* Setting focus to a non-existing widget is a bad idea. */ |
| 491 | |
| 492 | if (this->nested_focus != nullptr) { |
| 493 | /* Do nothing if widget_index is already focused. */ |
| 494 | if (widget == this->nested_focus) return false; |
| 495 | |
| 496 | /* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */ |
| 497 | this->nested_focus->SetDirty(this); |
| 498 | if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus(); |
| 499 | } |
| 500 | |
| 501 | this->nested_focus = widget; |
| 502 | if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus(); |
| 503 | return true; |
| 504 | } |
| 505 | |
| 506 | std::string Window::GetWidgetString([[maybe_unused]] WidgetID widget, StringID stringid) const |
| 507 | { |
no test coverage detected