Corrected dropdown behaviour
parent
8299fe0ef4
commit
539949d396
|
@ -1,13 +1,13 @@
|
|||
@echo off
|
||||
|
||||
set CommonCompilerOptions=/Zi /FC /nologo /DVN_INTERNAL=1 /DVN_SLOW=1 /Oi /W4 /WL /WX /wd4201 /wd4305 /wd4244 /wd4100 /wd4505 /std:c++17
|
||||
set CommonCompilerOptions=/Zi /FC /nologo /DVN_INTERNAL=1 /DVN_SLOW=1 /Oi /W4 /WL /WX /wd4996 /wd4201 /wd4305 /wd4244 /wd4100 /wd4505 /std:c++17
|
||||
|
||||
if not exist "../build" mkdir "../build"
|
||||
|
||||
pushd "../build/"
|
||||
|
||||
REM cl %CommonCompilerOptions% ../code/gen.cpp
|
||||
REM gen.exe
|
||||
rem cl %CommonCompilerOptions% ../code/gen.cpp
|
||||
rem gen.exe
|
||||
|
||||
cl %CommonCompilerOptions% ../code/vn.cpp /LD /link /export:VN_UpdateAndRender /incremental:no
|
||||
cl %CommonCompilerOptions% ../code/win32_main.cpp /link user32.lib gdi32.lib winmm.lib opengl32.lib
|
||||
|
|
|
@ -63,7 +63,7 @@ static void GenUI(void)
|
|||
fprintf(Out, "{\n");
|
||||
fprintf(Out, "\tui *UI = UI_GetState();\n");
|
||||
fprintf(Out, "\tAssert(UI->Stacks.%sStackUsed > 0);\n", Stack.Name);
|
||||
fprintf(Out, "\t--UI->Stacks.%sStackUsed;\n", Stack.Name, Stack.Name);
|
||||
fprintf(Out, "\t--UI->Stacks.%sStackUsed;\n", Stack.Name);
|
||||
fprintf(Out, "}\n");
|
||||
|
||||
fprintf(Out, "\n");
|
||||
|
|
|
@ -38,6 +38,8 @@ VN_UPDATE_AND_RENDER(VN_UpdateAndRender)
|
|||
|
||||
State->GlyphAtlas = CreateGlyphAtlas(RenderCommands);
|
||||
|
||||
//Config_AddS64(&State->Config, StrLit("Platform/RefreshRate"), &Input->RefreshRate);
|
||||
|
||||
Workspace_Init(&State->Workspace);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/* date = June 17th 2023 10:48 pm */
|
||||
|
||||
#ifndef VN_CONFIG_H
|
||||
#define VN_CONFIG_H
|
||||
|
||||
struct config_entry
|
||||
{
|
||||
string Name;
|
||||
buffer Target;
|
||||
|
||||
config_entry *Next;
|
||||
config_entry *Prev;
|
||||
};
|
||||
|
||||
struct config
|
||||
{
|
||||
memory_arena Arena;
|
||||
|
||||
config_entry *First;
|
||||
config_entry *Last;
|
||||
};
|
||||
|
||||
static void Config_ReadFile(config *Config, string Path);
|
||||
static void Config_WriteFile(config *Config);
|
||||
|
||||
static void Config_AddEntry(config *Config, string Name, buffer Target);
|
||||
static void Config_AddS64(config *Config, string Name, s64 *Target);
|
||||
|
||||
#endif //VN_CONFIG_H
|
|
@ -5,12 +5,24 @@
|
|||
|
||||
#include "math.h"
|
||||
|
||||
inline r32 Round(r32 Value)
|
||||
{
|
||||
r32 Result = roundf(Value);
|
||||
return(Result);
|
||||
}
|
||||
|
||||
inline r32 Floor(r32 Value)
|
||||
{
|
||||
r32 Result = floorf(Value);
|
||||
return(Result);
|
||||
}
|
||||
|
||||
inline r32 Ceil(r32 Value)
|
||||
{
|
||||
r32 Result = ceilf(Value);
|
||||
return(Result);
|
||||
}
|
||||
|
||||
inline r32 Pow(r32 Base, r32 Exponent)
|
||||
{
|
||||
r32 Result = powf(Base, Exponent);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include "vn_core.h"
|
||||
|
||||
// sixten: Services the platform provides to the game
|
||||
// sixten: Services the platform provides to the application
|
||||
|
||||
struct platform_memory_block
|
||||
{
|
||||
|
@ -151,7 +151,7 @@ struct platform_event_list
|
|||
|
||||
static platform_api Platform;
|
||||
|
||||
// sixten: Services that the render backend provides to the game
|
||||
// sixten: Services that the render backend provides to the application
|
||||
|
||||
#include "vn_render.h"
|
||||
|
||||
|
@ -187,16 +187,20 @@ struct vn_render_commands
|
|||
#include "vn_string.h"
|
||||
#include "vn_thread_context.h"
|
||||
|
||||
// sixten: Services the game provides to the platform
|
||||
// sixten: Services the application provides to the platform
|
||||
|
||||
struct vn_input
|
||||
{
|
||||
// sixten: Platform to application
|
||||
platform_event_list *EventList;
|
||||
|
||||
v2 MouseP;
|
||||
v2 dMouseP;
|
||||
|
||||
r32 dtForFrame;
|
||||
|
||||
// sixten: Application to platform
|
||||
s32 TargetRefreshRate;
|
||||
};
|
||||
|
||||
struct vn_memory
|
||||
|
|
|
@ -197,22 +197,19 @@ static void Workspace_BuildToolbar(workspace *Workspace, r32 dtForFrame)
|
|||
|
||||
if(Workspace_BuildMenuItem(FontIcon_None, "Welcome", "").Clicked)
|
||||
{
|
||||
workspace_view *NewView = Workspace_CreateNewView(Workspace_View_Startup, CurrentPanel);
|
||||
DLLInsertLast(CurrentPanel->FirstView, CurrentPanel->LastView, NewView);
|
||||
Workspace_CreateNewView(Workspace_View_Startup, CurrentPanel);
|
||||
|
||||
Workspace->Menu = ToolbarMenu_None;
|
||||
}
|
||||
if(Workspace_BuildMenuItem(FontIcon_None, "Editor", "").Clicked)
|
||||
{
|
||||
workspace_view *NewView = Workspace_CreateNewView(Workspace_View_Editor, CurrentPanel);
|
||||
DLLInsertLast(CurrentPanel->FirstView, CurrentPanel->LastView, NewView);
|
||||
Workspace_CreateNewView(Workspace_View_Editor, CurrentPanel);
|
||||
|
||||
Workspace->Menu = ToolbarMenu_None;
|
||||
}
|
||||
if(Workspace_BuildMenuItem(FontIcon_Wrench, "Settings", "").Clicked)
|
||||
{
|
||||
workspace_view *NewView = Workspace_CreateNewView(Workspace_View_Settings, CurrentPanel);
|
||||
DLLInsertLast(CurrentPanel->FirstView, CurrentPanel->LastView, NewView);
|
||||
Workspace_CreateNewView(Workspace_View_Settings, CurrentPanel);
|
||||
|
||||
Workspace->Menu = ToolbarMenu_None;
|
||||
}
|
||||
|
@ -712,8 +709,7 @@ static void Workspace_Init(workspace *Workspace)
|
|||
|
||||
// sixten(TEMP): Add mock views.
|
||||
{
|
||||
workspace_view *View1 = Workspace_CreateNewView(Workspace_View_Startup, Workspace->RootPanel);
|
||||
DLLInsertLast(Workspace->RootPanel->FirstView, Workspace->RootPanel->LastView, View1);
|
||||
Workspace_CreateNewView(Workspace_View_Startup, Workspace->RootPanel);
|
||||
}
|
||||
|
||||
// sixten: Setup keybinds
|
||||
|
@ -725,8 +721,8 @@ static void Workspace_Init(workspace *Workspace)
|
|||
}
|
||||
}
|
||||
|
||||
static void Workspace_Update(workspace *Workspace, vn_render_commands *RenderCommands,
|
||||
vn_input *Input, glyph_atlas *GlyphAtlas)
|
||||
static void Workspace_Update(workspace *Workspace, vn_render_commands *RenderCommands, vn_input *Input,
|
||||
glyph_atlas *GlyphAtlas)
|
||||
{
|
||||
Workspace->EventList = Input->EventList;
|
||||
|
||||
|
|
|
@ -15,6 +15,13 @@ inline workspace_view *Workspace_CreateNewView(workspace_view_type Type, workspa
|
|||
{ View->Data = PushSize(&View->Arena, sizeof(workspace_view_settings)); } break;
|
||||
}
|
||||
|
||||
DLLInsertLast(Parent->FirstView, Parent->LastView, View);
|
||||
|
||||
if(View->Parent)
|
||||
{
|
||||
Parent->CurrentView = View;
|
||||
}
|
||||
|
||||
return(View);
|
||||
}
|
||||
|
||||
|
@ -239,14 +246,18 @@ static void Workspace_BuildSettingsTabButton(workspace_view_settings *Settings,
|
|||
}
|
||||
}
|
||||
|
||||
static void UI_DropdownSelection(char **Alternatives, s32 AlternativeCount, b32 *Open, s32 *Selected)
|
||||
static b32 UI_DropdownSelection(char **Alternatives, s32 AlternativeCount, b32 *Open, s32 *Selected)
|
||||
{
|
||||
b32 Result = false;
|
||||
|
||||
UI_SetNextLayoutAxis(Axis2_X);
|
||||
UI_Parent(UI_MakeBoxF(0, ""))
|
||||
{
|
||||
UI_LabelF("Refresh Rate:");
|
||||
UI_Spacer(UI_Pixels(10, 1));
|
||||
|
||||
b32 ActiveInDropdown = false;
|
||||
|
||||
UI_SetNextWidth(UI_Pixels(200, 1));
|
||||
UI_SetNextCornerRadius(4);
|
||||
UI_SetNextLayoutAxis(Axis2_X);
|
||||
|
@ -263,35 +274,63 @@ static void UI_DropdownSelection(char **Alternatives, s32 AlternativeCount, b32
|
|||
UI_Width(UI_Pixels(25, 1)) UI_Font(Font_Icons) UI_LabelF("%U", FontIcon_DownDir);
|
||||
}
|
||||
|
||||
ui_signal Signal = UI_SignalFromBox(DropdownBox);
|
||||
if(Signal.Pressed)
|
||||
ui_signal DropdownSignal = UI_SignalFromBox(DropdownBox);
|
||||
if(DropdownSignal.Pressed)
|
||||
{
|
||||
*Open = true;
|
||||
*Open = !(*Open);
|
||||
}
|
||||
|
||||
if(*Open)
|
||||
if(AreEqual(UI_GetActive(), DropdownBox->Key))
|
||||
{
|
||||
ActiveInDropdown = true;
|
||||
}
|
||||
|
||||
r32 OpenTransition = AnimationCurve_AnimateValueF(*Open, 0, 0.175, "UI Dropdown %p%p", Alternatives, Open);
|
||||
|
||||
if(OpenTransition > 0.1)
|
||||
{
|
||||
UI_Tooltip
|
||||
{
|
||||
UI_SetNextFixedP(V2(DropdownBox->Rect.Min.x, DropdownBox->Rect.Max.y));
|
||||
UI_SetNextCornerRadius(4);
|
||||
UI_SetNextWidth(UI_Pixels(200, 1));
|
||||
UI_SetNextHeight(UI_ChildrenSum(AnimationCurve_AnimateValueF(1, 0, 0.3, "UI Dropdown %p%p", Alternatives, Open), 1));
|
||||
UI_SetNextHeight(UI_ChildrenSum(OpenTransition, 1));
|
||||
UI_Parent(UI_MakeBoxF(UI_BoxFlag_Clip |
|
||||
UI_BoxFlag_DrawDropShadow |
|
||||
UI_BoxFlag_FloatingX |
|
||||
UI_BoxFlag_FloatingY, "Dropdown Contents"))
|
||||
{
|
||||
UI_PushWidth(UI_Percent(1, 1));
|
||||
|
||||
for(s64 Index = 0;
|
||||
Index < AlternativeCount;
|
||||
Index < Round(AlternativeCount*OpenTransition);
|
||||
++Index)
|
||||
{
|
||||
UI_Width(UI_Percent(1, 1)) UI_ButtonF(Alternatives[Index]);
|
||||
ui_signal ButtonSignal = UI_ButtonF(Alternatives[Index]);
|
||||
if(AreEqual(UI_GetActive(), ButtonSignal.Box->Key))
|
||||
{
|
||||
ActiveInDropdown = true;
|
||||
}
|
||||
|
||||
if(ButtonSignal.Pressed)
|
||||
{
|
||||
*Selected = Index;
|
||||
Result = true;
|
||||
}
|
||||
}
|
||||
|
||||
UI_PopWidth();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!ActiveInDropdown && !AreEqual(UI_GetActive(), UI_EmptyKey()))
|
||||
{
|
||||
*Open = false;
|
||||
}
|
||||
}
|
||||
|
||||
return(Result);
|
||||
}
|
||||
|
||||
static void Workspace_BuildSettings(workspace *Workspace, workspace_view *View)
|
||||
|
@ -348,7 +387,11 @@ static void Workspace_BuildSettings(workspace *Workspace, workspace_view *View)
|
|||
|
||||
persist b32 DropdownOpen = false;
|
||||
persist s32 DropdownSelected = 0;
|
||||
UI_DropdownSelection(Alternatives, ArrayCount(Alternatives), &DropdownOpen, &DropdownSelected);
|
||||
|
||||
if(UI_DropdownSelection(Alternatives, ArrayCount(Alternatives), &DropdownOpen, &DropdownSelected))
|
||||
{
|
||||
DropdownOpen = false;
|
||||
}
|
||||
|
||||
UI_Spacer(UI_Pixels(50, 1));
|
||||
}
|
||||
|
|
|
@ -658,11 +658,18 @@ int WinMain(HINSTANCE Instance, HINSTANCE PreviousInstance, LPSTR CommandLine, i
|
|||
LoadedCode.UpdateAndRender(&ThreadContext, &Memory, &Input, &RenderCommands);
|
||||
}
|
||||
|
||||
b32 UseVSync = (Input.TargetRefreshRate == 0);
|
||||
wglSwapIntervalEXT(UseVSync);
|
||||
|
||||
OpenGL_EndFrame(&OpenGLContext, &RenderCommands);
|
||||
wglSwapLayerBuffers(DeviceContext, WGL_SWAP_MAIN_PLANE);
|
||||
}
|
||||
|
||||
Win32_EnforceFrameRate(CurrentTime, 144.0);
|
||||
b32 ShouldLimitFrameRate = (Input.TargetRefreshRate > 0);
|
||||
if(ShouldLimitFrameRate)
|
||||
{
|
||||
Win32_EnforceFrameRate(CurrentTime, Input.TargetRefreshRate);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue