X
X
xverizex2020-04-10 18:31:49
linux
xverizex, 2020-04-10 18:31:49

How to work with these styles in gtk?

there is such a code.

const char *style = "* { background-color: #3c3c3c; } entry { color: #ffffff; } box#text_box * { background-color: #1c1c1c; border-radius: 6px; } textview text { color: #ffffff; }";

static gboolean entry_input_text_cb ( GtkWidget *widget, GdkEvent *event, gpointer data ) {
        GdkEventKey *key = ( GdkEventKey * ) event;
        if ( key->keyval == GDK_KEY_Return ) {
                const char *t = gtk_entry_get_text ( ( GtkEntry * ) entry_input_text );
                if ( strlen ( t ) == 0 ) return FALSE;

                GtkTextBuffer *buf = gtk_text_buffer_new ( NULL );
                gtk_text_buffer_set_text ( buf, t, strlen ( t ) );
                printf ( "t: %s\n", t );

                GtkWidget *frame = g_object_new ( GTK_TYPE_FRAME, "shadow-type", GTK_SHADOW_NONE, "name", "frame_text", NULL );

                GtkWidget *text_view = gtk_text_view_new_with_buffer ( buf );
                gtk_widget_set_name ( text_view, "text_view" );
                gtk_widget_set_margin_start ( frame, 10 );
                gtk_widget_set_margin_end ( frame, 10 );
                gtk_widget_set_margin_top ( frame, 10 );

                gtk_widget_set_margin_top ( text_view, 10 );
                gtk_widget_set_margin_bottom ( text_view, 10 );
                gtk_widget_set_margin_start ( text_view, 10 );
                gtk_widget_set_margin_end ( text_view, 10 );

                g_signal_connect ( text_view, "draw", G_CALLBACK ( text_view_draw_cb ), NULL );
                gtk_container_add ( ( GtkContainer * ) frame, text_view );
                gtk_box_pack_start ( ( GtkBox * ) text_box, frame, FALSE, FALSE, 0 );
                gtk_widget_show_all ( text_box );

        }

        return FALSE;
}


5e9090f7994bf387147249.png

As you can see from the screenshot, border-radius is applied to all widgets that are at box#text_box. and i don't know how to make textview not use border-radius. how can i do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xverizex, 2020-04-10
@xverizex

Anyway, I solved the problem. That's how it was supposed to be.

const char *style = "* { background-color: #3c3c3c; } entry { color: #ffffff; } frame#frame_text * { background-color: #1c1c1c; border-radius: 6px; } textview text { color: #ffffff; } textview#text_view_w * { border-radius: 0px; }";

static gboolean entry_input_text_cb ( GtkWidget *widget, GdkEvent *event, gpointer data ) {
        GdkEventKey *key = ( GdkEventKey * ) event;
        if ( key->keyval == GDK_KEY_Return ) {
                const char *t = gtk_entry_get_text ( ( GtkEntry * ) entry_input_text );
                if ( strlen ( t ) == 0 ) return FALSE;

                GtkTextBuffer *buf = gtk_text_buffer_new ( NULL );
                gtk_text_buffer_set_text ( buf, t, strlen ( t ) );
                printf ( "t: %s\n", t );

                GtkWidget *frame = g_object_new ( GTK_TYPE_FRAME, "shadow-type", GTK_SHADOW_NONE, "name", "frame_text", NULL );

                GtkWidget *text_view = gtk_text_view_new_with_buffer ( buf );
                gtk_widget_set_name ( text_view, "text_view_w" );
                gtk_widget_set_margin_start ( frame, 10 );
                gtk_widget_set_margin_end ( frame, 10 );
                gtk_widget_set_margin_top ( frame, 10 );

                gtk_widget_set_margin_top ( text_view, 10 );
                gtk_widget_set_margin_bottom ( text_view, 10 );
                gtk_widget_set_margin_start ( text_view, 10 );
                gtk_widget_set_margin_end ( text_view, 10 );

                g_signal_connect ( text_view, "draw", G_CALLBACK ( text_view_draw_cb ), NULL );
                gtk_container_add ( ( GtkContainer * ) frame, text_view );
                gtk_box_pack_start ( ( GtkBox * ) text_box, frame, FALSE, FALSE, 0 );
                gtk_widget_show_all ( text_box );

        }

        return FALSE;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question