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);
116 const int32_t combinedStartX = rect.x + textAlignmentOffsetX;
119 .y = blockY + (combinedHeight - iconMeasurement.
height) / 2,
120 .w = iconMeasurement.
width,
121 .h = iconMeasurement.
height
123 out.
textRect.x = rect.x + iconMeasurement.
width + iconTextGap;
124 out.
textRect.w = std::max(0, rect.w - iconMeasurement.
width - iconTextGap);
125 out.
textRect.y = blockY + (combinedHeight - textHeight) / 2;
130 const int32_t combinedStartX = rect.x + textAlignmentOffsetX;
132 .x = combinedStartX + textWidth + iconTextGap,
133 .y = blockY + (combinedHeight - iconMeasurement.
height) / 2,
134 .w = iconMeasurement.
width,
135 .h = iconMeasurement.
height
138 out.
textRect.w = rect.w - iconTextGap - iconMeasurement.
width;
139 out.
textRect.y = blockY + (combinedHeight - textHeight) / 2;
144 const int32_t combinedStartX = rect.x + textAlignmentOffsetX;
145 const int32_t iconCenterX = combinedStartX + combinedWidth / 2;
147 .x = iconCenterX - iconMeasurement.
width / 2,
149 .w = iconMeasurement.
width,
150 .h = iconMeasurement.
height
160 const int32_t combinedStartX = rect.x + textAlignmentOffsetX;
161 const int32_t iconCenterX = combinedStartX + combinedWidth / 2;
167 .x = iconCenterX - iconMeasurement.
width / 2,
168 .y = blockY + textHeight + iconTextGap,
169 .w = iconMeasurement.
width,
170 .h = iconMeasurement.
height
176 (void)combinedHeight;
189 if (!hasIcon)
return rectWidth;
191 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:182
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:53
int32_t width
Definition gui_text_system.h:54
int32_t height
Definition gui_text_system.h:55
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:406