mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-23 14:48:06 +00:00
Compare commits
5 Commits
47c8248833
...
bb0b619402
Author | SHA1 | Date | |
---|---|---|---|
|
bb0b619402 | ||
|
08e4c5b198 | ||
|
b1c72a0647 | ||
|
aee4baee1c | ||
|
fbf8251996 |
@ -111,7 +111,6 @@ TextElementConfig :: struct {
|
|||||||
lineHeight: u16,
|
lineHeight: u16,
|
||||||
wrapMode: TextWrapMode,
|
wrapMode: TextWrapMode,
|
||||||
textAlignment: TextAlignment,
|
textAlignment: TextAlignment,
|
||||||
hashStringContents: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageElementConfig :: struct {
|
ImageElementConfig :: struct {
|
||||||
|
21
clay.h
21
clay.h
@ -360,6 +360,8 @@ typedef CLAY_PACKED_ENUM {
|
|||||||
CLAY_TEXT_ALIGN_CENTER,
|
CLAY_TEXT_ALIGN_CENTER,
|
||||||
// Horizontally aligns wrapped lines of text to the right hand side of their bounding box.
|
// Horizontally aligns wrapped lines of text to the right hand side of their bounding box.
|
||||||
CLAY_TEXT_ALIGN_RIGHT,
|
CLAY_TEXT_ALIGN_RIGHT,
|
||||||
|
// The boundingBox passed to the TEXT render command may be smaller than the measured text size. The renderer must then decide how to shorten the text to make it fit
|
||||||
|
CLAY_TEXT_ALIGN_SHRINK,
|
||||||
} Clay_TextAlignment;
|
} Clay_TextAlignment;
|
||||||
|
|
||||||
// Controls various functionality related to text elements.
|
// Controls various functionality related to text elements.
|
||||||
@ -1670,6 +1672,7 @@ Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Cl
|
|||||||
item.nextIndex = hashItem->nextIndex;
|
item.nextIndex = hashItem->nextIndex;
|
||||||
if (hashItem->generation <= context->generation) { // First collision - assume this is the "same" element
|
if (hashItem->generation <= context->generation) { // First collision - assume this is the "same" element
|
||||||
hashItem->elementId = elementId; // Make sure to copy this across. If the stringId reference has changed, we should update the hash item to use the new one.
|
hashItem->elementId = elementId; // Make sure to copy this across. If the stringId reference has changed, we should update the hash item to use the new one.
|
||||||
|
hashItem->idAlias = idAlias;
|
||||||
hashItem->generation = context->generation + 1;
|
hashItem->generation = context->generation + 1;
|
||||||
hashItem->layoutElement = layoutElement;
|
hashItem->layoutElement = layoutElement;
|
||||||
hashItem->debugData->collision = false;
|
hashItem->debugData->collision = false;
|
||||||
@ -2804,14 +2807,24 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
float offset = (currentElementBoundingBox.width - wrappedLine->dimensions.width);
|
float offset = (currentElementBoundingBox.width - wrappedLine->dimensions.width);
|
||||||
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_LEFT) {
|
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_LEFT || textElementConfig->textAlignment == CLAY_TEXT_ALIGN_SHRINK) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_CENTER) {
|
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_CENTER) {
|
||||||
offset /= 2;
|
offset /= 2;
|
||||||
}
|
}
|
||||||
|
Clay_BoundingBox textBoundingBox = {
|
||||||
|
currentElementBoundingBox.x + offset,
|
||||||
|
currentElementBoundingBox.y + yPosition,
|
||||||
|
wrappedLine->dimensions.width,
|
||||||
|
wrappedLine->dimensions.height
|
||||||
|
};
|
||||||
|
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_SHRINK && boundingBox.width > currentElementBoundingBox.width) {
|
||||||
|
boundingBox.width = currentElementBoundingBox.width;
|
||||||
|
}
|
||||||
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
||||||
.boundingBox = { currentElementBoundingBox.x + offset, currentElementBoundingBox.y + yPosition, wrappedLine->dimensions.width, wrappedLine->dimensions.height },
|
.boundingBox = { currentElementBoundingBox.x + offset, currentElementBoundingBox.y + yPosition, wrappedLine->dimensions.width, wrappedLine->dimensions.height },
|
||||||
|
.boundingBox = textBoundingBox,
|
||||||
.renderData = { .text = {
|
.renderData = { .text = {
|
||||||
.stringContents = CLAY__INIT(Clay_StringSlice) { .length = wrappedLine->line.length, .chars = wrappedLine->line.chars, .baseChars = currentElement->childrenOrTextContent.textElementData->text.chars },
|
.stringContents = CLAY__INIT(Clay_StringSlice) { .length = wrappedLine->line.length, .chars = wrappedLine->line.chars, .baseChars = currentElement->childrenOrTextContent.textElementData->text.chars },
|
||||||
.textColor = textElementConfig->textColor,
|
.textColor = textElementConfig->textColor,
|
||||||
@ -3810,10 +3823,10 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) {
|
|||||||
Clay_LayoutElementHashMapItem *mapItem = Clay__GetHashMapItem(currentElement->id); // TODO think of a way around this, maybe the fact that it's essentially a binary tree limits the cost, but the worst case is not great
|
Clay_LayoutElementHashMapItem *mapItem = Clay__GetHashMapItem(currentElement->id); // TODO think of a way around this, maybe the fact that it's essentially a binary tree limits the cost, but the worst case is not great
|
||||||
int32_t clipElementId = Clay__int32_tArray_GetValue(&context->layoutElementClipElementIds, (int32_t)(currentElement - context->layoutElements.internalArray));
|
int32_t clipElementId = Clay__int32_tArray_GetValue(&context->layoutElementClipElementIds, (int32_t)(currentElement - context->layoutElements.internalArray));
|
||||||
Clay_LayoutElementHashMapItem *clipItem = Clay__GetHashMapItem(clipElementId);
|
Clay_LayoutElementHashMapItem *clipItem = Clay__GetHashMapItem(clipElementId);
|
||||||
Clay_BoundingBox elementBox = mapItem->boundingBox;
|
|
||||||
elementBox.x -= root->pointerOffset.x;
|
|
||||||
elementBox.y -= root->pointerOffset.y;
|
|
||||||
if (mapItem) {
|
if (mapItem) {
|
||||||
|
Clay_BoundingBox elementBox = mapItem->boundingBox;
|
||||||
|
elementBox.x -= root->pointerOffset.x;
|
||||||
|
elementBox.y -= root->pointerOffset.y;
|
||||||
if ((Clay__PointIsInsideRect(position, elementBox)) && (clipElementId == 0 || (Clay__PointIsInsideRect(position, clipItem->boundingBox)))) {
|
if ((Clay__PointIsInsideRect(position, elementBox)) && (clipElementId == 0 || (Clay__PointIsInsideRect(position, clipItem->boundingBox)))) {
|
||||||
if (mapItem->onHoverFunction) {
|
if (mapItem->onHoverFunction) {
|
||||||
mapItem->onHoverFunction(mapItem->elementId, context->pointerInfo, mapItem->hoverFunctionUserData);
|
mapItem->onHoverFunction(mapItem->elementId, context->pointerInfo, mapItem->hoverFunctionUserData);
|
||||||
|
Loading…
Reference in New Issue
Block a user