MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / drawListViewItem

Function drawListViewItem

source/ui/controls/listViewItem.cpp:37–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void drawListViewItem(const ListViewItem& item) {
38 float width = ImGui::GetColumnWidth()-GlobalSettings::scaleFloatUI(4.0f);
39 ImVec2 startPos = ImGui::GetCursorPos();
40 const float iconVertGap = GlobalSettings::scaleFloatUI(5);
41
42 ImVec2 textSize = ImGui::CalcTextSize(item.text.c_str());
43 if (textSize.x>width) {
44 ImVec2 fullTextSize = ImGui::CalcTextSize(item.text.c_str(), nullptr, false, width);
45 ImFont* font = ImGui::GetFont();
46 const char* start = item.text.c_str();
47 const char* end = start + item.text.length();
48 const char* text = start;
49 const char* p = font->CalcWordWrapPositionA(font->Scale, text, text+item.text.length(), width);
50
51 ImGui::PushID(start);
52 //ImGui::SetCursorPosX(ImGui::GetCursorPosX()+(float)(width/2-fullTextSize.x/2));
53 int lineCount = (int)(fullTextSize.y/textSize.y+0.5);
54 if (lineCount>UiSettings::MAX_NUMBER_OF_LINES_FOR_APP_LIST_VIEW_TEXT) {
55 lineCount = UiSettings::MAX_NUMBER_OF_LINES_FOR_APP_LIST_VIEW_TEXT;
56 }
57 fullTextSize.y=ImGui::GetStyle().ItemSpacing.y*(lineCount-1)+lineCount*textSize.y;
58 ImVec2 fullItemSize = fullTextSize;
59 fullItemSize.x = width;
60 fullItemSize.y += UiSettings::ICON_SIZE + iconVertGap * 3;
61 if (ImGui::Selectable("", false, ImGuiSelectableFlags_AllowRightClick, fullItemSize)) {
62 item.onSelect(ImGui::IsMouseReleased(ImGuiMouseButton_Right));
63 }
64 if (item.icon) {
65 ImGui::SetCursorPosX(startPos.x);
66 ImGui::SetCursorPosY(startPos.y+ iconVertGap);
67 drawIcon(item);
68 }
69 ImGui::SetCursorPosY(startPos.y + (float)UiSettings::ICON_SIZE + iconVertGap * 2);
70 ImGui::PopID();
71 int i=0;
72 while (p<end && i<UiSettings::MAX_NUMBER_OF_LINES_FOR_APP_LIST_VIEW_TEXT-1) {
73 i++;
74 BString line = BString::copy(text, (int)(p - text)).trim();
75 textSize = ImGui::CalcTextSize(line.c_str());
76 ImGui::SetCursorPosX(ImGui::GetCursorPosX()+(width/2-textSize.x/2));
77 SAFE_IMGUI_TEXT(line.c_str());
78 text = p;
79 while(text[0]==' ') {
80 text++;
81 }
82 p = font->CalcWordWrapPositionA(font->Scale, text, text+item.text.length(), width);
83 if (p == text) { // didn't find a break;
84 p = getTextThatFits(p, width);
85 }
86 }
87 if (text<end) {
88 BString line;
89 if (p == end) {
90 line = BString::copy(text);
91 } else {
92 float w = width - ImGui::CalcTextSize("...").x;
93 line = BString::copy(text, (int)(getTextThatFits(text, w) - text));
94 line = line + "...";

Callers 1

drawListViewFunction · 0.85

Calls 6

drawIconFunction · 0.85
getTextThatFitsFunction · 0.85
CalcWordWrapPositionAMethod · 0.80
trimMethod · 0.80
c_strMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected