-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Gtk4 final --------- Co-authored-by: marsalien7 Co-authored-by: Martin
- Loading branch information
Showing
5 changed files
with
83 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
# GIT Help | ||
|
||
Marker : feature-keybord branch | ||
|
||
Noch eine Änderung | ||
|
||
## Strategie | ||
|
||
|
||
|
||
## First steps | ||
|
||
git init | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,103 @@ | ||
#include <gtk/gtk.h> | ||
// https://docs.gtk.org/gtk4/ | ||
|
||
#define BUTTON_NUM 20 | ||
|
||
GtkWidget *window; | ||
GtkWidget *entry; | ||
GtkWidget *button; | ||
GtkWidget *grid; | ||
GtkWidget *buttons[10]; | ||
GtkWidget *buttons[BUTTON_NUM]; | ||
GtkWidget *box; | ||
|
||
const char *buttonlabels[BUTTON_NUM] = {"C","/","*","-","7","8","9","+","4","5","6","(","1","2","3",")"," ","0",",","="}; | ||
|
||
// Funktion zum Behandeln des Button-Klicks | ||
void button_clicked(GtkWidget *button, gpointer data) { | ||
const char *text = gtk_entry_get_text(GTK_ENTRY(data)); | ||
void button_clicked(GtkWidget *button, gpointer data) | ||
{ | ||
const char *text = gtk_editable_get_text(GTK_EDITABLE(data)); | ||
printf("Der eingegebene Text ist: %s\n", text); | ||
} | ||
|
||
// Funktion zum Behandeln der Ziffern-Buttons | ||
void number_button_clicked(GtkWidget *button, gpointer data) { | ||
const char *number = gtk_button_get_label(GTK_BUTTON(button)); | ||
gtk_entry_set_text(GTK_ENTRY(data), number); | ||
// gtk_entry_append_text(GTK_ENTRY(data), number); | ||
void number_button_clicked(GtkWidget *button, gpointer data) | ||
{ | ||
const char *label = gtk_button_get_label(GTK_BUTTON(button)); | ||
char button_char = *label; | ||
switch (button_char) { | ||
case 'C': | ||
// gtk_entry_set_text (GTK_ENTRY(data), ""); | ||
gtk_editable_set_text(GTK_EDITABLE(data), ""); | ||
break; | ||
default: | ||
GtkEntryBuffer *buffer = gtk_entry_get_buffer (GTK_ENTRY(data)); | ||
gtk_entry_buffer_insert_text (buffer, -1, label, -1); | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
gtk_init(&argc, &argv); | ||
|
||
static void activate (GtkApplication *app, gpointer user_data) | ||
{ | ||
// Erstellen Sie ein Fenster | ||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
gtk_window_set_title(GTK_WINDOW(window), "Hello World"); | ||
gtk_window_set_default_size(GTK_WINDOW(window), 300, 100); | ||
window = gtk_application_window_new (app); | ||
gtk_window_set_title(GTK_WINDOW(window), "Hello World Gtk4"); | ||
gtk_window_set_default_size(GTK_WINDOW(window), 320, 100); | ||
|
||
// Erstellen Sie ein Eingabefeld | ||
// Erstellt ein Eingabefeld | ||
entry = gtk_entry_new(); | ||
|
||
// Erstellen Sie einen Button | ||
// Erstellt einen Button | ||
button = gtk_button_new_with_label("Eingabe ausgeben"); | ||
|
||
// Verbinden Sie den Button-Klick mit der Funktion button_clicked | ||
// Verbindt den Button-Klick mit der Funktion button_clicked | ||
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked), entry); | ||
|
||
// Verbinden Sie den delete-event-Handler mit gtk_main_quit() | ||
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL); | ||
|
||
/**/ | ||
|
||
// Erstellen Sie ein GtkGrid-Widget für den Tastenblock | ||
// Erstellt ein GtkGrid-Widget für den Tastenblock | ||
grid = gtk_grid_new(); | ||
gtk_grid_set_column_spacing(GTK_GRID(grid), 5); | ||
gtk_grid_set_row_spacing(GTK_GRID(grid), 5); | ||
|
||
// Erstellen Sie 10 Buttons für die Ziffern 0-9 | ||
for (int i = 0; i < 10; i++) { | ||
buttons[i] = gtk_button_new_with_label(g_strdup_printf("%d", i)); | ||
for (int i = 0; i < BUTTON_NUM; i++) { | ||
// Erstellen der Buttons | ||
buttons[i] = gtk_button_new_with_label(buttonlabels[i]); | ||
g_signal_connect(buttons[i], "clicked", G_CALLBACK(number_button_clicked), entry); | ||
} | ||
|
||
// Fügen Sie die Buttons in das Grid-Widget ein | ||
int row = 0, column = 0; | ||
for (int i = 0; i < 10; i++) { | ||
gtk_grid_attach(GTK_GRID(grid), buttons[i], column, row, 1, 1); | ||
if (column == 2) { | ||
column = 0; | ||
row++; | ||
} else { | ||
column++; | ||
} | ||
// Fügt die Buttons in das Grid-Widget ein | ||
gtk_grid_attach(GTK_GRID(grid), buttons[i], i % 4, i / 4, 1, 1); | ||
} | ||
|
||
/**/ | ||
// Erstellen Sie einen Box-Container und fügen Sie das Eingabefeld, den Button und den Tastenblock hinzu | ||
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); | ||
gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0); | ||
gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0); | ||
gtk_box_pack_start(GTK_BOX(box), grid, TRUE, TRUE, 0); | ||
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); | ||
gtk_box_append(GTK_BOX(box), entry); | ||
gtk_widget_set_margin_top(entry, 10); | ||
gtk_widget_set_margin_start(entry, 10); | ||
gtk_widget_set_margin_end(entry, 10); | ||
|
||
gtk_box_append(GTK_BOX(box), grid); | ||
gtk_widget_set_halign(grid, GTK_ALIGN_CENTER); | ||
gtk_widget_set_margin_top(grid, 10); | ||
gtk_widget_set_margin_bottom(grid, 10); | ||
|
||
gtk_box_append(GTK_BOX(box), button); | ||
gtk_widget_set_margin_start(button, 10); | ||
gtk_widget_set_margin_end(button, 10); | ||
gtk_widget_set_margin_bottom(button, 10); | ||
|
||
// Fügen Sie den Box-Container zum Fenster hinzu | ||
gtk_container_add(GTK_CONTAINER(window), box); | ||
gtk_window_set_child (GTK_WINDOW (window), box); | ||
|
||
gtk_window_present (GTK_WINDOW (window)); | ||
} | ||
|
||
// Zeigen Sie alle Widgets an | ||
gtk_widget_show_all(window); | ||
|
||
// Starten Sie die GTK+-Hauptschleife | ||
gtk_main(); | ||
int main (int argc, char **argv) | ||
{ | ||
GtkApplication *app; | ||
int status; | ||
|
||
return 0; | ||
} | ||
app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE); | ||
g_signal_connect(app, "activate", G_CALLBACK (activate), NULL); | ||
status = g_application_run (G_APPLICATION (app), argc, argv); | ||
g_object_unref (app); | ||
|
||
return status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"c_cpp.includePath": [ | ||
"/usr/include/gtk-3.0" // Ersetzen Sie diesen Pfad nach Bedarf | ||
"/usr/include/gtk-4.0" // Ersetzen Sie diesen Pfad nach Bedarf | ||
] | ||
} |