partially implemented panel switching through keyboard, layout system needs to be reworked

This commit is contained in:
Matthew 2025-10-07 07:17:30 +11:00
parent 04849a7487
commit 6b64920f15
2 changed files with 93 additions and 9 deletions

View File

@ -491,11 +491,59 @@ Shift(Modifier md)
return cast(bool)(md & (MD.LeftShift | MD.RightShift)); return cast(bool)(md & (MD.LeftShift | MD.RightShift));
} }
bool
MovePanelFocus(A2D axis, bool prev)(UIPanel* panel)
{
bool result = false;
if(!Nil(panel))
{
UIPanel* target = prev ? panel.prev : panel.next;
if(panel.parent.axis == axis && !Nil(target) && target.ed != null)
{
SetFocusedPanel(target);
result = true;
}
else for(UIPanel* p = panel.parent; !Nil(p); p = p.parent)
{
if(p.parent.axis == axis)
{
for(UIPanel* t = prev ? p.prev : p.next; !Nil(t); t = prev ? t.prev : t.next)
{
UIPanel* f = t.first;
if(!Nil(f) || f.ed == null)
{
while(f.ed == null)
{
if(Nil(f.first))
{
break;
}
f = f.first;
}
}
if(!Nil(f) && f.ed != null)
{
SetFocusedPanel(f);
result = true;
break;
}
}
}
}
}
return result;
}
void void
HandleInputs(EditorCtx* ctx, Inputs* inputs) HandleInputs(EditorCtx* ctx, Inputs* inputs)
{ {
u8[] cb_text; u8[] cb_text;
FlatBuffer* fb = !Nil(GetFocusedPanel()) ? &(GetFocusedPanel()).ed.buf : null; UIPanel* panel = GetFocusedPanel();
FlatBuffer* fb = !Nil(panel) ? &panel.ed.buf : null;
for(auto node = inputs.list.first; node != null; node = node.next) for(auto node = inputs.list.first; node != null; node = node.next)
{ {
@ -520,6 +568,34 @@ HandleInputs(EditorCtx* ctx, Inputs* inputs)
{ {
taken = HandleCmdMode(ctx, node.value); taken = HandleCmdMode(ctx, node.value);
} }
else if(ctx.state == ES.SetPanelFocus)
{
switch(key) with(Input)
{
case Up:
{
if(MovePanelFocus!(A2D.Y, true )(panel)) goto case Escape;
} break;
case Down:
{
if(MovePanelFocus!(A2D.Y, false)(panel)) goto case Escape;
} break;
case Left:
{
if(MovePanelFocus!(A2D.X, true )(panel)) goto case Escape;
} break;
case Right:
{
if(MovePanelFocus!(A2D.X, false)(panel)) goto case Escape;
} break;
case Escape:
{
ResetCtx(ctx);
taken = true;
} break;
default: break;
}
}
else else
{ {
switch(key) with(Input) switch(key) with(Input)
@ -567,21 +643,28 @@ HandleInputs(EditorCtx* ctx, Inputs* inputs)
} break; } break;
case c: case c:
{ {
AddEditor(ctx, GetFocusedPanel(), A2D.Y); if(Ctrl(md))
taken = true; {
// Copy
taken = true;
}
} break; } break;
case d: case w:
{
if(Ctrl(md))
{
ctx.state = ES.SetPanelFocus;
}
} break;
debug case d:
{ {
static bool dbg = false; static bool dbg = false;
dbg = !dbg; dbg = !dbg;
SetDebug(dbg); SetDebug(dbg);
} break; } break;
case g: debug case g:
{ {
debug g_frame_step = !g_frame_step;
{
g_frame_step = !g_frame_step;
}
} break; } break;
debug case s: debug case s:
{ {

View File

@ -466,6 +466,7 @@ WrappedTextLine(u8[] text, u8[] parent_id, f32 text_size, u64 line_no, TS[] styl
} }
f32 parent_width = parent.size.x - (parent.border_thickness * 2); f32 parent_width = parent.size.x - (parent.border_thickness * 2);
Logf("w %f", parent_width);
u64 chars; u64 chars;
TextPart* tp = part; TextPart* tp = part;