improve line wrapping cutoff, fix vertex buffer overflow bug

This commit is contained in:
Matthew 2025-10-14 07:49:21 +11:00
parent 1dbe631edf
commit ef360946cd

View File

@ -40,9 +40,12 @@ const Vec4[4] CMD_PALETTE_INPUT_COL = [
Vec4(0.17, 0.17, 0.17, 1.0), Vec4(0.17, 0.17, 0.17, 1.0),
]; ];
const u64 VERTEX_MAX_COUNT = 10000;
// TODO: add setting // TODO: add setting
const f32 TEXT_SIZE = 16.0; const f32 TEXT_SIZE = 16.0;
const UIPanel g_ui_nil_panel; const UIPanel g_ui_nil_panel;
UIPanel* g_UI_NIL_PANEL; UIPanel* g_UI_NIL_PANEL;
@ -446,6 +449,7 @@ Panel(UIPanel* panel)
f32 x = panel.rect.x0; f32 x = panel.rect.x0;
f32 y = panel.rect.y0 + TEXT_SIZE; f32 y = panel.rect.y0 + TEXT_SIZE;
f32 code_view_width = panel.size.x-lcw-border*2.0-padding*2.0;
FontAtlas* atlas = &ctx.atlas_buf.atlas; FontAtlas* atlas = &ctx.atlas_buf.atlas;
bool edit = EditModeActive(); bool edit = EditModeActive();
U64Vec2 pos = VecPos(&ed.buf); U64Vec2 pos = VecPos(&ed.buf);
@ -459,7 +463,8 @@ Panel(UIPanel* panel)
x_pos += padding; x_pos += padding;
u64 ch_offset; u64 ch_offset;
auto parts = MakeMultiline(buf.text, panel.size.x-lcw, buf.style);
auto parts = MakeMultiline(buf.text, code_view_width, buf.style);
for(auto n = parts; n != null; n = n.next) for(auto n = parts; n != null; n = n.next)
{ {
auto l = &n.value; auto l = &n.value;
@ -562,6 +567,8 @@ CommandPalette(CmdPalette* cmd)
{ {
DrawChar(&ctx.atlas_buf.atlas, options[i][j], &ch_x, ch_y, Vec4(1.0)); DrawChar(&ctx.atlas_buf.atlas, options[i][j], &ch_x, ch_y, Vec4(1.0));
} }
if(y+h > size.y+h) break;
} }
} }
@ -679,11 +686,10 @@ InitUICtx(PlatformWindow* window)
tab_width: 2, tab_width: 2,
}; };
u64 vertex_size = 10000;
for(u64 i = 0; i < FRAME_OVERLAP; i += 1) for(u64 i = 0; i < FRAME_OVERLAP; i += 1)
{ {
ctx.buffers[i].m_vtx = CreateMappedBuffer!(Vertex)(&ctx.rd, BT.Vertex, vertex_size); ctx.buffers[i].m_vtx = CreateMappedBuffer!(Vertex)(&ctx.rd, BT.Vertex, VERTEX_MAX_COUNT);
ctx.buffers[i].m_idx = CreateMappedBuffer!(u32)(&ctx.rd, BT.Index, cast(u64)(ceil(vertex_size * 1.5))); ctx.buffers[i].m_idx = CreateMappedBuffer!(u32)(&ctx.rd, BT.Index, cast(u64)(ceil(VERTEX_MAX_COUNT*1.5)));
ctx.buffers[i].vtx = ctx.buffers[i].m_vtx.data; ctx.buffers[i].vtx = ctx.buffers[i].m_vtx.data;
ctx.buffers[i].idx = ctx.buffers[i].m_idx.data; ctx.buffers[i].idx = ctx.buffers[i].m_idx.data;
} }
@ -1202,6 +1208,8 @@ AddUIIndices(UICtx* ctx)
ctx.buffers[ctx.f_idx].idx[5] = 3; ctx.buffers[ctx.f_idx].idx[5] = 3;
ctx.buffers[ctx.f_idx].count += 1; ctx.buffers[ctx.f_idx].count += 1;
assert(ctx.buffers[ctx.f_idx].count < VERTEX_MAX_COUNT);
} }
bool bool