luapage/ui.c
2021-07-20 02:14:20 +03:00

42 lines
1.8 KiB
C

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <luajit.h>
#include "ui.h"
struct application_state* page_application_new() {
struct application_state* state = malloc(sizeof(struct application_state));
state->gapp = gtk_application_new("xyz.hippoz.nettle", G_APPLICATION_FLAGS_NONE);
return state;
}
void page_application_init(struct application_state* state) {
state->page_window = gtk_application_window_new(state->gapp);
gtk_window_set_title(GTK_WINDOW(state->page_window), "Window");
gtk_window_set_default_size(GTK_WINDOW(state->page_window), 200, 200);
state->scrolled = gtk_scrolled_window_new(NULL, NULL);
state->pageview_buffer = gtk_text_buffer_new(NULL);
state->pageview = gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(state->pageview_buffer));
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(state->pageview), GTK_WRAP_WORD_CHAR);
gtk_text_view_set_editable(GTK_TEXT_VIEW(state->pageview), 0);
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(state->pageview), 0);
gtk_container_add(GTK_CONTAINER(state->scrolled), GTK_WIDGET(state->pageview));
gtk_container_add(GTK_CONTAINER(state->page_window), GTK_WIDGET(state->scrolled));
}
void page_application_show(struct application_state* state) {
gtk_widget_show_all(state->page_window);
}
void page_application_text_buffer_append_text(struct application_state* state, const char* display_text) {
GtkTextIter iter;
gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(state->pageview_buffer), &iter);
gtk_text_buffer_insert_markup(GTK_TEXT_BUFFER(state->pageview_buffer), &iter, display_text, -1);
}
void page_application_text_buffer_set_text(struct application_state* state, const char* text) {
gtk_text_buffer_set_text(state->pageview_buffer, text, -1);
}