rendered paste body#include <Ewl.h>#include <stdio.h> static void cb_window_destroy(Ewl_Widget *w, void *ev, void *data);static void cb_window_close(Ewl_Widget *w, void *ev, void *data);static void cb_key_down(Ewl_Widget *w, void *ev, void *data); static void cb_clicked(Ewl_Widget *w, void *ev, void *data); int main(int argc, char ** argv) { Ewl_Widget *win, *scroll, *o, *s, *box, *so, *button, *vbox, *hbox, *label; if (!ewl_init(&argc, argv)) { fprintf(stderr, "Unable to init Elive Image Viewer.\n"); return 1; } if (argc < 2) { fprintf(stderr, "Need image to view .\n"); return 1; } /*main window*/ win = ewl_window_new(); ewl_window_title_set(EWL_WINDOW(win), "Elive Image Viewer"); ewl_window_class_set(EWL_WINDOW(win), "elive_image_viewer"); ewl_window_name_set(EWL_WINDOW(win), "elive_image_viewer"); ewl_object_fill_policy_set(EWL_OBJECT(win), EWL_FLAG_FILL_ALL); ewl_object_size_request(EWL_OBJECT(win), 740, 580); ewl_callback_append(win, EWL_CALLBACK_DELETE_WINDOW, cb_window_close, NULL); ewl_callback_append(win, EWL_CALLBACK_KEY_DOWN, cb_key_down, NULL); ewl_callback_append(win, EWL_CALLBACK_DESTROY, cb_window_destroy, NULL); ewl_widget_name_set(win, "main_win"); ewl_widget_show(win); /*\main window*/ /*vertical box*/ vbox = ewl_vbox_new(); ewl_object_fill_policy_set(EWL_OBJECT(vbox), EWL_FLAG_FILL_ALL); ewl_container_child_append(EWL_CONTAINER(win), vbox); ewl_widget_name_set(vbox, "Vertical Box"); ewl_widget_show(vbox); /*\vertical box*/ /*notebox where the image will be in*/ box = ewl_notebook_new(); ewl_notebook_tabbar_visible_set(EWL_NOTEBOOK(box), FALSE); ewl_object_fill_policy_set(EWL_OBJECT(box), EWL_FLAG_FILL_ALL); ewl_container_child_append(EWL_CONTAINER(vbox), box); ewl_widget_name_set(box, "Image Box"); ewl_widget_show(box); /*\notebox where the image will be in*/ /*horizontal box*/ hbox = ewl_hbox_new(); ewl_object_fill_policy_set(EWL_OBJECT(hbox), EWL_FLAG_FILL_ALL); ewl_container_child_append(EWL_CONTAINER(box), hbox); ewl_widget_show(hbox); /*scroll bar*/ so = ewl_scrollpane_new(); ewl_container_child_append(EWL_CONTAINER(hbox), so); ewl_widget_name_set(so, "ScrollBar"); /*\horizontal box*/ so = ewl_cell_new(); ewl_container_child_append(EWL_CONTAINER(hbox), so); ewl_widget_name_set(so, "Box"); ewl_widget_show(so); /*image*/ o = ewl_image_new(); ewl_image_file_path_set(EWL_IMAGE(o), argv[1]); ewl_image_proportional_set(EWL_IMAGE(o), TRUE); ewl_object_fill_policy_set(EWL_OBJECT(o), EWL_FLAG_FILL_SHRINK); ewl_container_child_append(EWL_CONTAINER(so), o); ewl_widget_name_set(o, "image"); ewl_widget_show(o); /*\image*/ /*horizontal box*/ hbox = ewl_hbox_new(); ewl_object_fill_policy_set(EWL_OBJECT(hbox), EWL_FLAG_FILL_HFILL); ewl_container_child_append(EWL_CONTAINER(vbox), hbox); ewl_widget_name_set(hbox, "Horizontal Box"); ewl_widget_show(hbox); /*button*/ button = ewl_button_new(); ewl_button_label_set(EWL_BUTTON(button), "Original"); ewl_callback_append(button, EWL_CALLBACK_CLICKED, cb_clicked, NULL); ewl_object_fill_policy_set(EWL_OBJECT(button), EWL_FLAG_FILL_SHRINK); ewl_container_child_append(EWL_CONTAINER(hbox), button); ewl_widget_show(button); /*\button*/ /*label*/ label = ewl_label_new(); ewl_label_text_set(EWL_LABEL(label), ewl_image_file_path_get(EWL_IMAGE(o))); ewl_container_child_append(EWL_CONTAINER(hbox), label); ewl_widget_name_set(label, "label"); ewl_widget_show(label); /*label*/ ewl_main(); return 0;} /*button call back*/ static void cb_clicked(Ewl_Widget *w, void *ev, void *data) { Ewl_Widget *b, *so, *k; so = ewl_widget_name_find("ScrollBar"); b = ewl_widget_name_find("Box"); k = ewl_widget_name_find("image"); if ((!k) || (!so) || (!b)) return; if (!strcmp(ewl_button_label_get(EWL_BUTTON(w)), "Original")) { ewl_button_label_set(EWL_BUTTON(w), "Fit"); ewl_container_child_remove(EWL_CONTAINER(b), k); ewl_container_child_append(EWL_CONTAINER(so), k); ewl_widget_hide(b); ewl_widget_show(so); } else { ewl_button_label_set(EWL_BUTTON(w), "Original"); ewl_container_child_remove(EWL_CONTAINER(so), k); ewl_container_child_append(EWL_CONTAINER(b), k); ewl_widget_hide(so); ewl_widget_show(b); }} /*end of button call back*/ static void cb_window_destroy(Ewl_Widget *w, void *ev, void *data) { ewl_main_quit();} static void cb_window_close(Ewl_Widget *w, void *ev, void *data) { ewl_widget_destroy(w);} static void cb_key_down(Ewl_Widget *w, void *ev, void *data) { Ewl_Event_Key_Down *e; e = ev; if (!strcmp(e->base.keyname, "Escape")|| !strcmp(e->base.keyname, "q")) { Ewl_Widget *win; win = ewl_widget_name_find("main_win"); ewl_widget_destroy(win); }}