Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #73 from fomgleb/styles-upgrading
Browse files Browse the repository at this point in the history
Styles upgrading
  • Loading branch information
fomgleb authored Apr 30, 2023
2 parents 30ed225 + 2f32c1a commit 1acca20
Show file tree
Hide file tree
Showing 18 changed files with 718 additions and 726 deletions.
18 changes: 9 additions & 9 deletions client/inc/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#define MIN_LOGIN_LENGTH 4
#define MIN_PASSWORD_LENGTH 5

#define CANVAS_ID "canvas"
#define CREATE_ROOM_ID "create_room"
#define MESSAGES_LIST_SCROLLED_WINDOW_ID "messages_list_scrolled_window"

#define NEW_LOGIN_ENTRY_ID "new_login_entry"
#define CHAT_NAME_LABEL_ID "chat_name"
#define SELECTED_CHAT_NAME_LABEL_ID "selected_chat_name_label"
#define LOGIN_ENTRY_ID "login_entry"
#define PASSWORD_ENTRY_ID "password_entry"
#define NEW_PASSWORD_ENTRY_ID "new_password_entry"
Expand All @@ -29,20 +29,16 @@

#define ERROR_MESSAGE_LOGIN_LABEL_ID "error_message_login_label"
#define ERROR_MESSAGE_REGISTRATION_LABEL_ID "error_message_registration_label"
#define CONNECTING_LABEL_ID "connecting_label"

#define CHAT_SETTINGS_BUTTON_ID "open_chat_settings_window"

#define AUTHENTICATION_LABEL_ID "authentication_label"
#define CREATE_CHAT_TOP_LABEL_ID "create_chat_top_label"
#define CREATE_CHAT_TOP_LABEL_ID "create_chat_top_label"
#define CHAT_SETTINGS_TOP_LABEL_ID "chat_settings_top_label"

//Windows
#define CHAT_CREATE_ROOM_ID "create_room"
#define SETTINGS_WINDOW_ID "settings_window"
#define MESSENGER_WINDOW_ID "messenger_window"
#define CREATE_ROOM_PARENT_ID "create_room_parent"
#define CHAT_LISTS_WINDOW_ID "chats_list_container"
#define CREATE_CHAT_WINDOW_ID "create_chat_window"
#define UPPER_CANVAS_WINDOW_ID "upper_canvas_window"
#define CHAT_SETTINGS_WINDOW_ID "chat_settings_window"
Expand All @@ -51,12 +47,16 @@

//Conteners
#define NEW_MESSAGE_ENTRY_ID "new_message_entry"
#define CHATS_LIST_CONTAINER_ID "chats_list_container"
#define CHATS_LIST_BOX_ID "chats_list_box"
#define CHAT_FIELD_CONTENER_ID "chat_field"

#define GROUP_SETTINGS_BOX "group_settings_box"
#define CONNECTING_BOX_ID "connecting_box"

// Message
#define ADDITIONAL_MESSAGE_INFO_LABEL_ID "additional_message_info_label"
#define MY_ADDITIONAL_MESSAGE_INFO_LABEL_ID "my_additional_message_info_label"

#define LAST_LOADING_MESSAGES_COUNT 30

extern GtkBuilder *Builder;
Expand Down
23 changes: 9 additions & 14 deletions client/inc/styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,30 @@
#include "file.h"
#include "gui_utils.h"

#define PATH_TO_LIGHT_STYLE "resources/styles/light.css"
#define PATH_TO_DARK_STYLE "resources/styles/dark.css"
#define PATH_TO_COMMON_STYLE "resources/styles/common_style.css"
#define PATH_TO_DARK_STYLE "resources/styles/dark_style.css"
#define PATH_TO_LIGHT_STYLE "resources/styles/light_style.css"
#define PATH_TO_DARK_STYLE_SETTINGS "resources/styles/dark_style_settings.css"
#define PATH_TO_LIGHT_STYLE_SETTINGS "resources/styles/light_style_settings.css"

#define PATH_TO_DARK_STYLE "resources/styles/dark_style.css"
#define PATH_TO_LIGHT_STYLE "resources/styles/light_style.css"

#define DEFAULT_CURSOR_IMAGE_PATH "resources/img/cursor.png"

#define STYLE_TYPE_SETTING_PATH "resources/settings/style_type.txt"

#define CSS_CLASS_ENTRY "entry"
#define CSS_CLASS_CANVAS "canvas"
#define CSS_CLASS_CHAT_NAME "chat-name"
#define CSS_CLASS_MAIN_AREA "main-area"
#define CSS_CLASS_CREATE_ROOM "create-room"
#define CSS_CLASS_SEARCH_ENTRY "search-entry"
#define CSS_CLASS_ENTRY_DEFAULT "entry-default"
#define CSS_CLASS_MESSAGE_FIELD "message-field"
#define CSS_CLASS_ERROR_MESSAGE "error-message"
#define CSS_CLASS_DEFAULT_WINDOW "default-window"
#define CSS_CLASS_CONNECTION_BOX "connection-box"
#define CSS_CLASS_NEW_CHAT_BUTTON "new-chat-button"
#define CSS_CLASS_WINDOW_TOP_LABEL "window-top-label"
#define CSS_CLASS_CONNECTION_LABEL "connection-label"
#define CSS_CLASS_TIME_TEXT_SETTINGS "time-text"
#define CSS_CLASS_TIME_NAME_SETTINGS "name-text"
#define CSS_CLASS_CREATE_CHAT_WINDOW "create-chat-window"
#define CSS_CLASS_CREATE_ROOM_PARENT "create-room-parent"
#define CSS_CLASS_SEARCH_ENTRY_PARENT "search-entry-parent"
#define CSS_CLASS_UPPER_CANVAS_WINDOW "upper-canvas-window"
#define CSS_CLASS_CHAT_SETTINGS_WINDOW "chat-settings-window"
#define CSS_CLASS_CHATS_LIST_CONTAINER "chats-list-containter"
#define CSS_CLASS_AUTHENTICATION_WINDOW "authentication-window"
#define CSS_CLASS_NEW_MESSAGE_ENTRY_PARENT "new-message-entry-parent"

typedef enum {
Expand Down
2 changes: 1 addition & 1 deletion client/src/gui/chat_settings_window/chat_settings_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void gui_leave_from_chat(id_t chat_id) {
printf("The user removed from the chat.\n");
}

write_label_text(Builder, CHAT_NAME_LABEL_ID, NULL);
write_label_text(Builder, SELECTED_CHAT_NAME_LABEL_ID, NULL);
gui_render_chats_list();
clear_container(Builder, CHAT_FIELD_CONTENER_ID);
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/gui/messenger_window/gui_chats_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
static void create_button_in_chat_list(t_chat *chat) {
GtkWidget *new_button = gtk_button_new_with_label(chat->name);
g_signal_connect(new_button, "clicked", G_CALLBACK(on_chat_clicked), chat);
add_to_box_start(Builder, new_button, CHATS_LIST_CONTAINER_ID, 0);
add_to_box_start(Builder, new_button, CHATS_LIST_BOX_ID, 0);
}

void gui_render_chats_list() {
list_t *chats_list = rq_get_chats_i_am_in(ServerAddress, ThisUser->id);
if (toggle_widget_visibility(!chats_list, Builder, CONNECTING_BOX_ID)) return;

clear_container(Builder, CHATS_LIST_CONTAINER_ID);
clear_container(Builder, CHATS_LIST_BOX_ID);

bool selected_chat_exists = false;
for (list_node_t *i = chats_list->head; i != NULL; i = i->next) {
Expand Down
12 changes: 6 additions & 6 deletions client/src/gui/messenger_window/gui_messages_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

static gboolean scroll_to_bottom_message_list(gpointer user_data) {
GtkBuilder *builder = user_data;
scroll_to_bottom(builder, "chat_scrolled_field");
scroll_to_bottom(builder, MESSAGES_LIST_SCROLLED_WINDOW_ID);
return FALSE;
}

Expand Down Expand Up @@ -119,16 +119,16 @@ static void create_and_show_message_widget(t_message *message) {

add_to_box_start(Builder, message->container_box, CHAT_FIELD_CONTENER_ID, 10);

apply_style_to_widget(message->is_edited_label, ADDITIONAL_MESSAGE_INFO_LABEL_ID);
apply_style_to_widget(creation_date_label, ADDITIONAL_MESSAGE_INFO_LABEL_ID);
if (message->sender_id == ThisUser->id) {
apply_style_to_widget(content_box, "my-message-content-box");
apply_style_to_widget(name, "my-name-text");
apply_style_to_widget(message->is_edited_label, "my-additional-message-info");
apply_style_to_widget(creation_date_label, "my-additional-message-info");
apply_style_to_widget(message->is_edited_label, MY_ADDITIONAL_MESSAGE_INFO_LABEL_ID);
apply_style_to_widget(creation_date_label, MY_ADDITIONAL_MESSAGE_INFO_LABEL_ID);
} else {
apply_style_to_widget(content_box, "message-content-box");
apply_style_to_widget(name, CSS_CLASS_TIME_NAME_SETTINGS);
apply_style_to_widget(message->is_edited_label, "additional-message-info");
apply_style_to_widget(creation_date_label, "additional-message-info");
}

gtk_widget_show_all(message->container_box);
Expand Down Expand Up @@ -240,7 +240,7 @@ static void gui_open_chat(t_chat *chat) {
GtkWidget *chat_settings_window = get_widget(Builder, CHAT_SETTINGS_BUTTON_ID);

clear_container(Builder, CHAT_FIELD_CONTENER_ID);
write_label_text(Builder, CHAT_NAME_LABEL_ID, chat->name);
write_label_text(Builder, SELECTED_CHAT_NAME_LABEL_ID, chat->name);
load_messages(chat->id);

g_signal_handlers_destroy(message_field);
Expand Down
26 changes: 11 additions & 15 deletions client/src/styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ void save_theme(t_style_type style_type) {
}

void load_light_theme() {
load_css(PATH_TO_LIGHT_STYLE);
GtkCssProvider *provider = gtk_css_provider_new();
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
t_string css_str = read_three_files(PATH_TO_LIGHT_STYLE_SETTINGS, PATH_TO_COMMON_STYLE, PATH_TO_LIGHT_STYLE);
gtk_css_provider_load_from_data(provider, css_str.val, css_str.len, NULL);
string_destroy(&css_str);
}

void load_dark_theme() {
load_css(PATH_TO_DARK_STYLE);
GtkCssProvider *provider = gtk_css_provider_new();
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
t_string css_str = read_three_files(PATH_TO_DARK_STYLE_SETTINGS, PATH_TO_COMMON_STYLE, PATH_TO_DARK_STYLE);
gtk_css_provider_load_from_data(provider, css_str.val, css_str.len, NULL);
string_destroy(&css_str);
}

void apply_style_to_widget(GtkWidget *widget, const char *class_name) {
Expand Down Expand Up @@ -89,18 +97,11 @@ void apply_styles_for_messenger_window(GtkBuilder *gtk_builder) {

set_cursor_image(messenger_window, DEFAULT_CURSOR_IMAGE_PATH);

get_widget_by_id_and_apply_style(gtk_builder, CANVAS_ID, CSS_CLASS_CANVAS);
get_widget_by_id_and_apply_style(gtk_builder, MAIN_AREA_ID, CSS_CLASS_MAIN_AREA);
get_widget_by_id_and_apply_style(gtk_builder, NEW_MESSAGE_ENTRY_ID, CSS_CLASS_ENTRY);
get_widget_by_id_and_apply_style(gtk_builder, CREATE_ROOM_ID, CSS_CLASS_CREATE_ROOM);
get_widget_by_id_and_apply_style(gtk_builder, CHAT_NAME_LABEL_ID, CSS_CLASS_CHAT_NAME);
get_widget_by_id_and_apply_style(gtk_builder, SEARCH_ENTRY_ID, CSS_CLASS_SEARCH_ENTRY);
get_widget_by_id_and_apply_style(gtk_builder, CREATE_ROOM_ID, CSS_CLASS_NEW_CHAT_BUTTON);
get_widget_by_id_and_apply_style(gtk_builder, CONNECTING_BOX_ID, CSS_CLASS_CONNECTION_BOX);

get_widget_by_id_and_apply_style(gtk_builder, NEW_MESSAGE_ENTRY_ID, CSS_CLASS_MESSAGE_FIELD);
get_widget_by_id_and_apply_style(gtk_builder, CONNECTING_LABEL_ID, CSS_CLASS_CONNECTION_LABEL);
get_widget_by_id_and_apply_style(gtk_builder, CREATE_ROOM_PARENT_ID, CSS_CLASS_CREATE_ROOM_PARENT);
get_widget_by_id_and_apply_style(gtk_builder, CHAT_LISTS_WINDOW_ID, CSS_CLASS_CHATS_LIST_CONTAINER);
get_widget_by_id_and_apply_style(gtk_builder, UPPER_CANVAS_WINDOW_ID, CSS_CLASS_UPPER_CANVAS_WINDOW);
get_widget_by_id_and_apply_style(gtk_builder, SEARCH_ENTRY_PARENT_ID, CSS_CLASS_SEARCH_ENTRY_PARENT);
get_widget_by_id_and_apply_style(gtk_builder, NEW_MESSAGE_ENTRY_PARENT_ID, CSS_CLASS_NEW_MESSAGE_ENTRY_PARENT);
Expand All @@ -111,7 +112,6 @@ void apply_styles_to_create_chat_window(GtkBuilder *gtk_builder) {

GtkWidget *crate_chat_window = get_widget(gtk_builder, CREATE_CHAT_WINDOW_ID);
set_cursor_image(crate_chat_window, DEFAULT_CURSOR_IMAGE_PATH);
apply_style_to_widget(crate_chat_window, CSS_CLASS_DEFAULT_WINDOW);

get_widget_by_id_and_apply_style(gtk_builder, CREATE_CHAT_TOP_LABEL_ID, CSS_CLASS_WINDOW_TOP_LABEL);
get_widget_by_id_and_apply_style(gtk_builder, NEW_CHAT_NAME_ENTRY_ID, CSS_CLASS_ENTRY);
Expand All @@ -122,7 +122,6 @@ void apply_styles_to_chat_settings_window(GtkBuilder *gtk_builder) {

GtkWidget *chat_settings_window = GTK_WIDGET(gtk_builder_get_object(gtk_builder, CHAT_SETTINGS_WINDOW_ID));
set_cursor_image(chat_settings_window, DEFAULT_CURSOR_IMAGE_PATH);
apply_style_to_widget(chat_settings_window, CSS_CLASS_DEFAULT_WINDOW);

get_widget_by_id_and_apply_style(gtk_builder, CHAT_SETTINGS_TOP_LABEL_ID, CSS_CLASS_WINDOW_TOP_LABEL);
get_widget_by_id_and_apply_style(gtk_builder, ENTRY_ADD_MEMBER_ID, CSS_CLASS_ENTRY);
Expand All @@ -136,8 +135,6 @@ void apply_styles_to_authentication_window(GtkBuilder *gtk_builder) {
set_cursor_image(authentication_window, DEFAULT_CURSOR_IMAGE_PATH);
get_widget_by_id_and_apply_style(gtk_builder, AUTHENTICATION_LABEL_ID, CSS_CLASS_WINDOW_TOP_LABEL);

apply_style_to_widget(authentication_window, CSS_CLASS_AUTHENTICATION_WINDOW);

get_widget_by_id_and_apply_style(gtk_builder, LOGIN_ENTRY_ID, CSS_CLASS_ENTRY);
get_widget_by_id_and_apply_style(gtk_builder, PASSWORD_ENTRY_ID, CSS_CLASS_ENTRY);
get_widget_by_id_and_apply_style(gtk_builder, NEW_LOGIN_ENTRY_ID, CSS_CLASS_ENTRY);
Expand All @@ -151,7 +148,6 @@ void apply_styles_to_settings_window(GtkBuilder *gtk_builder) {
GtkWidget *settings_window = GTK_WIDGET(gtk_builder_get_object(gtk_builder, SETTINGS_WINDOW_ID));
open_window(gtk_builder, SETTINGS_WINDOW_ID);
set_cursor_image(settings_window, DEFAULT_CURSOR_IMAGE_PATH);
apply_style_to_widget(settings_window, CSS_CLASS_DEFAULT_WINDOW);
get_widget_by_id_and_apply_style(gtk_builder, SETTINGS_LOGIN_ENTRY_ID, CSS_CLASS_ENTRY);
}

Expand Down
Loading

0 comments on commit 1acca20

Please sign in to comment.