Skip to content

Commit

Permalink
Surface: Don't hardcode comment column
Browse files Browse the repository at this point in the history
  • Loading branch information
Dax89 committed Jan 3, 2021
1 parent 60242d6 commit 05050d1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
11 changes: 4 additions & 7 deletions rdcore/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define SEPARATOR_LENGTH 50
#define COMMENT_SEPARATOR " | "

Renderer::Renderer(Context* ctx, rd_flag flags, int* commentcolumn): Object(ctx), m_commentcolumn(commentcolumn), m_flags(flags) { }
Renderer::Renderer(Context* ctx, rd_flag flags): Object(ctx), m_flags(flags) { }

bool Renderer::render(const RDDocumentItem* item)
{
Expand Down Expand Up @@ -250,13 +250,10 @@ void Renderer::renderComments(rd_address address)
{
if(this->hasFlag(RendererFlags_NoComments)) return;

// Recalculate comment column
if(m_commentcolumn) *m_commentcolumn = std::max<size_t>(*m_commentcolumn, m_text.size());

std::string comment = this->document()->comment(address, false, COMMENT_SEPARATOR);
if(comment.empty()) return;

if(m_commentcolumn) this->chunk(std::string((*m_commentcolumn - m_text.size()) + INDENT_COMMENT, ' '));
this->chunk(std::string(INDENT_COMMENT, ' '));
this->chunk("# " + Utils::simplified(comment), Theme_Comment);
}

Expand Down Expand Up @@ -346,14 +343,14 @@ std::string Renderer::getInstruction(Context* ctx, rd_address address)

std::string Renderer::getAssemblerInstruction(Context* ctx, rd_address address)
{
Renderer r(ctx, RendererFlags_Simplified, nullptr);
Renderer r(ctx, RendererFlags_Simplified);
r.renderAssemblerInstruction(address);
return r.text();
}

std::string Renderer::getRDILInstruction(Context* ctx, rd_address address)
{
Renderer r(ctx, RendererFlags_Simplified, nullptr);
Renderer r(ctx, RendererFlags_Simplified);
r.renderRDILInstruction(address);
return r.text();
}
3 changes: 1 addition & 2 deletions rdcore/renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Renderer: public Object
};

public:
Renderer(Context* ctx, rd_flag flags, int* commentcolumn);
Renderer(Context* ctx, rd_flag flags);
bool render(const RDDocumentItem* item);
const std::string& text() const;
const Chunks& chunks() const;
Expand Down Expand Up @@ -85,7 +85,6 @@ class Renderer: public Object
private:
mutable std::string m_asminstruction, m_rdilinstruction;
u8 m_currentfg{Theme_Default}, m_currentbg{Theme_Default};
int* m_commentcolumn;
std::deque<SurfaceChunk> m_tokens;
std::string m_text;
rd_flag m_flags;
Expand Down
2 changes: 1 addition & 1 deletion rdcore/renderer/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ void Surface::update(const RDDocumentItem* currentitem)
continue;
}

Renderer r(this->context(), m_flags, &m_commentcolumn);
Renderer r(this->context(), m_flags);
if(!r.render(std::addressof(*it))) continue;

m_surface[row].item = *it;
Expand Down
2 changes: 1 addition & 1 deletion rdcore/renderer/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Surface: public Object
SurfacePath m_path;
std::unordered_map<int, SurfaceRow> m_surface;
std::pair<RDDocumentItem, RDDocumentItem> m_items{ };
int m_rows{0}, m_cols{0}, m_firstcol{0}, m_commentcolumn{0}, m_lastcolumn{0};
int m_rows{0}, m_cols{0}, m_firstcol{0}, m_lastcolumn{0};
std::string m_selectedtext;
uintptr_t m_userdata;
bool m_active{false};
Expand Down

0 comments on commit 05050d1

Please sign in to comment.