fix scroll, fix click/drag boundaries, fix line counter box being too large

This commit is contained in:
Matthew 2025-10-13 06:55:43 +11:00
parent e3ee79c3e8
commit 1dbe631edf
5 changed files with 37 additions and 9 deletions

Binary file not shown.

Binary file not shown.

View File

@ -4,7 +4,7 @@ set -eu
# SHADERS
shader_compiler="glslc"
shader_flags="-std=460 -O --target-env=vulkan1.2"
shader_flags="-std=460 -O --target-env=vulkan1.2 -g"
shader_out="-oassets/"
mkdir -p build

View File

@ -405,6 +405,7 @@ LineLength(FlatBuffer* fb, u64 line)
void
GetLines(FlatBuffer* fb, LineBuffers* linebufs, u64 length)
{
fb.rows = length;
GetLines(fb, linebufs, fb.offset, length);
}
@ -875,13 +876,16 @@ UpdateOffset(FlatBuffer* fb)
i64 screen_pos = CurrentLine(fb) - offset;
i64 start = 0;
i64 end = rows-2;
Logf("p %s start %s end %s", screen_pos, start, end);
if(offset > 0 && screen_pos < start)
{
offset += screen_pos;
Logf("scroll up %s", offset);
}
else if(screen_pos > end)
{
offset += screen_pos - end;
Logf("scroll down %s", offset);
}
}

View File

@ -363,6 +363,21 @@ DrawChar(FontAtlas* atlas, u8 ch, f32* x_pos, f32 y, Vec4 col = Vec4(1.0))
}
}
bool
PrintInputs()
{
bool result;
UICtx* ctx = GetCtx();
for(auto n = ctx.inputs.list.first; n != null; n = n.next)
{
Logf("key %s %s %s", n.value.key, n.value.x, n.value.y);
result = true;
}
return result;
}
void
Panel(UIPanel* panel)
{
@ -381,14 +396,20 @@ Panel(UIPanel* panel)
parent.axis == A2D.Y ? 10 : 0
);
Vec2 p0 = panel.rect.vec0-adj;
Vec2 p1 = panel.rect.vec1+adj;
Vec2 p0 = panel.rect.vec0+adj;
Vec2 p1 = panel.rect.vec1-adj;
if(!Nil(prev)) with(panel)
{
if(Dragged(item, p0, p1) && item.dragged.v[pax] != 0.0)
Vec2 d0 = rect.vec0-adj;
Vec2 d1 = Vec2(
pax == A2D.X ? rect.vec0.x+adj.x : rect.vec1.x,
pax == A2D.Y ? rect.vec0.y+adj.y : rect.vec1.y
);
if(Dragged(item, d0, d1) && item.dragged.v[pax] != 0.0)
{
f32 mov_pct = Remap(item.dragged.v[pax], 0.0, size.v[pax], 0.0, 1.0);
f32 mov_pct = Remap(item.dragged.v[pax], 0.0, panel.parent.size.v[pax], 0.0, 1.0);
if(CheckPanelBounds(pct + mov_pct) && CheckPanelBounds(panel.prev.pct - mov_pct))
{
pct += mov_pct;
@ -404,8 +425,6 @@ Panel(UIPanel* panel)
SetFocusedPanel(panel);
}
DrawBorderedRect(panel.rect.vec0, panel.size, 2.0, 2.0, 0.1, DEFAULT_COL, focused ? HL_BORDER_COL : DEFAULT_BORDER_COL);
i64 rows = cast(i64)ceil(panel.size.y/TEXT_SIZE);
GetLines(&ed.buf, &ed.linebufs, rows);
@ -418,7 +437,11 @@ Panel(UIPanel* panel)
f32 lcw = CalcTextWidth(end_line_text);
f32 padding = 4.0;
DrawRect(panel.rect.vec0, panel.rect.vec1+Vec2(lcw+padding*2, panel.size.y), 0.0, 0.0, focused ? LC_HL_COLOR : LC_COLOR);
f32 border = 2.0, radius = 2.0, softness = 0.1;
DrawRect(panel.rect.vec0, panel.size, radius, border, DEFAULT_COL);
DrawRect(panel.rect.vec0, Vec2(lcw+padding*2, panel.size.y), 0.0, 0.0, focused ? LC_HL_COLOR : LC_COLOR);
DrawBorder(panel.rect.vec0, panel.size, border, radius, softness, focused ? HL_BORDER_COL : DEFAULT_BORDER_COL);
f32 x = panel.rect.x0;
f32 y = panel.rect.y0 + TEXT_SIZE;
@ -441,7 +464,7 @@ Panel(UIPanel* panel)
{
auto l = &n.value;
if(pos.y == i)
if(pos.y == ed.buf.offset+i)
{
DrawCursor(atlas, l.text, pos.x, x+lcw+padding*2.0, y, ch_offset, edit);
}
@ -598,6 +621,7 @@ SetFocusedPanel(UIPanel* panel)
{
if(!CheckNil(g_UI_NIL_PANEL, panel))
{
Logf("set focus");
g_ui_ctx.focused_panel = panel;
}
}