feat: basic ui interfacing
This commit is contained in:
19
.vscode/c_cpp_properties.json
vendored
Normal file
19
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ project(
|
|||||||
version: '0.0.0',
|
version: '0.0.0',
|
||||||
meson_version: '>=0.63',
|
meson_version: '>=0.63',
|
||||||
default_options: [
|
default_options: [
|
||||||
'c_std=c23',
|
'c_std=c2x',
|
||||||
'warning_level=3',
|
'warning_level=3',
|
||||||
'buildtype=debug',
|
'buildtype=debug',
|
||||||
],
|
],
|
||||||
@@ -14,7 +14,8 @@ gtk = dependency('gtk4', required: true)
|
|||||||
|
|
||||||
src = files(
|
src = files(
|
||||||
'src/main.c',
|
'src/main.c',
|
||||||
'src/matrix.c'
|
'src/matrix.c',
|
||||||
|
'src/ui/uicontroller.c'
|
||||||
)
|
)
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
|
|||||||
19
src/main.c
19
src/main.c
@@ -1,18 +1,25 @@
|
|||||||
#include "gtk/gtk.h"
|
#include "gtk/gtk.h"
|
||||||
#include "stdio.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) {
|
static void activate(GtkApplication *app, gpointer user_data) {
|
||||||
GtkWidget *window;
|
|
||||||
|
|
||||||
window = gtk_application_window_new(app);
|
VektorWidgetState* widget_state = (VektorWidgetState*)malloc(sizeof(VektorWidgetState));
|
||||||
gtk_window_set_title(GTK_WINDOW(window), "Vektor");
|
vektor_uictrl_init(app, widget_state);
|
||||||
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
|
|
||||||
|
|
||||||
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) {
|
int main(int argc, char **argv) {
|
||||||
printf("\x1b[1;46m IGNITION \x1b[0m\n");
|
|
||||||
|
|
||||||
GtkApplication *app;
|
GtkApplication *app;
|
||||||
int status;
|
int status;
|
||||||
|
|||||||
31
src/ui/uicontroller.c
Normal file
31
src/ui/uicontroller.c
Normal file
@@ -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);
|
||||||
|
}
|
||||||
20
src/ui/uicontroller.h
Normal file
20
src/ui/uicontroller.h
Normal file
@@ -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
|
||||||
62
ui/main.ui
Normal file
62
ui/main.ui
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<interface>
|
||||||
|
<requires lib="gtk" version="4.0"/>
|
||||||
|
|
||||||
|
<!--Topbar-->
|
||||||
|
<menu id="topbar">
|
||||||
|
<submenu>
|
||||||
|
<attribute name="label">File</attribute>
|
||||||
|
<item><attribute name="label">New</attribute><attribute name="action">app.new</attribute></item>
|
||||||
|
<item><attribute name="label">Open</attribute><attribute name="action">app.open</attribute></item>
|
||||||
|
<item><attribute name="label">Save</attribute><attribute name="action">app.save</attribute></item>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<item><attribute name="label">Quit</attribute><attribute name="action">app.quit</attribute></item>
|
||||||
|
</section>
|
||||||
|
</submenu>
|
||||||
|
</menu>
|
||||||
|
|
||||||
|
<!--Main window-->
|
||||||
|
<object class="GtkApplicationWindow" id="main_window">
|
||||||
|
<property name="default-width">600</property>
|
||||||
|
<property name="default-height">400</property>
|
||||||
|
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
|
||||||
|
<!--Topbar-->
|
||||||
|
<child>
|
||||||
|
<object class="GtkPopoverMenuBar">
|
||||||
|
<property name="menu-model">topbar</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
|
||||||
|
<!--Main area below-->
|
||||||
|
<child>
|
||||||
|
<object class="GtkPaned" id="workspace_paned">
|
||||||
|
<property name="orientation">horizontal</property>
|
||||||
|
<property name="vexpand">true</property>
|
||||||
|
<property name="wide-handle">true</property>
|
||||||
|
|
||||||
|
<!--Main viewport area-->
|
||||||
|
<child>
|
||||||
|
<object class="GtkFrame" id="workspace">
|
||||||
|
<property name="label">Workspace</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
|
||||||
|
<!--Sidepanel (layers & modifiers)-->
|
||||||
|
<child>
|
||||||
|
<object class="GtkFrame" id="sidepanel">
|
||||||
|
<property name="label">Sidepanel</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
|
||||||
|
</object>
|
||||||
|
</interface>
|
||||||
Reference in New Issue
Block a user