Merge remote-tracking branch 'rxi/master'

This commit is contained in:
Francesco Abbate 2020-11-17 10:24:27 +01:00
commit cdcd89d6d7
4 changed files with 13 additions and 1 deletions

View File

@ -160,7 +160,9 @@ local commands = {
local line1, _, line2 = doc():get_selection(true)
if line1 == line2 then line2 = line2 + 1 end
local text = doc():get_text(line1, 1, line2, math.huge)
text = text:gsub("\n[\t ]*", " ")
text = text:gsub("(.-)\n[\t ]*", function(x)
return x:find("^%s*$") and x or x .. " "
end)
doc():insert(line1, 1, text)
doc():remove(line1, #text + 1, line2, math.huge)
if doc():has_selection() then

View File

@ -18,6 +18,7 @@ typedef struct {
RenRect rect;
RenColor color;
RenFont *font;
int tab_width;
char text[0];
} Command;
@ -143,6 +144,7 @@ int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor c
cmd->color = color;
cmd->font = font;
cmd->rect = rect;
cmd->tab_width = ren_get_font_tab_width(font);
}
}
@ -254,6 +256,7 @@ void rencache_end_frame(void) {
ren_draw_rect(cmd->rect, cmd->color);
break;
case DRAW_TEXT:
ren_set_font_tab_width(cmd->font, cmd->tab_width);
ren_draw_text(cmd->font, cmd->text, cmd->rect.x, cmd->rect.y, cmd->color);
break;
}

View File

@ -183,6 +183,12 @@ void ren_set_font_tab_width(RenFont *font, int n) {
}
int ren_get_font_tab_width(RenFont *font) {
GlyphSet *set = get_glyphset(font, '\t');
return set->glyphs['\t'].xadvance;
}
int ren_get_font_width(RenFont *font, const char *text) {
int x = 0;
const char *p = text;

View File

@ -22,6 +22,7 @@ void ren_free_image(RenImage *image);
RenFont* ren_load_font(const char *filename, float size);
void ren_free_font(RenFont *font);
void ren_set_font_tab_width(RenFont *font, int n);
int ren_get_font_tab_width(RenFont *font);
int ren_get_font_width(RenFont *font, const char *text);
int ren_get_font_height(RenFont *font);