21 switch (horizontalAlignment)
33 switch (verticalAlignment)
70 .iconRect =
IntRect{ 0, 0, 0, 0 },
85 int32_t combinedWidth = textWidth;
86 int32_t combinedHeight = textHeight;
92 combinedWidth = textWidth + iconTextGap + iconMeasurement.
width;
93 combinedHeight = std::max(textHeight, iconMeasurement.
height);
97 combinedWidth = std::max(textWidth, iconMeasurement.
width);
98 combinedHeight = textHeight + iconTextGap + iconMeasurement.
height;
102 const int32_t textAlignmentOffsetX =
HorizontalAlignOffset(horizontalAlignment, rect.w, combinedWidth);
106 const int32_t blockY = rect.y +
VerticalAlignOffset(verticalAlignment, rect.h, combinedHeight);
113 const int32_t combinedStartX = rect.x + textAlignmentOffsetX;
116 .y = blockY + (combinedHeight - iconMeasurement.
height) / 2,
117 .w = iconMeasurement.
width,
118 .h = iconMeasurement.
height
120 out.
textRect.x = combinedStartX + iconMeasurement.
width + iconTextGap;
122 out.
textRect.y = blockY + (combinedHeight - textHeight) / 2;
127 const int32_t combinedStartX = rect.x + textAlignmentOffsetX;
129 .x = combinedStartX + textWidth + iconTextGap,
130 .y = blockY + (combinedHeight - iconMeasurement.
height) / 2,
131 .w = iconMeasurement.
width,
132 .h = iconMeasurement.
height
135 out.
textRect.w = rect.w - iconTextGap - iconMeasurement.
width;
136 out.
textRect.y = blockY + (combinedHeight - textHeight) / 2;
141 const int32_t combinedStartX = rect.x + textAlignmentOffsetX;
142 const int32_t iconCenterX = combinedStartX + combinedWidth / 2;
144 .x = iconCenterX - iconMeasurement.
width / 2,
146 .w = iconMeasurement.
width,
147 .h = iconMeasurement.
height
157 const int32_t combinedStartX = rect.x + textAlignmentOffsetX;
158 const int32_t iconCenterX = combinedStartX + combinedWidth / 2;
162 out.
textRect.h = textHeight - iconMeasurement.
height - iconTextGap;
164 .x = iconCenterX - iconMeasurement.
width / 2,
165 .y = blockY + textHeight + iconTextGap,
166 .w = iconMeasurement.
width,
167 .h = iconMeasurement.
height
173 (void)combinedHeight;
186 if (!hasIcon)
return rectWidth;
188 return std::max(0, rectWidth - iconTextGap - iconMeasurement.
width);
IconSide
Where an element's icon sits relative to its text (CSS: -tachyon-icon-side).
Definition gui_style.h:249
TextAlign
Alignment of text in its box (CSS: text-align, -tachyon-vertical-text-align).
Definition gui_style_text.h:68
@ Bottom
Definition gui_style.h:255
@ None
Definition gui_style.h:250
@ Right
Definition gui_style.h:253
@ Left
Definition gui_style.h:252
@ Top
Definition gui_style.h:254
@ Bottom
Horizontal: n/a (behaves like right). Vertical: bottom.
Definition gui_style_text.h:75
@ Center
Horizontal and vertical: center.
Definition gui_style_text.h:70
@ End
Horizontal: the language's end (right for LTR, left for RTL). Vertical: bottom.
Definition gui_style_text.h:71
@ Right
Horizontal: right. Vertical: n/a (behaves like bottom).
Definition gui_style_text.h:73
@ Start
Horizontal: the language's start (left for LTR, right for RTL). Vertical: top.
Definition gui_style_text.h:69
int32_t IconAwareLayoutMaxWidth(int32_t rectWidth, const IconMeasurement &iconMeasurement, IconSide iconSide, int32_t iconTextGap, bool hasIcon)
The max width to lay text out in: rectWidth minus the icon and gap for a Left / Right icon,...
Definition gui_icon_text_placement.h:179
int32_t HorizontalAlignOffset(TextAlign horizontalAlignment, int32_t boxWidth, int32_t contentWidth)
X offset, in pixels, of contentWidth content aligned inside a boxWidth box.
Definition gui_icon_text_placement.h:19
IconTextPlacement ComputeIconTextPlacement(const IntRect &rect, int32_t textWidth, int32_t textHeight, const IconMeasurement &iconMeasurement, IconSide iconSide, int32_t iconTextGap, TextAlign horizontalAlignment, TextAlign verticalAlignment=TextAlign::Start)
Definition gui_icon_text_placement.h:58
int32_t VerticalAlignOffset(TextAlign verticalAlignment, int32_t boxHeight, int32_t contentHeight)
Definition gui_icon_text_placement.h:31
Definition gui_logging.h:24
Definition gui_text_system.h:54
int32_t width
Definition gui_text_system.h:55
int32_t height
Definition gui_text_system.h:56
Placement of a text + icon pair inside rect:
Definition gui_icon_text_placement.h:53
IntRect textRect
Definition gui_icon_text_placement.h:54
IntRect iconRect
Definition gui_icon_text_placement.h:55
Definition gui_base_types.h:407