Proof-of-concept dynamic panel creation
This commit is contained in:
		@@ -27,5 +27,5 @@ char* driver_get_name(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
char* driver_get_image(void)
 | 
					char* driver_get_image(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return "g-wolves/htx/htx_0.png";
 | 
					    return "drivers/g-wolves/htx/htx_0.png";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "main-window.h"
 | 
					#include "main-window.h"
 | 
				
			||||||
#include "panels/empty-panel.h"
 | 
					#include "panels/empty-panel.h"
 | 
				
			||||||
 | 
					#include "panels/mouse-panel.h"
 | 
				
			||||||
#include "device/device.h"
 | 
					#include "device/device.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <gtk/gtk.h>
 | 
					#include <gtk/gtk.h>
 | 
				
			||||||
@@ -163,6 +164,25 @@ void main_window_add_all_devices(MainWindow* self)
 | 
				
			|||||||
		main_window_add_device_to_list(self, array_get(devices, i));
 | 
							main_window_add_device_to_list(self, array_get(devices, i));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void main_window_device_selected(GtkListBox* self, GtkListBoxRow* row, gpointer user_data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						MainWindow* main_window = (MainWindow*) gtk_widget_get_root(GTK_WIDGET(self));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Selection cleared
 | 
				
			||||||
 | 
						if(!row)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// TODO: set to empty panel ?
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						device_t* device = (device_t*) g_object_get_data(G_OBJECT(row), "ginput_device");
 | 
				
			||||||
 | 
						MousePanel* mp = (Panel*) mouse_panel_new();
 | 
				
			||||||
 | 
						mouse_panel_set_device(mp, device);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// TODO : change and use already added child if possible
 | 
				
			||||||
 | 
						activate_panel(main_window, GINPUT_PANEL(mp), device_get_name(device));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
main_window_constructed(GObject* object)
 | 
					main_window_constructed(GObject* object)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -257,6 +277,8 @@ main_window_init(MainWindow* self)
 | 
				
			|||||||
	                       G_BINDING_SYNC_CREATE);
 | 
						                       G_BINDING_SYNC_CREATE);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	activate_panel(self, empty_panel_new(), "empty");
 | 
						activate_panel(self, empty_panel_new(), "empty");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						g_signal_connect(self->device_list, "row_selected", G_CALLBACK(main_window_device_selected), NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO use translation
 | 
					// TODO use translation
 | 
				
			||||||
@@ -285,6 +307,7 @@ void main_window_add_device_to_list(MainWindow* self, device_t* device)
 | 
				
			|||||||
	gtk_widget_set_margin_top(GTK_WIDGET(label), 7);
 | 
						gtk_widget_set_margin_top(GTK_WIDGET(label), 7);
 | 
				
			||||||
	gtk_widget_set_margin_bottom(GTK_WIDGET(label), 7);
 | 
						gtk_widget_set_margin_bottom(GTK_WIDGET(label), 7);
 | 
				
			||||||
	gtk_list_box_row_set_child(row, GTK_WIDGET(label));
 | 
						gtk_list_box_row_set_child(row, GTK_WIDGET(label));
 | 
				
			||||||
 | 
						g_object_set_data(G_OBJECT(row), "ginput_device", device);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Add row to listbox
 | 
						// Add row to listbox
 | 
				
			||||||
	gtk_list_box_append(GTK_LIST_BOX(self->device_list), GTK_WIDGET(row));
 | 
						gtk_list_box_append(GTK_LIST_BOX(self->device_list), GTK_WIDGET(row));
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user