mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
Implement centred labels
This commit is contained in:
3
distribution/openrct2.d.ts
vendored
3
distribution/openrct2.d.ts
vendored
@@ -1997,9 +1997,12 @@ declare global {
|
||||
interface LabelWidget extends WidgetBase {
|
||||
type: 'label';
|
||||
text?: string;
|
||||
textAlign?: TextAlignment;
|
||||
onChange?: (index: number) => void;
|
||||
}
|
||||
|
||||
type TextAlignment = "left" | "centred";
|
||||
|
||||
type SortOrder = "none" | "ascending" | "descending";
|
||||
|
||||
type ScrollbarType = "none" | "horizontal" | "vertical" | "both";
|
||||
|
||||
@@ -357,8 +357,16 @@ static void WidgetTextCentred(rct_drawpixelinfo* dpi, rct_window* w, rct_widgeti
|
||||
stringId = STR_STRING;
|
||||
ft.Add<utf8*>(widget->string);
|
||||
}
|
||||
DrawTextEllipsised(
|
||||
dpi, { (topLeft.x + r + 1) / 2 - 1, topLeft.y }, widget->width() - 2, stringId, ft, colour, TextAlignment::CENTRE);
|
||||
|
||||
ScreenCoordsXY coords = { (topLeft.x + r + 1) / 2 - 1, topLeft.y };
|
||||
if (widget->type == WindowWidgetType::LabelCentred)
|
||||
{
|
||||
gfx_draw_string_centred_wrapped(dpi, ft.Data(), coords, widget->width() - 2, stringId, colour);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextEllipsised(dpi, coords, widget->width() - 2, stringId, ft, colour, TextAlignment::CENTRE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,7 +406,16 @@ static void WidgetText(rct_drawpixelinfo* dpi, rct_window* w, rct_widgetindex wi
|
||||
stringId = STR_STRING;
|
||||
ft.Add<utf8*>(widget->string);
|
||||
}
|
||||
DrawTextEllipsised(dpi, { l + 1, t }, r - l, stringId, ft, colour);
|
||||
|
||||
ScreenCoordsXY coords = { l + 1, t };
|
||||
if (widget->type == WindowWidgetType::LabelCentred)
|
||||
{
|
||||
gfx_draw_string_centred_wrapped(dpi, ft.Data(), coords, r - l, stringId, colour);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextEllipsised(dpi, coords, r - l, stringId, ft, colour);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -93,6 +93,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
std::string Name;
|
||||
ImageId Image;
|
||||
std::string Text;
|
||||
TextAlignment TextAlign;
|
||||
colour_t Colour;
|
||||
std::string Tooltip;
|
||||
std::vector<std::string> Items;
|
||||
@@ -175,10 +176,18 @@ namespace OpenRCT2::Ui::Windows
|
||||
result.SelectedIndex = AsOrDefault(desc["selectedIndex"], 0);
|
||||
result.OnChange = desc["onChange"];
|
||||
}
|
||||
else if (result.Type == "groupbox" || result.Type == "label")
|
||||
else if (result.Type == "groupbox")
|
||||
{
|
||||
result.Text = ProcessString(desc["text"]);
|
||||
}
|
||||
else if (result.Type == "label")
|
||||
{
|
||||
result.Text = ProcessString(desc["text"]);
|
||||
if (ProcessString(desc["textAlign"]) == "centred")
|
||||
{
|
||||
result.TextAlign = TextAlignment::CENTRE;
|
||||
}
|
||||
}
|
||||
else if (result.Type == "listview")
|
||||
{
|
||||
result.ListViewColumns = FromDuk<std::vector<ListViewColumn>>(desc["columns"]);
|
||||
@@ -976,6 +985,10 @@ namespace OpenRCT2::Ui::Windows
|
||||
widget.type = WindowWidgetType::Label;
|
||||
widget.string = const_cast<utf8*>(desc.Text.c_str());
|
||||
widget.flags |= WIDGET_FLAGS::TEXT_IS_STRING;
|
||||
if (desc.TextAlign == TextAlignment::CENTRE)
|
||||
{
|
||||
widget.type = WindowWidgetType::LabelCentred;
|
||||
}
|
||||
widgetList.push_back(widget);
|
||||
}
|
||||
else if (desc.Type == "listview")
|
||||
|
||||
@@ -652,6 +652,33 @@ namespace OpenRCT2::Scripting
|
||||
{
|
||||
dukglue_set_base_class<ScWidget, ScLabelWidget>(ctx);
|
||||
dukglue_register_property(ctx, &ScLabelWidget::text_get, &ScLabelWidget::text_set, "text");
|
||||
dukglue_register_property(ctx, &ScLabelWidget::textAlign_get, &ScLabelWidget::textAlign_set, "textAlign");
|
||||
}
|
||||
|
||||
private:
|
||||
std::string textAlign_get() const
|
||||
{
|
||||
auto* widget = GetWidget();
|
||||
if (widget != nullptr)
|
||||
{
|
||||
if (widget->type == WindowWidgetType::LabelCentred)
|
||||
{
|
||||
return "centred";
|
||||
}
|
||||
}
|
||||
return "left";
|
||||
}
|
||||
|
||||
void textAlign_set(const std::string& value)
|
||||
{
|
||||
auto* widget = GetWidget();
|
||||
if (widget != nullptr)
|
||||
{
|
||||
if (value == "centred")
|
||||
widget->type = WindowWidgetType::LabelCentred;
|
||||
else
|
||||
widget->type = WindowWidgetType::Label;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -946,6 +973,7 @@ namespace OpenRCT2::Scripting
|
||||
case WindowWidgetType::Groupbox:
|
||||
return GetObjectAsDukValue(ctx, std::make_shared<ScGroupBoxWidget>(c, n, widgetIndex));
|
||||
case WindowWidgetType::Label:
|
||||
case WindowWidgetType::LabelCentred:
|
||||
return GetObjectAsDukValue(ctx, std::make_shared<ScLabelWidget>(c, n, widgetIndex));
|
||||
case WindowWidgetType::Scroll:
|
||||
return GetObjectAsDukValue(ctx, std::make_shared<ScListViewWidget>(c, n, widgetIndex));
|
||||
|
||||
Reference in New Issue
Block a user