Improved Workspace Navigation.

main
sixtenhugosson 2023-12-26 10:52:45 +01:00
parent 44f5f66b9f
commit b2be6558e7
9 changed files with 187 additions and 89 deletions

View File

@ -90,7 +90,7 @@ struct glyph
r32 Advance; r32 Advance;
}; };
#define DEFAULT_GLYPH_ATLAS_DIM 1024*4 #define DEFAULT_GLYPH_ATLAS_DIM 1024*2
#define MAX_GLYPH_SIZE 128 #define MAX_GLYPH_SIZE 128
#define STB_TRUETYPE_IMPLEMENTATION #define STB_TRUETYPE_IMPLEMENTATION

View File

@ -93,6 +93,7 @@ enum platform_key
Key_PageUp, Key_PageDown, Key_PageUp, Key_PageDown,
Key_Home, Key_End, Key_Home, Key_End,
Key_Plus, Key_Minus, Key_Plus, Key_Minus,
Key_Period, Key_Comma,
Key_Backspace, Key_Delete, Key_Backspace, Key_Delete,

View File

@ -12,8 +12,13 @@ static workspace_keybind Workspace_Keybinds[] =
{Key_P, PlatformModifier_Ctrl, W_Command_SplitPanelHorizontal}, {Key_P, PlatformModifier_Ctrl, W_Command_SplitPanelHorizontal},
{Key_L, PlatformModifier_Ctrl, W_Command_SplitPanelVertical}, {Key_L, PlatformModifier_Ctrl, W_Command_SplitPanelVertical},
{Key_W, PlatformModifier_Ctrl, W_Command_CloseView, 0},
{Key_P, PlatformModifier_Ctrl|PlatformModifier_Shift, W_Command_ClosePanel},
{Key_Comma, PlatformModifier_Ctrl, W_Command_CyclePanel},
{Key_Comma, PlatformModifier_Ctrl|PlatformModifier_Shift, W_Command_CyclePanelReverse},
{Key_O, PlatformModifier_Ctrl, W_Command_OpenView, W_ViewKind_FileLister}, {Key_O, PlatformModifier_Ctrl, W_Command_OpenView, W_ViewKind_FileLister},
{Key_P, PlatformModifier_Ctrl|PlatformModifier_Shift, W_Command_OpenView, W_ViewKind_Settings},
#if VN_INTERNAL #if VN_INTERNAL
{Key_U, PlatformModifier_Ctrl|PlatformModifier_Shift, W_Command_ToggleRenderUIDebugRects}, {Key_U, PlatformModifier_Ctrl|PlatformModifier_Shift, W_Command_ToggleRenderUIDebugRects},

View File

@ -21,72 +21,73 @@ WORKSPACE_COMMAND(W_Command_ClosePanel)
} }
workspace_panel *Parent = Panel->Parent; workspace_panel *Parent = Panel->Parent;
if(Parent)
Assert(Parent); {
Assert(Panel != Workspace->RootPanel); Assert(Panel != Workspace->RootPanel);
DLLRemove(Parent->First, Parent->Last, Panel); DLLRemove(Parent->First, Parent->Last, Panel);
b32 OneChildRemains = (Parent->First == Parent->Last); b32 OneChildRemains = (Parent->First == Parent->Last);
if(OneChildRemains) if(OneChildRemains)
{ {
workspace_panel *Child = Parent->First; workspace_panel *Child = Parent->First;
Assert(DLLIsEmpty(Parent->FirstView)); Assert(DLLIsEmpty(Parent->FirstView));
Parent->FirstView = Child->FirstView; Parent->FirstView = Child->FirstView;
Parent->LastView = Child->LastView; Parent->LastView = Child->LastView;
Parent->First = Child->First; Parent->First = Child->First;
Parent->Last = Child->Last; Parent->Last = Child->Last;
Parent->SplitAxis = Child->SplitAxis; Parent->SplitAxis = Child->SplitAxis;
Parent->CurrentView = Child->CurrentView; Parent->CurrentView = Child->CurrentView;
// sixten: Update the parents of the children. // sixten: Update the parents of the children.
for(workspace_view *View = Parent->FirstView; for(workspace_view *View = Parent->FirstView;
View != 0; View != 0;
View = View->Next) View = View->Next)
{ {
View->Parent = Parent; View->Parent = Parent;
} }
for(workspace_panel *ParentChild = Parent->First; for(workspace_panel *ParentChild = Parent->First;
ParentChild != 0; ParentChild != 0;
ParentChild = ParentChild->Next) ParentChild = ParentChild->Next)
{ {
ParentChild->Parent = Parent; ParentChild->Parent = Parent;
} }
DLLRemove(Parent->First, Parent->Last, Child); DLLRemove(Parent->First, Parent->Last, Child);
W_DeletePanel(Child); W_DeletePanel(Child);
} }
else else
{ {
s32 ChildCount = 0; s32 ChildCount = 0;
for(workspace_panel *Child = Parent->First; for(workspace_panel *Child = Parent->First;
Child != 0; Child != 0;
Child = Child->Next) Child = Child->Next)
{ {
++ChildCount; ++ChildCount;
} }
r32 ToAppend = Panel->PercentOfParent / ChildCount; r32 ToAppend = Panel->PercentOfParent / ChildCount;
for(workspace_panel *Child = Parent->First; for(workspace_panel *Child = Parent->First;
Child != 0; Child != 0;
Child = Child->Next) Child = Child->Next)
{ {
Child->PercentOfParent += ToAppend; Child->PercentOfParent += ToAppend;
} }
} }
// sixten: Delete all child views. // sixten: Delete all child views.
workspace_view *NextChild = 0; workspace_view *NextChild = 0;
for(workspace_view *Child = Panel->FirstView; for(workspace_view *Child = Panel->FirstView;
Child != 0; Child != 0;
Child = NextChild) Child = NextChild)
{ {
NextChild = Child->Next; NextChild = Child->Next;
W_DestroyView(Child); W_DestroyView(Child);
} }
W_DeletePanel(Panel); W_DeletePanel(Panel);
}
} }
WORKSPACE_COMMAND(W_Command_OpenView) WORKSPACE_COMMAND(W_Command_OpenView)
@ -97,18 +98,30 @@ WORKSPACE_COMMAND(W_Command_OpenView)
WORKSPACE_COMMAND(W_Command_CloseView) WORKSPACE_COMMAND(W_Command_CloseView)
{ {
workspace_view *View = (workspace_view *)U64ToPointer(Argument); workspace_view *View = 0;
workspace_panel *Panel = View->Parent; if(Argument)
{
DLLRemove(Panel->FirstView, Panel->LastView, View); View = (workspace_view *)U64ToPointer(Argument);
if(Panel->CurrentView == View) }
{ else
Panel->CurrentView = Panel->FirstView; {
} workspace *Workspace = W_GetState();
View = Workspace->CurrentPanel->CurrentView;
W_DestroyView(View); }
if(View)
{
workspace_panel *Panel = View->Parent;
DLLRemove(Panel->FirstView, Panel->LastView, View);
if(Panel->CurrentView == View)
{
Panel->CurrentView = Panel->FirstView;
}
W_DestroyView(View);
}
} }
WORKSPACE_COMMAND(W_Command_OpenFile) WORKSPACE_COMMAND(W_Command_OpenFile)
{ {
temp Scratch = GetScratch(); temp Scratch = GetScratch();
@ -190,6 +203,68 @@ WORKSPACE_COMMAND(W_Command_OpenFile)
ReleaseScratch(Scratch); ReleaseScratch(Scratch);
} }
static workspace_panel *W_FindFirstLeaf(workspace_panel *Panel)
{
for(;Panel->First;) Panel = Panel->First;
return(Panel);
}
static workspace_panel *W_FindNextPanelParent(workspace_panel *Panel)
{
workspace_panel *Result = 0;
if(Panel->Next)
{
Result = Panel->Next;
}
else if(Panel->Parent)
{
Result = W_FindNextPanelParent(Panel->Parent);
}
else
{
Result = Panel;
}
return(Result);
}
WORKSPACE_COMMAND(W_Command_CyclePanel)
{
workspace *Workspace = W_GetState();
workspace_panel *Panel = W_FindFirstLeaf(W_FindNextPanelParent(Workspace->CurrentPanel));
Workspace->CurrentPanel = Panel;
}
static workspace_panel *W_FindLastLeaf(workspace_panel *Panel)
{
for(;Panel->Last;) Panel = Panel->Last;
return(Panel);
}
static workspace_panel *W_FindPrevPanelParent(workspace_panel *Panel)
{
workspace_panel *Result = 0;
if(Panel->Prev)
{
Result = Panel->Prev;
}
else if(Panel->Parent)
{
Result = W_FindPrevPanelParent(Panel->Parent);
}
else
{
Result = Panel;
}
return(Result);
}
WORKSPACE_COMMAND(W_Command_CyclePanelReverse)
{
workspace *Workspace = W_GetState();
workspace_panel *Panel = W_FindLastLeaf(W_FindPrevPanelParent(Workspace->CurrentPanel));
Workspace->CurrentPanel = Panel;
}
#if VN_INTERNAL #if VN_INTERNAL
WORKSPACE_COMMAND(W_Command_ToggleRenderUIDebugRects) WORKSPACE_COMMAND(W_Command_ToggleRenderUIDebugRects)
{ {

View File

@ -235,6 +235,7 @@ static void W_BuildTextEditorErrorList(workspace_view_text_editor *Editor)
if(Signal.Hovering) if(Signal.Hovering)
{ {
UI_TooltipLabel(StrLit("Goto in source"), UI_MouseP()); UI_TooltipLabel(StrLit("Goto in source"), UI_MouseP());
// sixten(TODO): ACTUALLY GO TO THE SOURCE LOCATION
} }
} }
UI_Spacer(UI_Em(0.5, 1)); UI_Spacer(UI_Em(0.5, 1));
@ -316,6 +317,17 @@ UI_CUSTOM_DRAW_CALLBACK(W_TextEditorDrawCallback)
} }
} }
#if 0
//- sixten: render gradient on current line
{
v4_r32 ColorBegin = SetAlpha(Theme_HighlightBorderColor, 0.5);
v4_r32 ColorEnd = SetAlpha(Theme_HighlightBorderColor, 0.0);
range2_r32 LineDest = Range2R32(Box->Rect.Min+V2R32(0, (CursorTextP.Line-1)*LineHeight), Box->Rect.Min+V2R32(400, CursorTextP.Line*LineHeight));
PushQuad(Group, LineDest, ColorBegin, ColorEnd, ColorBegin, ColorEnd, 0, 0, 0);
PushQuad(Group, LineDest, Theme_BackgroundColor, Theme_BackgroundColor, Theme_BackgroundColor, Theme_BackgroundColor, 4.0f, 14, 0);
}
#endif
//- sixten: render tokens //- sixten: render tokens
v2_r32 TokenP = StartTokenP; v2_r32 TokenP = StartTokenP;
for(token *Token = VisibleTokensBegin; Token < VisibleTokensEnd; Token += 1) for(token *Token = VisibleTokensBegin; Token < VisibleTokensEnd; Token += 1)
@ -324,7 +336,7 @@ UI_CUSTOM_DRAW_CALLBACK(W_TextEditorDrawCallback)
//- sixten: get color & font from token //- sixten: get color & font from token
font_id Font = Font_Monospace; font_id Font = Font_Monospace;
v4 Color = Color_Magenta; v4 Color = Color_Cyan;
if(Token->Kind == TokenKind_Comment) { Color = Color_Grey; Font = Font_MonospaceOblique; } if(Token->Kind == TokenKind_Comment) { Color = Color_Grey; Font = Font_MonospaceOblique; }
else if(Token->Kind > TokenKind_SymbolsBegin && Token->Kind < TokenKind_SymbolsEnd) { Color = Color_Grey; } else if(Token->Kind > TokenKind_SymbolsBegin && Token->Kind < TokenKind_SymbolsEnd) { Color = Color_Grey; }
else if(Token->Kind == TokenKind_StringLiteral) { Color = ColorFromHex(0xffa900ff); } else if(Token->Kind == TokenKind_StringLiteral) { Color = ColorFromHex(0xffa900ff); }
@ -552,7 +564,6 @@ static void W_BuildTextEditor(workspace_view *View)
s64 ColumnIndex = UTF8IndexFromOffset(Line, ColumnOffset); s64 ColumnIndex = UTF8IndexFromOffset(Line, ColumnOffset);
CursorHasBeenModified = true; CursorHasBeenModified = true;
Editor->DropdownActive = false;
text_point Point = {LineIndex + 1, ColumnIndex + 1}; text_point Point = {LineIndex + 1, ColumnIndex + 1};
Editor->EditState.Cursor = OffsetFromTextPoint(Editor->Text.String, Editor->Lines, Point); Editor->EditState.Cursor = OffsetFromTextPoint(Editor->Text.String, Editor->Lines, Point);
@ -776,6 +787,15 @@ static void W_BuildTextEditor(workspace_view *View)
Editor->Offset.y = CursorP.y - VisibleRegionDim.y + LineHeight; Editor->Offset.y = CursorP.y - VisibleRegionDim.y + LineHeight;
} }
if(CursorP.x < Editor->Offset.x)
{
Editor->Offset.x = CursorP.x;
}
if(CursorP.x > Editor->Offset.x + VisibleRegionDim.x - LineHeight)
{
Editor->Offset.x = CursorP.x - VisibleRegionDim.x + LineHeight;
}
if(Editor->LastTextPoint.Line == Point.Line) if(Editor->LastTextPoint.Line == Point.Line)
{ {
Editor->LastTextPoint = Point; Editor->LastTextPoint = Point;

View File

@ -72,12 +72,7 @@ struct workspace_view_text_editor
history_node *SavePoint; history_node *SavePoint;
// sixten: ui building & rendering // sixten: ui building & rendering
ui_box *ContainerBox;
v2 TextDim;
v2 Offset; v2 Offset;
b32 DropdownActive;
v2 DropdownP;
r32 DropdownTransition;
}; };
//////////////////////////////// ////////////////////////////////

View File

@ -40,7 +40,7 @@ inline workspace_view *W_CreateNewView(workspace_view_kind Kind, workspace_panel
Editor->Tokens = TextData.Tokens; Editor->Tokens = TextData.Tokens;
Editor->Lines = TextData.Lines; Editor->Lines = TextData.Lines;
Editor->FontSize = 13.0f; Editor->FontSize = 15.0f;
} break; } break;
case W_ViewKind_NavEditor: case W_ViewKind_NavEditor:

View File

@ -575,6 +575,8 @@ static LRESULT Win32_WindowCallback(HWND Window, UINT Message, WPARAM WParam, LP
else if(VKCode == VK_END) { Key = Key_End; } else if(VKCode == VK_END) { Key = Key_End; }
else if(VKCode == VK_OEM_PLUS) { Key = Key_Plus; } else if(VKCode == VK_OEM_PLUS) { Key = Key_Plus; }
else if(VKCode == VK_OEM_MINUS) { Key = Key_Minus; } else if(VKCode == VK_OEM_MINUS) { Key = Key_Minus; }
else if(VKCode == VK_OEM_PERIOD) { Key = Key_Period; }
else if(VKCode == VK_OEM_COMMA) { Key = Key_Comma; }
else if(VKCode == VK_BACK) { Key = Key_Backspace; } else if(VKCode == VK_BACK) { Key = Key_Backspace; }
else if(VKCode == VK_DELETE) { Key = Key_Delete; } else if(VKCode == VK_DELETE) { Key = Key_Delete; }
else if(VKCode == VK_ESCAPE) { Key = Key_Escape; } else if(VKCode == VK_ESCAPE) { Key = Key_Escape; }
@ -794,7 +796,7 @@ int WinMain(HINSTANCE Instance, HINSTANCE PreviousInstance, LPSTR CommandLine, i
// sixten: Setup OpenGL // sixten: Setup OpenGL
HDC DeviceContext = GetDC(Window); HDC DeviceContext = GetDC(Window);
Win32_CreateOpenGLContext(DeviceContext); Win32_CreateOpenGLContext(DeviceContext);
opengl_context OpenGLContext = OpenGL_SetupContext(&RenderCommands, 16*1024); opengl_context OpenGLContext = OpenGL_SetupContext(&RenderCommands, 64*1024);
vn_memory Memory = {}; vn_memory Memory = {};
Memory.PlatformAPI = Platform; Memory.PlatformAPI = Platform;

View File

@ -9,7 +9,7 @@ proc main
@arthur(normal) "Welcome to the Scene Test!"; @arthur(normal) "Welcome to the Scene Test!";
@arthur(happy) "Feel free to move around."; @arthur(happy) "Feel free to move around.";
branch branch
{ {
"No! Sooth me with your voice one more time." "No! Sooth me with your voice one more time."
{ {