Skip to content

Commit

Permalink
text scaling fix, just fuck this, fuck me and fuck you
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey-Putiy committed Apr 12, 2023
1 parent 6067603 commit 57ffa94
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Client/src/gui_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ void receive_bubble(const char *text, const char *name) {
GtkWidget *box;
GtkTextBuffer *buffer;

int size_limit = gtk_widget_get_allocated_width(box_container) - 200;

box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start(GTK_BOX(box_container), box, FALSE, FALSE, 0);
gtk_widget_set_halign(box, GTK_ALIGN_START);
Expand Down Expand Up @@ -257,13 +255,13 @@ void receive_bubble(const char *text, const char *name) {

gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_NONE);

if (width > size_limit) {
if (width > 400) {
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_WORD);
gtk_widget_set_size_request(text_view, size_limit, -1);
gtk_widget_set_size_request(text_view, 400, -1);
gtk_widget_set_hexpand(text_view, TRUE);
gtk_widget_set_halign(text_view, GTK_ALIGN_FILL);
gtk_widget_set_hexpand(username_box, TRUE);
gtk_widget_set_halign(username_box, GTK_ALIGN_FILL);
gtk_widget_set_halign(username_box, GTK_ALIGN_START);
}

buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
Expand All @@ -285,38 +283,39 @@ void text_bubble(const char *text, int msg_id) {
GtkWidget *text_view;
GtkTextBuffer *buffer;

int size_limit = gtk_widget_get_allocated_width(box_container) - 200;

//text part
gtk_widget_set_hexpand(box_container, FALSE);

box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
gtk_box_pack_start(GTK_BOX(box_container), box, FALSE, FALSE, 0);
gtk_widget_set_halign(box, GTK_ALIGN_END);
gtk_widget_set_size_request(box, -1, 30);
add_class(box, "bubble");
gtk_widget_set_hexpand(box, TRUE);
gtk_widget_set_vexpand(box,FALSE);

gtk_box_pack_start(GTK_BOX(box_container), box, FALSE, FALSE, 0);

text_view = gtk_text_view_new();

gtk_widget_set_valign(text_view, GTK_ALIGN_CENTER);

gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view), FALSE);
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text_view), FALSE);
gtk_box_pack_start(GTK_BOX(box), text_view, FALSE, TRUE, 0);
// gtk_box_pack_start(GTK_BOX(box), text_view, FALSE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(box), text_view);

PangoLayout *layout = gtk_widget_create_pango_layout(text_view, text);
int width, height;
pango_layout_get_pixel_size(layout, &width, &height);

gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_NONE);

if (width > size_limit) {
if (width > 400) {
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_WORD);
gtk_widget_set_size_request(text_view, size_limit, -1);
gtk_widget_set_size_request(text_view, 400, -1);
gtk_widget_set_hexpand(text_view, TRUE);
gtk_widget_set_halign(text_view, GTK_ALIGN_FILL);
gtk_widget_set_halign(text_view, GTK_ALIGN_END);

gtk_widget_set_hexpand(box, TRUE);
gtk_widget_set_halign(box, GTK_ALIGN_END);
}
Expand Down

0 comments on commit 57ffa94

Please sign in to comment.