initial commit

This commit is contained in:
dvorakmortonxd 2026-09-03 13:01:25 +02:00
commit 20344fea5c
4 changed files with 11 additions and 80 deletions

View file

@ -60,7 +60,6 @@ The application is a simple GUI program written in C using GTK 4. It features:
- A main window with a title "Sprechen.c". - A main window with a title "Sprechen.c".
- A vertical box layout containing a centered label with welcome text. - A vertical box layout containing a centered label with welcome text.
- Custom CSS styling for a gradient background and styled label box. - Custom CSS styling for a gradient background and styled label box.
- The text size scales dynamically with the window width to ensure readability on different screen sizes.
- The GTK application lifecycle is managed via `GtkApplication`, with activation callback setting up the UI. - The GTK application lifecycle is managed via `GtkApplication`, with activation callback setting up the UI.
Future extensions may include: Future extensions may include:

2
error.txt Normal file
View file

@ -0,0 +1,2 @@
Entering activate
After gtk_window_present

BIN
sprechen

Binary file not shown.

View file

@ -1,62 +1,10 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib.h>
#include <string.h>
typedef struct {
GtkWidget *label;
GtkCssProvider *provider;
} ScaleData;
static void
on_window_notify (GObject *object,
GParamSpec *pspec,
gpointer user_data)
{
// We get the ScaleData from the window
ScaleData *scale_data = g_object_get_data(G_OBJECT(object), "scale-data");
if (!scale_data || !scale_data->label || !scale_data->provider)
return;
GtkWidget *window = GTK_WIDGET(object);
int width;
g_object_get(window, "width", &width, NULL);
// Calculate font size in points based on width
// Base: 600px width -> 18 points
double points_per_pixel = 18.0 / 600.0;
double font_size_points = width * points_per_pixel;
// Clamp between 10 and 24 points
if (font_size_points < 10.0) font_size_points = 10.0;
if (font_size_points > 24.0) font_size_points = 24.0;
// Update the CSS provider with the new font size
char *css_data = g_strdup_printf(
"window {"
" background-color: #2E3440;"
" background-image: linear-gradient(135deg, #2E3440 0%%, #3B4252 100%%);"
" color: #ECEFF4;"
" font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;"
"}"
"label {"
" margin: 30px;"
" padding: 30px;"
" background-color: rgba(59, 66, 82, 0.8);"
" border-radius: 16px;"
" box-shadow: 0 8px 16px rgba(0,0,0,0.4);"
" font-size: %dpt;"
"}",
(int)font_size_points);
gtk_css_provider_load_from_string(scale_data->provider, css_data);
g_free(css_data);
}
static void activate(GtkApplication *app, gpointer user_data) { static void activate(GtkApplication *app, gpointer user_data) {
GtkWidget *window; GtkWidget *window;
GtkWidget *box; GtkWidget *box;
GtkWidget *label; GtkWidget *label;
GtkCssProvider *provider; GtkCssProvider *provider;
ScaleData *scale_data;
// Create a new application window // Create a new application window
window = gtk_application_window_new(app); window = gtk_application_window_new(app);
@ -79,19 +27,15 @@ static void activate(GtkApplication *app, gpointer user_data) {
gtk_label_set_max_width_chars(label, 40); gtk_label_set_max_width_chars(label, 40);
gtk_box_append(GTK_BOX(box), label); gtk_box_append(GTK_BOX(box), label);
// Create and load CSS for beautiful background with initial font size // Load CSS for beautiful background
provider = gtk_css_provider_new(); provider = gtk_css_provider_new();
int initial_width = 600; // default width gtk_css_provider_load_from_string(provider,
double points_per_pixel = 18.0 / 600.0;
double initial_font_size_points = initial_width * points_per_pixel;
if (initial_font_size_points < 10.0) initial_font_size_points = 10.0;
if (initial_font_size_points > 24.0) initial_font_size_points = 24.0;
char *initial_css = g_strdup_printf(
"window {" "window {"
" background-color: #2E3440;" " background-color: #2E3440;" /* Dark bluish background */
" background-image: linear-gradient(135deg, #2E3440 0%%, #3B4252 100%%);" " background-image: linear-gradient(135deg, #2E3440 0%, #3B4252 100%);"
" color: #ECEFF4;" " color: #ECEFF4;"
" font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;" " font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;"
" font-size: 18px;"
"}" "}"
"label {" "label {"
" margin: 30px;" " margin: 30px;"
@ -99,11 +43,8 @@ static void activate(GtkApplication *app, gpointer user_data) {
" background-color: rgba(59, 66, 82, 0.8);" " background-color: rgba(59, 66, 82, 0.8);"
" border-radius: 16px;" " border-radius: 16px;"
" box-shadow: 0 8px 16px rgba(0,0,0,0.4);" " box-shadow: 0 8px 16px rgba(0,0,0,0.4);"
" font-size: %dpt;" "}"
"}", );
(int)initial_font_size_points);
gtk_css_provider_load_from_string(provider, initial_css);
g_free(initial_css);
// Apply CSS to the window // Apply CSS to the window
gtk_style_context_add_provider_for_display( gtk_style_context_add_provider_for_display(
@ -111,18 +52,7 @@ static void activate(GtkApplication *app, gpointer user_data) {
GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_USER); GTK_STYLE_PROVIDER_PRIORITY_USER);
// We keep the provider to update it later, so we don't unreference it yet g_object_unref(provider);
// g_object_unref(provider); // We will unreference it in the cleanup? We'll store it in ScaleData and unreference when the window is destroyed.
// Set up scaling data
scale_data = g_new(ScaleData, 1);
scale_data->label = label;
scale_data->provider = provider;
g_object_set_data_full(G_OBJECT(window), "scale-data", scale_data, g_free);
// Connect to the window's notify::width and notify::height signals
g_signal_connect(window, "notify::width", G_CALLBACK(on_window_notify), NULL);
g_signal_connect(window, "notify::height", G_CALLBACK(on_window_notify), NULL);
gtk_window_present(window); gtk_window_present(window);
} }
@ -137,4 +67,4 @@ int main(int argc, char **argv) {
g_object_unref(app); g_object_unref(app);
return status; return status;
} }