Create code to load GUI

This commit is contained in:
Markus Koch 2019-07-20 23:50:50 +02:00
parent 2b57db2787
commit 040d74b8c4
9 changed files with 408 additions and 220 deletions

View File

@ -18,8 +18,9 @@ add_custom_command(DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/glade/*.glade "${CMAKE_CU
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/resources.c OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/resources.c
COMMAND glib-compile-resources --target="${CMAKE_CURRENT_BINARY_DIR}/resources.c" --sourcedir="${CMAKE_CURRENT_SOURCE_DIR}" --generate-source "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.gresource.xml") COMMAND glib-compile-resources --target="${CMAKE_CURRENT_BINARY_DIR}/resources.c" --sourcedir="${CMAKE_CURRENT_SOURCE_DIR}" --generate-source "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.gresource.xml")
FILE(GLOB_RECURSE HEADERS "src/*.h")
aux_source_directory(./src SRC_LIST) aux_source_directory(./src SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST} "${CMAKE_CURRENT_BINARY_DIR}/resources.c") add_executable(${PROJECT_NAME} ${SRC_LIST} "${CMAKE_CURRENT_BINARY_DIR}/resources.c" "${HEADERS}")
add_dependencies(${PROJECT_NAME} glib-resources) add_dependencies(${PROJECT_NAME} glib-resources)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/resources.c PROPERTIES GENERATED 1) SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/resources.c PROPERTIES GENERATED 1)
target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES}) target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES})

201
glade/cartItem.glade Normal file
View File

@ -0,0 +1,201 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="cart_item">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">4</property>
<child>
<object class="GtkStack" id="stack_image_loader">
<property name="width_request">100</property>
<property name="height_request">100</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="transition_type">crossfade</property>
<child>
<object class="GtkSpinner">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">True</property>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
<object class="GtkImage" id="image_item">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
<packing>
<property name="name">page1</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="name">d</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label_Title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Title</property>
<property name="wrap">True</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_id">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">######</property>
<attributes>
<attribute name="weight" value="light"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label_description">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Description</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label_comment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Comment</property>
<attributes>
<attribute name="style" value="italic"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton" id="button_delete">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_properties">
<property name="label">gtk-properties</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
</interface>

View File

@ -2,204 +2,9 @@
<!-- Generated with glade 3.22.1 --> <!-- Generated with glade 3.22.1 -->
<interface> <interface>
<requires lib="gtk+" version="3.20"/> <requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="list_item"> <object class="GtkApplicationWindow" id="main_window">
<property name="visible">True</property> <property name="width_request">640</property>
<property name="can_focus">False</property> <property name="height_request">400</property>
<property name="spacing">4</property>
<child>
<object class="GtkStack" id="stack_image_loader">
<property name="width_request">100</property>
<property name="height_request">100</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">baseline</property>
<property name="valign">center</property>
<property name="transition_type">crossfade</property>
<child>
<object class="GtkSpinner">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">True</property>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
<object class="GtkImage" id="image_item">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
<packing>
<property name="name">page1</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="name">d</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label_Title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Title</property>
<property name="wrap">True</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_id">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">######</property>
<attributes>
<attribute name="weight" value="light"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label_description">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Description</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label_comment">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Comment</property>
<attributes>
<attribute name="style" value="italic"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton" id="button_delete">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_properties">
<property name="label">gtk-properties</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
<object class="GtkApplicationWindow" id="window_main">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="show_menubar">False</property> <property name="show_menubar">False</property>
<child> <child>
@ -217,7 +22,7 @@
<property name="transition_duration">500</property> <property name="transition_duration">500</property>
<property name="transition_type">slide-left-right</property> <property name="transition_type">slide-left-right</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox" id="box_intro">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
@ -250,20 +55,56 @@
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Swipe item to check out, or swipe card to display currently checked out items.</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="name">page_introduction</property> <property name="name">page_introduction</property>
<property name="title" translatable="yes">page0</property> <property name="title" translatable="yes">page0</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkBox" id="box_cart">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child> <child>
<object class="GtkListBox" id="list_main"> <object class="GtkListBox" id="list_main">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
</object> </object>
<packing> <packing>
<property name="name">page_checkout</property> <property name="expand">True</property>
<property name="title" translatable="yes">page1</property> <property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Swipe additional item to add to cart, or swipe ID card to complete transaction.</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="name">page_cart</property>
<property name="title" translatable="yes">page0</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
@ -274,18 +115,6 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel" id="label_status">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Status</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object> </object>
</child> </child>
</object> </object>

39
src/cart_item.c Normal file
View File

@ -0,0 +1,39 @@
#include "cart_item.h"
G_DEFINE_TYPE(YacosCartItem, yacos_cart_item, GTK_TYPE_LIST_BOX_ROW)
static void yacos_cart_item_dispose(GObject *obj)
{
/* destroy parent container. This destroys all widgets inside */
G_OBJECT_CLASS(yacos_cart_item_parent_class)->dispose(obj);
}
static void yacos_cart_item_constructed(GObject *obj)
{
G_OBJECT_CLASS(yacos_cart_item_parent_class)->constructed(obj);
}
static void yacos_cart_item_class_init(YacosCartItemClass *klass)
{
GObjectClass *oclass = G_OBJECT_CLASS(klass);
oclass->dispose = yacos_cart_item_dispose;
oclass->constructed = yacos_cart_item_constructed;
}
static void yacos_cart_item_init(YacosCartItem *self)
{
GtkBuilder *builder;
GtkWidget *box;
builder = gtk_builder_new_from_resource("/net/notsyncing/yacos/glade/cartItem.glade");
box = GTK_WIDGET(gtk_builder_get_object(builder, "cart_item"));
gtk_container_add(GTK_CONTAINER(self), box);
// TODO: Get elements
g_object_unref(builder);
}
GtkWidget *yacos_cart_item_new(void)
{
return GTK_WIDGET(g_object_new(TYPE_YACOS_CART_ITEM, NULL));
}

34
src/cart_item.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef CART_ITEM_H
#define CART_ITEM_H
#include <gtk/gtk.h>
G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE(YacosCartItem, yacos_cart_item, YACOS, CART_ITEM, GtkListBoxRow)
#define TYPE_YACOS_CART_ITEM (yacos_cart_item_get_type())
typedef struct _YacosCartItemPriv {
GtkLabel label_title;
GtkLabel label_description;
GtkLabel label_comment;
GtkLabel label_id;
GtkButton button_properties;
GtkButton button_delete;
GtkImage image;
} YacosCartItemPriv;
struct _YacosCartItem {
/* Inheritance */
GtkListBoxRow parent;
/* Custom Elements */
YacosCartItemPriv priv;
};
GtkWidget *yacos_cart_item_new(void);
G_END_DECLS
#endif // CART_ITEM_H

View File

@ -1,7 +1,40 @@
#include <stdio.h> #include <gtk/gtk.h>
#include "main_window.h"
#include "cart_item.h"
int main() struct app_state {
struct mainWindow *mainWindow;
};
static void activate(GtkApplication* app, gpointer user_data)
{ {
printf("Hello World!\n"); struct app_state *app_state = user_data;
return 0; struct mainWindow **mainWindow = &(app_state->mainWindow);
*mainWindow = mainWindow_new(app);
if (*mainWindow) {
gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW((*mainWindow)->main_window));
gtk_widget_show_all((*mainWindow)->main_window);
// For testing only
gtk_stack_set_visible_child((*mainWindow)->stack_main, (*mainWindow)->page_cart.box);
GtkWidget *le = yacos_cart_item_new();
gtk_list_box_insert((*mainWindow)->page_cart.list, le, -1);
gtk_widget_show(le);
}
}
int main(int argc, char *argv[])
{
GtkApplication *app;
int status;
struct app_state app_state;
app = gtk_application_new ("net.notysyncing.yacos", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), &app_state);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
} }

25
src/main_window.c Normal file
View File

@ -0,0 +1,25 @@
#include "main_window.h"
struct mainWindow *mainWindow_new(GtkApplication *app)
{
GtkBuilder *builder;
struct mainWindow *mainWindow;
builder = gtk_builder_new_from_resource("/net/notsyncing/yacos/glade/mainWindow.glade");
mainWindow = malloc(sizeof(struct mainWindow));
mainWindow->main_window = GTK_WIDGET(gtk_builder_get_object(builder, "main_window"));
mainWindow->stack_main = GTK_STACK(gtk_builder_get_object(builder, "stack_main"));
mainWindow->page_intro.box = GTK_WIDGET(gtk_builder_get_object(builder, "box_intro"));
mainWindow->page_cart.box = GTK_WIDGET(gtk_builder_get_object(builder, "box_cart"));
mainWindow->page_cart.list = GTK_LIST_BOX(gtk_builder_get_object(builder, "list_main"));
gtk_builder_connect_signals(builder, NULL);
g_object_unref(G_OBJECT(builder));
return mainWindow;
}

25
src/main_window.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <gtk/gtk.h>
struct mainWindow {
GtkWidget *main_window;
GtkStack *stack_main;
struct page_intro {
GtkWidget *box;
} page_intro;
struct page_cart {
GtkWidget *box;
GtkListBox *list;
} page_cart;
};
struct mainWindow *mainWindow_new();
#endif // MAINWINDOW_H

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<gresources> <gresources>
<gresource prefix="/org/gtk/yacos"> <gresource prefix="/net/notsyncing/yacos">
<file compressed="true" preprocess="xml-stripblanks">glade/mainWindow.glade</file> <file compressed="true" preprocess="xml-stripblanks">glade/mainWindow.glade</file>
<file compressed="true" preprocess="xml-stripblanks">glade/cartItem.glade</file>
</gresource> </gresource>
</gresources> </gresources>