public formatted_text copy() { formatted_text the_copy = new formatted_text(text) { bg_ = bg_, align = align, image = image, parts_ = parts_.Select(x => x.copy()).ToList() }; return(the_copy); }
private formatted_text(string text, formatted_text other) { text_ = text; bg_ = other.bg_; align = other.align; image = other.image; parts_ = other.parts_; }
private formatted_text(string text, formatted_text other, List <text_part> other_parts = null) { text_ = text; bg_ = other.bg_; align = other.align; image = other.image; parts_ = other_parts ?? other.parts_; invariant_end(); }
public override void Render(Graphics g, Rectangle r) { DrawBackground(g, r); var i = ListItem.RowObject as match_item; if (i == null) { return; } var col_idx = Column.fixed_index(); string text = GetText(); override_print_ = override_print(i, text, col_idx, column_formatter_base.format_cell.location_type.view); var type = log_view_cell.cell_idx_to_type(col_idx); if (info_type_io.can_be_multi_line(type)) { override_print_ = override_print_.get_most_important_single_line(); } text = override_print_.text; bg_color_ = drawer_.bg_color(ListItem, col_idx, override_print_); Brush brush = brush_.brush(bg_color_); g.FillRectangle(brush, r); StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap); fmt.LineAlignment = StringAlignment.Center; fmt.Trimming = override_print_.align == HorizontalAlignment.Left ? StringTrimming.EllipsisCharacter : StringTrimming.None; fmt.Alignment = StringAlignment.Near; int left = 0; if (override_print_.align != HorizontalAlignment.Left) { var full_text_size = drawer_.text_width(g, text, drawer_.font(override_print_.merge_parts)); int width = r.Width; int extra = width - full_text_size; left = override_print_.align == HorizontalAlignment.Right ? extra - 5 : extra / 2; } draw_string(left, text, g, brush, r, fmt); draw_image(g, r); }
public format_cell(match_item item, log_view parent, int col_idx, info_type col_type, formatted_text text, int row_index, int top_row_index, int sel_index, bool is_bookmark, string prev_text, location_type location) { this.item = item; this.parent = parent; this.col_idx = col_idx; this.col_type = col_type; this.format_text = text; this.row_index = row_index; this.top_row_index = top_row_index; this.prev_text = prev_text; this.location = location; this.sel_index = sel_index; this.is_bookmark = is_bookmark; fg_color = item.fg(parent); bg_color = item.bg(parent); }
// this updates text + infos, so that it will return a single line from a possible multi-line text // we want this, in case the text is multi-line, but we can only print A SINGLE LINE public formatted_text get_most_important_single_line() { string text = text_; var parts = parts_.ToList(); if (!text.Contains('\r') && !text.Contains('\n')) { // text is single line return(new formatted_text(text, this)); } char more = '¶'; var lines = util.split_into_lines(text, util.split_into_lines_type.include_enter_chars_in_returned_lines).ToList(); if (parts.Count == 0) { // in this case, we don't have any custom printing - just return the first non empty line text = lines.FirstOrDefault(x => x.Length > 0 && !util.any_enter_char.Contains(x[0])); if (text == null) { // we only have empty lines text = ""; } else { int line_idx = lines.IndexOf(text); text = (line_idx > 0 && app.inst.show_paragraph_sign ? more + " " : "") + text.Trim() + (line_idx < lines.Count - 1 && app.inst.show_paragraph_sign ? " " + more : ""); } return(new formatted_text(text, this)); } // we have custom printing - first, see if we have typed search var relevant_print = parts.FirstOrDefault(x => x.is_typed_search || x.is_find_search); if (relevant_print == null) { relevant_print = parts[0]; } // find the relevant line int start = 0; string relevant_line = null; foreach (var line in lines) { if (relevant_print.start < start + line.Length) { relevant_line = line; break; } else { start += line.Length; } } Debug.Assert(relevant_line != null); bool line_before = start > 0; bool line_after = start + relevant_line.Length < text.Length; // at this point, ignore enters relevant_line = relevant_line.Trim(); int len = relevant_line.Length; // ... just take the print infos for the relevant line parts = parts.Where(x => (start <= x.start && x.start < start + len) || (start <= x.start + x.len && x.start + x.len < start + len)).ToList(); if (parts.Count > 0) { // adjust first and last - they might be outside our line if (parts[0].start < start) { parts[0] = new text_part(start, parts[0].len - (start - parts[0].start), parts[0]); } var last = parts[parts.Count - 1]; if (last.start + last.len > start + len) { parts[parts.Count - 1] = new text_part(last.start, start + len - last.start, last); } } if (!app.inst.show_paragraph_sign) { line_before = line_after = false; } // convert all the indexes into the relevant line for (int i = 0; i < parts.Count; ++i) { parts[i] = new text_part(parts[i].start - start + (line_before ? 2 : 0), parts[i].len, parts[i]); } text = (line_before ? more + " " : "") + relevant_line + (line_after ? " " + more : ""); var result = new formatted_text(text, this); result.parts_ = parts; result.invariant(); return(result); }