MCPcopy Create free account
hub / github.com/chrxh/alien / FavoriteButton

Function FavoriteButton

external/ImFileDialog/ImFileDialog.cpp:224–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222 return ret;
223 }
224 bool FavoriteButton(const char* label, bool isFavorite)
225 {
226 ImGuiContext& g = *GImGui;
227 ImGuiWindow* window = g.CurrentWindow;
228
229 ImVec2 pos = window->DC.CursorPos;
230 bool ret = ImGui::InvisibleButton(label, ImVec2(GUI_ELEMENT_SIZE, GUI_ELEMENT_SIZE));
231
232 bool hovered = ImGui::IsItemHovered();
233 bool active = ImGui::IsItemActive();
234
235 float size = g.LastItemData.Rect.Max.x - g.LastItemData.Rect.Min.x;
236
237 int numPoints = 5;
238 float innerRadius = size / 4;
239 float outerRadius = size / 2;
240 float angle = PI / numPoints;
241 ImVec2 center = ImVec2(pos.x + size / 2, pos.y + size / 2);
242
243 // fill
244 if (isFavorite || hovered || active) {
245 ImU32 fillColor = 0xff00ffff;// ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[ImGuiCol_Text]);
246 if (hovered || active)
247 fillColor = ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[active ? ImGuiCol_HeaderActive : ImGuiCol_HeaderHovered]);
248
249 // since there is no PathFillConcave, fill first the inner part, then the triangles
250 // inner
251 window->DrawList->PathClear();
252 for (int i = 1; i < numPoints * 2; i += 2)
253 window->DrawList->PathLineTo(ImVec2(center.x + innerRadius * sin(i * angle), center.y - innerRadius * cos(i * angle)));
254 window->DrawList->PathFillConvex(fillColor);
255
256 // triangles
257 for (int i = 0; i < numPoints; i++) {
258 window->DrawList->PathClear();
259
260 int pIndex = i * 2;
261 window->DrawList->PathLineTo(ImVec2(center.x + outerRadius * sin(pIndex * angle), center.y - outerRadius * cos(pIndex * angle)));
262 window->DrawList->PathLineTo(ImVec2(center.x + innerRadius * sin((pIndex + 1) * angle), center.y - innerRadius * cos((pIndex + 1) * angle)));
263 window->DrawList->PathLineTo(ImVec2(center.x + innerRadius * sin((pIndex - 1) * angle), center.y - innerRadius * cos((pIndex - 1) * angle)));
264
265 window->DrawList->PathFillConvex(fillColor);
266 }
267 }
268
269 // outline
270 window->DrawList->PathClear();
271 for (int i = 0; i < numPoints * 2; i++) {
272 float radius = i & 1 ? innerRadius : outerRadius;
273 window->DrawList->PathLineTo(ImVec2(center.x + radius * sin(i * angle), center.y - radius * cos(i * angle)));
274 }
275 window->DrawList->PathStroke(ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[ImGuiCol_Text]), true, 2.0f);
276
277 return ret;
278 }
279 bool FileIcon(const char* label, bool isSelected, ImTextureID icon, ImVec2 size, bool hasPreview, int previewWidth, int previewHeight)
280 {
281 ImGuiStyle& style = ImGui::GetStyle();

Callers 1

m_renderFileDialogMethod · 0.85

Calls 1

ImVec2Class · 0.85

Tested by

no test coverage detected