This is provided as a convenience for being an often requested feature. FIXME-STYLE: we delayed adding as there is a larger plan to revamp the styling system. Because of this we currently don't provide many styling options for this widget (e.g. hovered/active colors are automatically inferred from a single color).
| 1516 | // Because of this we currently don't provide many styling options for this widget |
| 1517 | // (e.g. hovered/active colors are automatically inferred from a single color). |
| 1518 | bool ImGui::TextLink(const char* label) |
| 1519 | { |
| 1520 | ImGuiWindow* window = GetCurrentWindow(); |
| 1521 | if (window->SkipItems) |
| 1522 | return false; |
| 1523 | |
| 1524 | ImGuiContext& g = *GImGui; |
| 1525 | const ImGuiID id = window->GetID(label); |
| 1526 | const char* label_end = FindRenderedTextEnd(label); |
| 1527 | |
| 1528 | ImVec2 pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); |
| 1529 | ImVec2 size = CalcTextSize(label, label_end, false); |
| 1530 | ImRect bb(pos, pos + size); |
| 1531 | ItemSize(size, 0.0f); |
| 1532 | if (!ItemAdd(bb, id)) |
| 1533 | return false; |
| 1534 | |
| 1535 | bool hovered, held; |
| 1536 | bool pressed = ButtonBehavior(bb, id, &hovered, &held); |
| 1537 | RenderNavCursor(bb, id); |
| 1538 | |
| 1539 | if (hovered) |
| 1540 | SetMouseCursor(ImGuiMouseCursor_Hand); |
| 1541 | |
| 1542 | ImVec4 text_colf = g.Style.Colors[ImGuiCol_TextLink]; |
| 1543 | ImVec4 line_colf = text_colf; |
| 1544 | { |
| 1545 | // FIXME-STYLE: Read comments above. This widget is NOT written in the same style as some earlier widgets, |
| 1546 | // as we are currently experimenting/planning a different styling system. |
| 1547 | float h, s, v; |
| 1548 | ColorConvertRGBtoHSV(text_colf.x, text_colf.y, text_colf.z, h, s, v); |
| 1549 | if (held || hovered) |
| 1550 | { |
| 1551 | v = ImSaturate(v + (held ? 0.4f : 0.3f)); |
| 1552 | h = ImFmod(h + 0.02f, 1.0f); |
| 1553 | } |
| 1554 | ColorConvertHSVtoRGB(h, s, v, text_colf.x, text_colf.y, text_colf.z); |
| 1555 | v = ImSaturate(v - 0.20f); |
| 1556 | ColorConvertHSVtoRGB(h, s, v, line_colf.x, line_colf.y, line_colf.z); |
| 1557 | } |
| 1558 | |
| 1559 | float line_y = bb.Max.y + ImFloor(g.FontBaked->Descent * g.FontBakedScale * 0.20f); |
| 1560 | window->DrawList->AddLineH(bb.Min.x, bb.Max.x, line_y, GetColorU32(line_colf), 1.0f * (float)(int)g.Style._MainScale); // FIXME-TEXT: Underline mode // FIXME-DPI |
| 1561 | |
| 1562 | PushStyleColor(ImGuiCol_Text, GetColorU32(text_colf)); |
| 1563 | RenderText(bb.Min, label, label_end, false); |
| 1564 | PopStyleColor(); |
| 1565 | |
| 1566 | IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); |
| 1567 | return pressed; |
| 1568 | } |
| 1569 | |
| 1570 | bool ImGui::TextLinkOpenURL(const char* label, const char* url) |
| 1571 | { |
nothing calls this directly
no test coverage detected