diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..7830fd3 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,19 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64", + "compileCommands": [ + "${workspaceFolder}/build/compile_commands.json" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/meson.build b/meson.build index 70c467e..f71b976 100644 --- a/meson.build +++ b/meson.build @@ -4,7 +4,7 @@ project( version: '0.0.0', meson_version: '>=0.63', default_options: [ - 'c_std=c23', + 'c_std=c2x', 'warning_level=3', 'buildtype=debug', ], @@ -14,7 +14,8 @@ gtk = dependency('gtk4', required: true) src = files( 'src/main.c', - 'src/matrix.c' + 'src/matrix.c', + 'src/ui/uicontroller.c' ) executable( diff --git a/src/main.c b/src/main.c index b12a6d2..52803dd 100644 --- a/src/main.c +++ b/src/main.c @@ -1,18 +1,25 @@ #include "gtk/gtk.h" #include "stdio.h" +#include "stdlib.h" + +#include "./ui/uicontroller.h" + + +static void on_map(GtkWidget* window, gpointer user_data) { + vektor_uictrl_map((VektorWidgetState*)user_data); +} static void activate(GtkApplication *app, gpointer user_data) { - GtkWidget *window; - window = gtk_application_window_new(app); - gtk_window_set_title(GTK_WINDOW(window), "Vektor"); - gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); + VektorWidgetState* widget_state = (VektorWidgetState*)malloc(sizeof(VektorWidgetState)); + vektor_uictrl_init(app, widget_state); - gtk_window_present(GTK_WINDOW(window)); + g_signal_connect(widget_state->window, "map", G_CALLBACK(on_map), widget_state); + + gtk_window_present(widget_state->window); } int main(int argc, char **argv) { - printf("\x1b[1;46m IGNITION \x1b[0m\n"); GtkApplication *app; int status; diff --git a/src/ui/uicontroller.c b/src/ui/uicontroller.c new file mode 100644 index 0000000..64847ac --- /dev/null +++ b/src/ui/uicontroller.c @@ -0,0 +1,31 @@ +#include "uicontroller.h" +#include "gtk/gtk.h" + +void vektor_uictrl_init(GtkApplication* app, VektorWidgetState* stateOut) { + GtkBuilder* builder = gtk_builder_new(); + GError* error = NULL; + + g_print("%s\n", g_get_current_dir()); + + // TODO: .ui files as resources instead of sketchy relative paths + if(!gtk_builder_add_from_file(builder, "./ui/main.ui", &error)) { + g_error("Fatal: %s", error->message); + } + + stateOut->window = GTK_WINDOW(gtk_builder_get_object(builder, "main_window")); + stateOut->workspacePaned = GTK_PANED(gtk_builder_get_object(builder, "workspace_paned")); + + gtk_window_set_application(stateOut->window, app); + gtk_window_set_title(stateOut->window, "Vektor"); + gtk_window_set_default_size(stateOut->window, 800, 600); + + g_object_unref(builder); +} + +void vektor_uictrl_map(VektorWidgetState* state) { + + // set the workspace divider to 7:3 ratio + int window_width = gtk_widget_get_width(GTK_WIDGET(state->window)); + g_print("%i", window_width); + gtk_paned_set_position(state->workspacePaned, 800 * .7); +} diff --git a/src/ui/uicontroller.h b/src/ui/uicontroller.h new file mode 100644 index 0000000..72a2de8 --- /dev/null +++ b/src/ui/uicontroller.h @@ -0,0 +1,20 @@ +#ifndef VKTR_UICTRL_H +#define VKTR_UICTRL_H + +#include "gtk/gtk.h" + +/* +Global application widget state, holding references to +all the widgets used in internal logic of the program +*/ +typedef struct VektorWidgetState { + GtkWindow* window; + + GtkPaned* workspacePaned; + //GtkWidget* Workspace +} VektorWidgetState; + +void vektor_uictrl_init(GtkApplication* app, VektorWidgetState* stateOut); +void vektor_uictrl_map(VektorWidgetState* state); + +#endif \ No newline at end of file diff --git a/ui/main.ui b/ui/main.ui new file mode 100644 index 0000000..2a47398 --- /dev/null +++ b/ui/main.ui @@ -0,0 +1,62 @@ + + + + + + + File + Newapp.new + Openapp.open + Saveapp.save + +
+ Quitapp.quit +
+
+
+ + + + 600 + 400 + + + + vertical + + + + + topbar + + + + + + + horizontal + true + true + + + + + Workspace + + + + + + + Sidepanel + + + + + + + + + + +
\ No newline at end of file