From 636e37d1832dbcb3aa12c915ede5a9d26d231d24 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 19 Apr 2021 12:12:07 +0100 Subject: Codechange: Add internal widget alignment property, along with widget part. --- src/widget_type.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/widget_type.h') diff --git a/src/widget_type.h b/src/widget_type.h index a5b323b87..97f64ba1b 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -89,6 +89,7 @@ enum WidgetType { WPT_DATATIP, ///< Widget part for specifying data and tooltip. WPT_PADDING, ///< Widget part for specifying a padding. WPT_PIPSPACE, ///< Widget part for specifying pre/inter/post space for containers. + WPT_ALIGNMENT, ///< Widget part for specifying text/image alignment. WPT_ENDCONTAINER, ///< Widget part to denote end of a container. WPT_FUNCTION, ///< Widget part for calling a user function. WPT_SCROLLBAR, ///< Widget part for attaching a scrollbar. @@ -296,6 +297,7 @@ public: void SetIndex(int index); void SetDataTip(uint32 widget_data, StringID tool_tip); void SetToolTip(StringID tool_tip); + void SetAlignment(StringAlignment align); inline void SetLowered(bool lowered); inline bool IsLowered() const; @@ -315,6 +317,7 @@ public: StringID tool_tip; ///< Tooltip of the widget. @see Widget::tootips int scrollbar_index; ///< Index of an attached scrollbar. TextColour highlight_colour; ///< Colour of highlight. + StringAlignment align; ///< Alignment of text/image within widget. }; /** @@ -905,6 +908,14 @@ struct NWidgetPartTextLines { FontSize size; ///< Font size of text lines. }; +/** + * Widget part for setting text/image alignment within a widget. + * @ingroup NestedWidgetParts + */ +struct NWidgetPartAlignment { + StringAlignment align; ///< Alignment of text/image. +}; + /** * Pointer to function returning a nested widget. * @param biggest_index Pointer to storage for collecting the biggest index used in the nested widget. @@ -926,6 +937,7 @@ struct NWidgetPart { NWidgetPartPaddings padding; ///< Part with paddings. NWidgetPartPIP pip; ///< Part with pre/inter/post spaces. NWidgetPartTextLines text_lines; ///< Part with text line data. + NWidgetPartAlignment align; ///< Part with internal alignment. NWidgetFunctionType *func_ptr; ///< Part with a function call. NWidContainerFlags cont_flags; ///< Part with container flags. } u; @@ -984,6 +996,21 @@ static inline NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSi return part; } +/** + * Widget part function for setting the alignment of text/images. + * @param align Alignment of text/image within widget. + * @ingroup NestedWidgetParts + */ +static inline NWidgetPart SetAlignment(StringAlignment align) +{ + NWidgetPart part; + + part.type = WPT_ALIGNMENT; + part.u.align.align = align; + + return part; +} + /** * Widget part function for setting filling. * @param fill_x Horizontal filling step from minimal size. -- cgit v1.2.3-54-g00ecf