| 71 | FontPicker::FontPicker(GUIManager& gui): Element(gui) {} |
| 72 | |
| 73 | void FontPicker::layout(const Clay_ElementId& id, std::string* newFontName, const FontPickerData& newData) { |
| 74 | using namespace ElementHelpers; |
| 75 | fontName = newFontName; |
| 76 | data = newData; |
| 77 | |
| 78 | sorted_font_list(gui); |
| 79 | |
| 80 | auto sortedFontListValIt = std::find(sortedFontList.begin(), sortedFontList.end(), *fontName); |
| 81 | size_t val = sortedFontListValIt != sortedFontList.end() ? sortedFontListValIt - sortedFontList.begin() : std::numeric_limits<size_t>::max(); |
| 82 | |
| 83 | const float ENTRY_HEIGHT = 25.0f; |
| 84 | |
| 85 | CLAY(id, { |
| 86 | .layout = { |
| 87 | .sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIT(0)}, |
| 88 | .childGap = 4 |
| 89 | } |
| 90 | }) { |
| 91 | auto textboxElement = ElementHelpers::input_text(gui, "Font textbox", fontName, { |
| 92 | .onEdit = [&] { |
| 93 | auto newFontName = get_valid_font_name(); |
| 94 | if(newFontName.has_value()) { |
| 95 | *fontName = newFontName.value(); |
| 96 | jumpToFontName = true; |
| 97 | if(data.onFontChange) data.onFontChange(); |
| 98 | } |
| 99 | gui.set_to_layout(); |
| 100 | }, |
| 101 | .onSelect = [&] { |
| 102 | dropdownOpen = true; |
| 103 | gui.set_to_layout(); |
| 104 | } |
| 105 | }); |
| 106 | |
| 107 | auto dropdownButton = svg_icon_button(gui, "Open font dropdown", "data/icons/droparrowbold.svg", { |
| 108 | .size = SMALL_BUTTON_SIZE, |
| 109 | .onClick = [&] { |
| 110 | dropdownOpen = !dropdownOpen; |
| 111 | } |
| 112 | }); |
| 113 | |
| 114 | if(dropdownOpen) { |
| 115 | gui.set_z_index(gui.get_z_index() + 1, [&] { |
| 116 | gui.element<LayoutElement>("DROPDOWN", [&](LayoutElement*, const Clay_ElementId& lId) { |
| 117 | Clay_ElementData dropdownElemData = Clay_GetElementData(lId); |
| 118 | float calculatedDropdownMaxHeight = 0.0f; |
| 119 | if(dropdownElemData.found) { |
| 120 | calculatedDropdownMaxHeight = std::max(gui.io.windowSize.y() - dropdownElemData.boundingBox.y - 2.0f, 0.0f); |
| 121 | calculatedDropdownMaxHeight = std::min<float>(calculatedDropdownMaxHeight, 300); |
| 122 | } |
| 123 | CLAY(lId, { |
| 124 | .layout = { |
| 125 | .sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIT(0, calculatedDropdownMaxHeight)}, |
| 126 | .childGap = 0 |
| 127 | }, |
| 128 | .backgroundColor = convert_vec4<Clay_Color>(gui.io.theme->backColor1), |
| 129 | .cornerRadius = CLAY_CORNER_RADIUS(4), |
| 130 | .floating = { |
nothing calls this directly
no test coverage detected