Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
ExampleAppLog Struct Reference
+ Collaboration diagram for ExampleAppLog:

Public Member Functions

 ExampleAppLog ()
 
void Clear ()
 
void AddLog (const char *fmt,...) IM_FMTARGS(2)
 
void Draw (const char *title, bool *p_open=NULL)
 

Public Attributes

ImGuiTextBuffer Buf
 
ImGuiTextFilter Filter
 
ImVector< int > LineOffsets
 
bool AutoScroll
 

Detailed Description

Constructor & Destructor Documentation

◆ ExampleAppLog()

ExampleAppLog::ExampleAppLog ( )
inline
6652 {
6653 AutoScroll = true;
6654 Clear();
6655 }
bool AutoScroll
Definition imgui_demo.cpp:6649
void Clear()
Definition imgui_demo.cpp:6657

References AutoScroll, and Clear().

+ Here is the call graph for this function:

Member Function Documentation

◆ AddLog()

void ExampleAppLog::AddLog ( const char *  fmt,
  ... 
)
inline
6665 {
6666 int old_size = Buf.size();
6667 va_list args;
6668 va_start(args, fmt);
6669 Buf.appendfv(fmt, args);
6670 va_end(args);
6671 for (int new_size = Buf.size(); old_size < new_size; old_size++)
6672 if (Buf[old_size] == '\n')
6673 LineOffsets.push_back(old_size + 1);
6674 }
ImGuiTextBuffer Buf
Definition imgui_demo.cpp:6646
ImVector< int > LineOffsets
Definition imgui_demo.cpp:6648
int size() const
Definition imgui.h:2059
IMGUI_API void appendfv(const char *fmt, va_list args) IM_FMTLIST(2)
Definition imgui.cpp:2164
void push_back(const T &v)
Definition imgui.h:1696

References ImGuiTextBuffer::appendfv(), Buf, LineOffsets, ImVector< T >::push_back(), and ImGuiTextBuffer::size().

+ Here is the call graph for this function:

◆ Clear()

void ExampleAppLog::Clear ( )
inline
6658 {
6659 Buf.clear();
6662 }
void clear()
Definition imgui.h:2061
void clear()
Definition imgui.h:1678

References Buf, ImVector< T >::clear(), ImGuiTextBuffer::clear(), LineOffsets, and ImVector< T >::push_back().

Referenced by ExampleAppLog(), and Draw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Draw()

void ExampleAppLog::Draw ( const char *  title,
bool *  p_open = NULL 
)
inline
6677 {
6678 if (!ImGui::Begin(title, p_open))
6679 {
6680 ImGui::End();
6681 return;
6682 }
6683
6684 // Options menu
6685 if (ImGui::BeginPopup("Options"))
6686 {
6687 ImGui::Checkbox("Auto-scroll", &AutoScroll);
6689 }
6690
6691 // Main window
6692 if (ImGui::Button("Options"))
6693 ImGui::OpenPopup("Options");
6695 bool clear = ImGui::Button("Clear");
6697 bool copy = ImGui::Button("Copy");
6699 Filter.Draw("Filter", -100.0f);
6700
6703
6704 if (clear)
6705 Clear();
6706 if (copy)
6708
6710 const char* buf = Buf.begin();
6711 const char* buf_end = Buf.end();
6712 if (Filter.IsActive())
6713 {
6714 // In this example we don't use the clipper when Filter is enabled.
6715 // This is because we don't have a random access on the result on our filter.
6716 // A real application processing logs with ten of thousands of entries may want to store the result of
6717 // search/filter.. especially if the filtering function is not trivial (e.g. reg-exp).
6718 for (int line_no = 0; line_no < LineOffsets.Size; line_no++)
6719 {
6720 const char* line_start = buf + LineOffsets[line_no];
6721 const char* line_end = (line_no + 1 < LineOffsets.Size) ? (buf + LineOffsets[line_no + 1] - 1) : buf_end;
6722 if (Filter.PassFilter(line_start, line_end))
6723 ImGui::TextUnformatted(line_start, line_end);
6724 }
6725 }
6726 else
6727 {
6728 // The simplest and easy way to display the entire buffer:
6729 // ImGui::TextUnformatted(buf_begin, buf_end);
6730 // And it'll just work. TextUnformatted() has specialization for large blob of text and will fast-forward
6731 // to skip non-visible lines. Here we instead demonstrate using the clipper to only process lines that are
6732 // within the visible area.
6733 // If you have tens of thousands of items and their processing cost is non-negligible, coarse clipping them
6734 // on your side is recommended. Using ImGuiListClipper requires
6735 // - A) random access into your data
6736 // - B) items all being the same height,
6737 // both of which we can handle since we an array pointing to the beginning of each line of text.
6738 // When using the filter (in the block of code above) we don't have random access into the data to display
6739 // anymore, which is why we don't use the clipper. Storing or skimming through the search result would make
6740 // it possible (and would be recommended if you want to search through tens of thousands of entries).
6741 ImGuiListClipper clipper;
6742 clipper.Begin(LineOffsets.Size);
6743 while (clipper.Step())
6744 {
6745 for (int line_no = clipper.DisplayStart; line_no < clipper.DisplayEnd; line_no++)
6746 {
6747 const char* line_start = buf + LineOffsets[line_no];
6748 const char* line_end = (line_no + 1 < LineOffsets.Size) ? (buf + LineOffsets[line_no + 1] - 1) : buf_end;
6749 ImGui::TextUnformatted(line_start, line_end);
6750 }
6751 }
6752 clipper.End();
6753 }
6755
6758
6760 ImGui::End();
6761 }
@ ImGuiStyleVar_ItemSpacing
Definition imgui.h:1492
@ ImGuiWindowFlags_HorizontalScrollbar
Definition imgui.h:927
IMGUI_API bool BeginPopup(const char *str_id, ImGuiWindowFlags flags=0)
Definition imgui.cpp:8311
IMGUI_API void PopStyleVar(int count=1)
Definition imgui.cpp:2565
IMGUI_API void Separator()
Definition imgui_widgets.cpp:1419
IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f)
Definition imgui.cpp:7455
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition imgui_widgets.cpp:715
IMGUI_API float GetScrollY()
Definition imgui.cpp:7894
IMGUI_API void End()
Definition imgui.cpp:6366
IMGUI_API bool Checkbox(const char *label, bool *v)
Definition imgui_widgets.cpp:1071
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition imgui.cpp:5722
IMGUI_API bool BeginChild(const char *str_id, const ImVec2 &size=ImVec2(0, 0), bool border=false, ImGuiWindowFlags flags=0)
Definition imgui.cpp:5019
IMGUI_API void LogToClipboard(int auto_open_depth=-1)
Definition imgui.cpp:10233
IMGUI_API void TextUnformatted(const char *text, const char *text_end=NULL)
Definition imgui_widgets.cpp:255
IMGUI_API void OpenPopup(const char *str_id, ImGuiPopupFlags popup_flags=0)
Definition imgui.cpp:8121
IMGUI_API void EndPopup()
Definition imgui.cpp:8357
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val)
Definition imgui.cpp:2537
IMGUI_API float GetScrollMaxY()
Definition imgui.cpp:7906
IMGUI_API void SetScrollHereY(float center_y_ratio=0.5f)
Definition imgui.cpp:7992
IMGUI_API void EndChild()
Definition imgui.cpp:5031
ImGuiTextFilter Filter
Definition imgui_demo.cpp:6647
Definition imgui.h:2138
IMGUI_API void End()
Definition imgui.cpp:2304
IMGUI_API void Begin(int items_count, float items_height=-1.0f)
Definition imgui.cpp:2286
int DisplayStart
Definition imgui.h:2139
int DisplayEnd
Definition imgui.h:2140
IMGUI_API bool Step()
Definition imgui.cpp:2316
const char * end() const
Definition imgui.h:2058
const char * begin() const
Definition imgui.h:2057
bool IsActive() const
Definition imgui.h:2030
IMGUI_API bool PassFilter(const char *text, const char *text_end=NULL) const
Definition imgui.cpp:2087
IMGUI_API bool Draw(const char *label="Filter (inc,-exc)", float width=0.0f)
Definition imgui.cpp:2038
Definition imgui.h:245
int Size
Definition imgui.h:1655

References AutoScroll, ImGuiTextBuffer::begin(), ImGui::Begin(), ImGuiListClipper::Begin(), ImGui::BeginChild(), ImGui::BeginPopup(), Buf, ImGui::Button(), ImGui::Checkbox(), Clear(), ImGuiListClipper::DisplayEnd, ImGuiListClipper::DisplayStart, ImGuiTextFilter::Draw(), ImGui::End(), ImGuiListClipper::End(), ImGuiTextBuffer::end(), ImGui::EndChild(), ImGui::EndPopup(), Filter, ImGui::GetScrollMaxY(), ImGui::GetScrollY(), ImGuiStyleVar_ItemSpacing, ImGuiWindowFlags_HorizontalScrollbar, ImGuiTextFilter::IsActive(), LineOffsets, ImGui::LogToClipboard(), ImGui::OpenPopup(), ImGuiTextFilter::PassFilter(), ImGui::PopStyleVar(), ImGui::PushStyleVar(), ImGui::SameLine(), ImGui::Separator(), ImGui::SetScrollHereY(), ImVector< T >::Size, ImGuiListClipper::Step(), and ImGui::TextUnformatted().

+ Here is the call graph for this function:

Member Data Documentation

◆ AutoScroll

bool ExampleAppLog::AutoScroll

Referenced by ExampleAppLog(), and Draw().

◆ Buf

ImGuiTextBuffer ExampleAppLog::Buf

Referenced by AddLog(), Clear(), and Draw().

◆ Filter

ImGuiTextFilter ExampleAppLog::Filter

Referenced by Draw().

◆ LineOffsets

ImVector<int> ExampleAppLog::LineOffsets

Referenced by AddLog(), Clear(), and Draw().


The documentation for this struct was generated from the following file: