chore: formatted main
This commit is contained in:
		
							parent
							
								
									59fec07d69
								
							
						
					
					
						commit
						c341f034fa
					
				
							
								
								
									
										43
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								src/main.cpp
									
									
									
									
									
								
							| 
						 | 
					@ -1,14 +1,13 @@
 | 
				
			||||||
 | 
					#include "renderer/clay_renderer_SDL3.h"
 | 
				
			||||||
#include <SDL3/SDL_hints.h>
 | 
					#include <SDL3/SDL_hints.h>
 | 
				
			||||||
#include <SDL3/SDL_keycode.h>
 | 
					#include <SDL3/SDL_keycode.h>
 | 
				
			||||||
#include <SDL3/SDL_oldnames.h>
 | 
					#include <SDL3/SDL_oldnames.h>
 | 
				
			||||||
#include <clay/clay.h>
 | 
					#include <clay/clay.h>
 | 
				
			||||||
#include "renderer/clay_renderer_SDL3.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "application.h"
 | 
					#include "application.h"
 | 
				
			||||||
#include "defs.h"
 | 
					#include "defs.h"
 | 
				
			||||||
#include "style.h"
 | 
					 | 
				
			||||||
#include "ui_data.h"
 | 
					 | 
				
			||||||
#include "resources.h"
 | 
					#include "resources.h"
 | 
				
			||||||
 | 
					#include "ui_data.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SDL_MAIN_HANDLED
 | 
					#define SDL_MAIN_HANDLED
 | 
				
			||||||
#include <SDL3/SDL.h>
 | 
					#include <SDL3/SDL.h>
 | 
				
			||||||
| 
						 | 
					@ -21,34 +20,29 @@
 | 
				
			||||||
#include <SDL3/SDL_video.h>
 | 
					#include <SDL3/SDL_video.h>
 | 
				
			||||||
#include <SDL3_ttf/SDL_ttf.h>
 | 
					#include <SDL3_ttf/SDL_ttf.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdbool.h>
 | 
				
			||||||
#include <stddef.h>
 | 
					#include <stddef.h>
 | 
				
			||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
#include <stdbool.h>
 | 
					 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
constexpr SDL_InitFlags sdlInitFlags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY;
 | 
					constexpr SDL_InitFlags sdlInitFlags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SDL_Window *window = nullptr;
 | 
					SDL_Window *window = nullptr;
 | 
				
			||||||
SDL_Renderer *renderer = nullptr;
 | 
					SDL_Renderer *renderer = nullptr;
 | 
				
			||||||
int screenWidth = 1920, screenHeight = 1080;
 | 
					 | 
				
			||||||
bool running = true;
 | 
					bool running = true;
 | 
				
			||||||
uint64_t clayMemorySize = 0;
 | 
					uint64_t clayMemorySize = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Clay_Arena clayPrimaryArena;
 | 
					Clay_Arena clayPrimaryArena;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Clay_SDL3RendererData backendData = {
 | 
					Clay_SDL3RendererData backendData = {nullptr, nullptr, nullptr};
 | 
				
			||||||
	nullptr, nullptr, nullptr
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline
 | 
					static inline void LogOutputResolution() {
 | 
				
			||||||
void LogOutputResolution() {
 | 
					 | 
				
			||||||
	int w, h;
 | 
						int w, h;
 | 
				
			||||||
	SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
 | 
						SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
 | 
				
			||||||
	SDL_Log("output size: %i, %d", w, h);
 | 
						SDL_Log("output size: %i, %d", w, h);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static
 | 
					static Clay_Dimensions MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData) {
 | 
				
			||||||
Clay_Dimensions MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData) {
 | 
					 | 
				
			||||||
	TTF_Font **fonts = (TTF_Font **)userData;
 | 
						TTF_Font **fonts = (TTF_Font **)userData;
 | 
				
			||||||
	TTF_Font *font = fonts[config->fontId];
 | 
						TTF_Font *font = fonts[config->fontId];
 | 
				
			||||||
	int width, height;
 | 
						int width, height;
 | 
				
			||||||
| 
						 | 
					@ -59,18 +53,22 @@ Clay_Dimensions MeasureText(Clay_StringSlice text, Clay_TextElementConfig *confi
 | 
				
			||||||
	return (Clay_Dimensions){(float)width, (float)height};
 | 
						return (Clay_Dimensions){(float)width, (float)height};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static
 | 
					static void HandleClayErrors(Clay_ErrorData data) {
 | 
				
			||||||
void HandleClayErrors(Clay_ErrorData data) {
 | 
					 | 
				
			||||||
	SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", data.errorText.chars);
 | 
						SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", data.errorText.chars);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline
 | 
					static inline void InitSDL() {
 | 
				
			||||||
void InitSDL() {
 | 
					 | 
				
			||||||
	SDL_SetHint(SDL_HINT_RENDER_LINE_METHOD, "3");
 | 
						SDL_SetHint(SDL_HINT_RENDER_LINE_METHOD, "3");
 | 
				
			||||||
	if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) {
 | 
						if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) {
 | 
				
			||||||
		SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_Init failed: %s", SDL_GetError());
 | 
							SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_Init failed: %s", SDL_GetError());
 | 
				
			||||||
		exit(1);
 | 
							exit(1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						int screenWidth{1920}, screenHeight{1080};
 | 
				
			||||||
 | 
						if(SDL_DisplayMode const *mode{SDL_GetDesktopDisplayMode(0)}) {
 | 
				
			||||||
 | 
							screenWidth = mode->w;
 | 
				
			||||||
 | 
							screenHeight = mode->h;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if((window = SDL_CreateWindow("Window", screenWidth, screenHeight, sdlInitFlags)) == nullptr) {
 | 
						if((window = SDL_CreateWindow("Window", screenWidth, screenHeight, sdlInitFlags)) == nullptr) {
 | 
				
			||||||
		SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_CreateWindow failed: %s", SDL_GetError());
 | 
							SDL_LogError(SDL_LOG_CATEGORY_ERROR, "SDL_CreateWindow failed: %s", SDL_GetError());
 | 
				
			||||||
		exit(2);
 | 
							exit(2);
 | 
				
			||||||
| 
						 | 
					@ -89,10 +87,11 @@ void InitSDL() {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static
 | 
					static void InitClay() {
 | 
				
			||||||
void InitClay() {
 | 
					 | 
				
			||||||
	clayMemorySize = Clay_MinMemorySize();
 | 
						clayMemorySize = Clay_MinMemorySize();
 | 
				
			||||||
	clayPrimaryArena = Clay_CreateArenaWithCapacityAndMemory(clayMemorySize, SDL_malloc(clayMemorySize));
 | 
						clayPrimaryArena = Clay_CreateArenaWithCapacityAndMemory(clayMemorySize, SDL_malloc(clayMemorySize));
 | 
				
			||||||
 | 
						int screenWidth{}, screenHeight{};
 | 
				
			||||||
 | 
						SDL_GetCurrentRenderOutputSize(renderer, &screenWidth, &screenHeight);
 | 
				
			||||||
	Clay_Initialize(clayPrimaryArena, {(float)screenWidth, (float)screenHeight}, {HandleClayErrors});
 | 
						Clay_Initialize(clayPrimaryArena, {(float)screenWidth, (float)screenHeight}, {HandleClayErrors});
 | 
				
			||||||
	Clay_SetMeasureTextFunction(MeasureText, fonts);
 | 
						Clay_SetMeasureTextFunction(MeasureText, fonts);
 | 
				
			||||||
	Clay_SetLayoutDimensions({(float)screenWidth, (float)screenHeight});
 | 
						Clay_SetLayoutDimensions({(float)screenWidth, (float)screenHeight});
 | 
				
			||||||
| 
						 | 
					@ -127,10 +126,7 @@ int main(int argc, char *argv[]) {
 | 
				
			||||||
				running = false;
 | 
									running = false;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case SDL_EVENT_WINDOW_RESIZED:
 | 
								case SDL_EVENT_WINDOW_RESIZED:
 | 
				
			||||||
					Clay_SetLayoutDimensions({
 | 
									Clay_SetLayoutDimensions({(float)event.window.data1, (float)event.window.data2});
 | 
				
			||||||
						(float)event.window.data1,
 | 
					 | 
				
			||||||
						(float)event.window.data2
 | 
					 | 
				
			||||||
					});
 | 
					 | 
				
			||||||
				LogOutputResolution();
 | 
									LogOutputResolution();
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case SDL_EVENT_MOUSE_WHEEL:
 | 
								case SDL_EVENT_MOUSE_WHEEL:
 | 
				
			||||||
| 
						 | 
					@ -156,7 +152,8 @@ int main(int argc, char *argv[]) {
 | 
				
			||||||
					shiftDown = event.key.down;
 | 
										shiftDown = event.key.down;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
				default: break;
 | 
								default:
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		Clay_UpdateScrollContainers(true, scrollMotion, deltaTime);
 | 
							Clay_UpdateScrollContainers(true, scrollMotion, deltaTime);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue