feat: allow vertical toolbar to be centered
This commit is contained in:
@@ -1495,12 +1495,13 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == NWID_HORIZONTAL) {
|
||||
//w->window_desc->default_width_trad = nbuttons * this->smallest_x;
|
||||
w->window_desc->pref_width = nbuttons * this->smallest_x;
|
||||
} else {
|
||||
//w->window_desc->default_height_trad = nbuttons * this->smallest_y;
|
||||
w->window_desc->pref_height = nbuttons * this->smallest_y;
|
||||
uint given_width, arrangable_count, button_count, spacer_count;
|
||||
const WidgetID *arrangement = GetButtonArrangement(given_width, arrangable_count, button_count, spacer_count);
|
||||
w->window_desc->pref_height = arrangable_count * this->smallest_y;
|
||||
}
|
||||
_toolbar_width = nbuttons * this->smallest_x;
|
||||
}
|
||||
@@ -1565,7 +1566,11 @@ public:
|
||||
}
|
||||
button_i++;
|
||||
} else {
|
||||
child_wid->current_x = child_wid->smallest_x;
|
||||
if (type == NWID_HORIZONTAL) {
|
||||
child_wid->current_x = child_wid->smallest_x;
|
||||
} else {
|
||||
child_wid->current_y = child_wid->smallest_y;
|
||||
}
|
||||
}
|
||||
if (type == NWID_HORIZONTAL) {
|
||||
child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
|
||||
@@ -2280,7 +2285,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
/* virtual */ const WidgetID *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const
|
||||
const WidgetID *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const override
|
||||
{
|
||||
// Ultra-compact arrangement, ultra-huge buttons.
|
||||
// No WID_TN_SHIFT, WID_TN_STORY, WID_TN_GOAL, and WID_TN_LEAGUE buttons.
|
||||
@@ -2906,9 +2911,13 @@ static std::unique_ptr<NWidgetBase> MakeMainToolbar()
|
||||
}
|
||||
|
||||
auto spacer= std::make_unique<NWidgetSpacer>(0, 0);
|
||||
spacer->SetMinimalSize(20, 20);
|
||||
auto ctrl_btn = std::make_unique<NWidgetLeaf>(WWT_TEXTBTN, COLOUR_GREY, WID_TN_CTRL, STR_TABLET_CTRL, STR_TABLET_CTRL_TOOLTIP);
|
||||
ctrl_btn->SetMinimalSize(20, 20);
|
||||
auto shift_btn = std::make_unique<NWidgetLeaf>(WWT_TEXTBTN, COLOUR_GREY, WID_TN_SHIFT, STR_TABLET_SHIFT, STR_TABLET_SHIFT_TOOLTIP);
|
||||
shift_btn->SetMinimalSize(20, 20);
|
||||
auto close_btn = std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TN_DELETE, STR_TABLET_CLOSE, STR_TABLET_CLOSE_TOOLTIP);
|
||||
close_btn->SetMinimalSize(20, 20);
|
||||
|
||||
hor->Add(std::move(spacer));
|
||||
hor->Add(std::move(ctrl_btn));
|
||||
@@ -2933,12 +2942,21 @@ static std::unique_ptr<NWidgetBase> MakeVerticalLeftToolbar()
|
||||
{
|
||||
auto tb = std::make_unique<NWidgetVerticalToolbarContainer>(NWidgetVerticalToolbarContainer::Side::LEFT);
|
||||
for (uint i = 0; i <= WID_TN_SWITCH_BAR; i++) {
|
||||
tb->Add(std::make_unique<NWidgetLeaf>(i == WID_TN_SAVE ? WWT_IMGBTN_2 : WWT_IMGBTN, COLOUR_GREY, i, toolbar_button_sprites[i], STR_TOOLBAR_TOOLTIP_PAUSE_GAME + i));
|
||||
auto leaf = std::make_unique<NWidgetLeaf>(i == WID_TN_SAVE ? WWT_IMGBTN_2 : WWT_IMGBTN, COLOUR_GREY, i, toolbar_button_sprites[i], STR_TOOLBAR_TOOLTIP_PAUSE_GAME + i);
|
||||
leaf->SetMinimalSize(20, 20);
|
||||
tb->Add(std::move(leaf));
|
||||
}
|
||||
|
||||
tb->Add(std::make_unique<NWidgetLeaf>(WWT_TEXTBTN, COLOUR_GREY, WID_TN_CTRL, STR_TABLET_CTRL, STR_TABLET_CTRL_TOOLTIP));
|
||||
tb->Add(std::make_unique<NWidgetLeaf>(WWT_TEXTBTN, COLOUR_GREY, WID_TN_SHIFT, STR_TABLET_SHIFT, STR_TABLET_SHIFT_TOOLTIP));
|
||||
tb->Add(std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TN_DELETE, STR_TABLET_CLOSE, STR_TABLET_CLOSE_TOOLTIP));
|
||||
std::array<std::unique_ptr<NWidgetLeaf>, 3> rem = {
|
||||
std::make_unique<NWidgetLeaf>(WWT_TEXTBTN, COLOUR_GREY, WID_TN_CTRL, STR_TABLET_CTRL, STR_TABLET_CTRL_TOOLTIP),
|
||||
std::make_unique<NWidgetLeaf>(WWT_TEXTBTN, COLOUR_GREY, WID_TN_SHIFT, STR_TABLET_SHIFT, STR_TABLET_SHIFT_TOOLTIP),
|
||||
std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TN_DELETE, STR_TABLET_CLOSE, STR_TABLET_CLOSE_TOOLTIP)
|
||||
};
|
||||
|
||||
for (auto&& leaf: rem) {
|
||||
leaf->SetMinimalSize(20, 20);
|
||||
tb->Add(std::move(leaf));
|
||||
}
|
||||
|
||||
return tb;
|
||||
}
|
||||
@@ -2948,7 +2966,7 @@ static const NWidgetPart _nested_toolbar_vertical_left_widgets[] = {
|
||||
};
|
||||
|
||||
static WindowDesc _toolb_vertical_left_desc(__FILE__, __LINE__,
|
||||
WDP_MANUAL, nullptr, 22, 480,
|
||||
WDP_MANUAL, nullptr, 0, 0,
|
||||
WC_MAIN_TOOLBAR, WC_NONE,
|
||||
WDF_NO_FOCUS | WDF_NO_CLOSE,
|
||||
std::begin(_nested_toolbar_vertical_left_widgets), std::end(_nested_toolbar_vertical_left_widgets),
|
||||
@@ -2959,12 +2977,21 @@ static std::unique_ptr<NWidgetBase> MakeVerticalRightToolbar()
|
||||
{
|
||||
auto tb = std::make_unique<NWidgetVerticalToolbarContainer>(NWidgetVerticalToolbarContainer::Side::RIGHT);
|
||||
for (uint i = 0; i <= WID_TN_SWITCH_BAR; i++) {
|
||||
tb->Add(std::make_unique<NWidgetLeaf>(i == WID_TN_SAVE ? WWT_IMGBTN_2 : WWT_IMGBTN, COLOUR_GREY, i, toolbar_button_sprites[i], STR_TOOLBAR_TOOLTIP_PAUSE_GAME + i));
|
||||
auto leaf = std::make_unique<NWidgetLeaf>(i == WID_TN_SAVE ? WWT_IMGBTN_2 : WWT_IMGBTN, COLOUR_GREY, i, toolbar_button_sprites[i], STR_TOOLBAR_TOOLTIP_PAUSE_GAME + i);
|
||||
leaf->SetMinimalSize(20, 20);
|
||||
tb->Add(std::move(leaf));
|
||||
}
|
||||
|
||||
tb->Add(std::make_unique<NWidgetLeaf>(WWT_TEXTBTN, COLOUR_GREY, WID_TN_CTRL, STR_TABLET_CTRL, STR_TABLET_CTRL_TOOLTIP));
|
||||
tb->Add(std::make_unique<NWidgetLeaf>(WWT_TEXTBTN, COLOUR_GREY, WID_TN_SHIFT, STR_TABLET_SHIFT, STR_TABLET_SHIFT_TOOLTIP));
|
||||
tb->Add(std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TN_DELETE, STR_TABLET_CLOSE, STR_TABLET_CLOSE_TOOLTIP));
|
||||
std::array<std::unique_ptr<NWidgetLeaf>, 3> rem = {
|
||||
std::make_unique<NWidgetLeaf>(WWT_TEXTBTN, COLOUR_GREY, WID_TN_CTRL, STR_TABLET_CTRL, STR_TABLET_CTRL_TOOLTIP),
|
||||
std::make_unique<NWidgetLeaf>(WWT_TEXTBTN, COLOUR_GREY, WID_TN_SHIFT, STR_TABLET_SHIFT, STR_TABLET_SHIFT_TOOLTIP),
|
||||
std::make_unique<NWidgetLeaf>(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TN_DELETE, STR_TABLET_CLOSE, STR_TABLET_CLOSE_TOOLTIP)
|
||||
};
|
||||
|
||||
for (auto&& leaf: rem) {
|
||||
leaf->SetMinimalSize(20, 20);
|
||||
tb->Add(std::move(leaf));
|
||||
}
|
||||
|
||||
return tb;
|
||||
}
|
||||
@@ -2974,7 +3001,7 @@ static const NWidgetPart _nested_toolbar_vertical_right_widgets[] = {
|
||||
};
|
||||
|
||||
static WindowDesc _toolb_vertical_right_desc(__FILE__, __LINE__,
|
||||
WDP_MANUAL, nullptr, 22, 480,
|
||||
WDP_MANUAL, nullptr, 0, 0,
|
||||
WC_MAIN_TOOLBAR_RIGHT, WC_NONE,
|
||||
WDF_NO_FOCUS | WDF_NO_CLOSE,
|
||||
std::begin(_nested_toolbar_vertical_right_widgets), std::end(_nested_toolbar_vertical_right_widgets),
|
||||
|
||||
@@ -412,6 +412,8 @@ bool VideoDriver_SDL_Base::PollEvent()
|
||||
case SDL_BUTTON_RIGHT:
|
||||
_right_button_down = true;
|
||||
_right_button_clicked = true;
|
||||
_right_button_down_pos.x = ev.button.x;
|
||||
_right_button_down_pos.y = ev.button.y;
|
||||
break;
|
||||
|
||||
default: break;
|
||||
|
||||
@@ -3664,6 +3664,24 @@ static int PositionWindow(Window *w, WindowClass clss, int setting)
|
||||
return w->left;
|
||||
}
|
||||
|
||||
static int PositionVerticalToolbar(Window *w, WindowClass clss, int setting)
|
||||
{
|
||||
if (w == nullptr || w->window_class != clss) {
|
||||
w = FindWindowById(clss, 0);
|
||||
}
|
||||
if (w == nullptr) return 0;
|
||||
|
||||
auto old_top = w->top;
|
||||
switch (setting) {
|
||||
case 1: w->top = (_screen.height - w->height) / 2; break;
|
||||
case 2: w->top = _screen.height - w->height; break;
|
||||
default: w->top = 0; break;
|
||||
}
|
||||
if (w->viewport != nullptr) w->viewport->top += w->top - old_top;
|
||||
AddDirtyBlock(w->left, 0, w->left + w->width, _screen.height); // invalidate the whole collumn
|
||||
return w->top;
|
||||
}
|
||||
|
||||
/**
|
||||
* (Re)position main toolbar window at the screen.
|
||||
* @param w Window structure of the main toolbar window, may also be \c nullptr.
|
||||
@@ -3671,7 +3689,11 @@ static int PositionWindow(Window *w, WindowClass clss, int setting)
|
||||
*/
|
||||
int PositionMainToolbar(Window *w)
|
||||
{
|
||||
if (_settings_client.gui.vertical_toolbar && _game_mode != GM_EDITOR) return 0; /* Always at the left */
|
||||
if (_settings_client.gui.vertical_toolbar && _game_mode != GM_EDITOR) {
|
||||
PositionVerticalToolbar(w, WC_MAIN_TOOLBAR, _settings_client.gui.toolbar_pos);
|
||||
PositionVerticalToolbar(nullptr, WC_MAIN_TOOLBAR_RIGHT, _settings_client.gui.toolbar_pos);
|
||||
return 0; /* Always at the left */
|
||||
}
|
||||
Debug(misc, 5, "Repositioning Main Toolbar...");
|
||||
return PositionWindow(w, WC_MAIN_TOOLBAR, _settings_client.gui.toolbar_pos);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user