[GTK3] Autoscroll the printer view
This commit is contained in:
parent
6ce3016719
commit
cc4be1f903
@ -36,10 +36,10 @@ Author: Maximilian Mader
|
|||||||
<template class="PrinterWindow">
|
<template class="PrinterWindow">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="resizable">False</property>
|
<property name="resizable">False</property>
|
||||||
<property name="default_width">320</property>
|
<property name="default_width">322</property>
|
||||||
<property name="default_height">432</property>
|
<property name="default_height">434</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScrolledWindow">
|
<object class="GtkScrolledWindow" id="scrolled_window">
|
||||||
<property name="min-content-height">432</property>
|
<property name="min-content-height">432</property>
|
||||||
<property name="max-content-height">432</property>
|
<property name="max-content-height">432</property>
|
||||||
<property name="hexpand">0</property>
|
<property name="hexpand">0</property>
|
||||||
|
@ -143,7 +143,7 @@ void set_combo_box_row_separator_func(GtkContainer *container) {
|
|||||||
g_list_free(children);
|
g_list_free(children);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean scroll_to_bottom(GtkTextView *textview, GtkTextMark *mark) {
|
void text_view_scroll_to_bottom(GtkTextView *textview, GtkTextMark *mark) {
|
||||||
GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
|
||||||
GtkTextIter iter;
|
GtkTextIter iter;
|
||||||
|
|
||||||
@ -154,8 +154,11 @@ gboolean scroll_to_bottom(GtkTextView *textview, GtkTextMark *mark) {
|
|||||||
gtk_text_view_scroll_to_mark(textview, mark, 0.0, true, 0.0, 0.10);
|
gtk_text_view_scroll_to_mark(textview, mark, 0.0, true, 0.0, 0.10);
|
||||||
|
|
||||||
gtk_text_buffer_delete_mark(buffer, mark);
|
gtk_text_buffer_delete_mark(buffer, mark);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
void scrolled_window_scroll_to_bottom(GtkScrolledWindow *window) {
|
||||||
|
GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(window);
|
||||||
|
gtk_adjustment_set_value(adj, gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj));
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar* format_scale_value_pct(GtkScale *scale, gdouble value) {
|
gchar* format_scale_value_pct(GtkScale *scale, gdouble value) {
|
||||||
|
@ -25,7 +25,8 @@ GtkWidget *menubar_to_menu(GtkMenuBar *menubar);
|
|||||||
gboolean is_separator(GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
|
gboolean is_separator(GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
|
||||||
void set_combo_box_row_separator_func(GtkContainer *container);
|
void set_combo_box_row_separator_func(GtkContainer *container);
|
||||||
|
|
||||||
gboolean scroll_to_bottom(GtkTextView *textview, GtkTextMark *mark);
|
void text_view_scroll_to_bottom(GtkTextView *textview, GtkTextMark *mark);
|
||||||
|
void scrolled_window_scroll_to_bottom(GtkScrolledWindow *window);
|
||||||
|
|
||||||
gchar* format_scale_value_pct(GtkScale *scale, gdouble value);
|
gchar* format_scale_value_pct(GtkScale *scale, gdouble value);
|
||||||
gchar* format_scale_color_temperature(GtkScale *scale, gdouble value);
|
gchar* format_scale_color_temperature(GtkScale *scale, gdouble value);
|
||||||
|
@ -411,11 +411,11 @@ static gboolean console_window_draw(GtkWidget *widget, cairo_t *cr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scroll_main) {
|
if (scroll_main) {
|
||||||
scroll_to_bottom(self->output, gtk_text_buffer_create_mark(main_text_buf, NULL, &main_scroll_iter, true));
|
text_view_scroll_to_bottom(self->output, gtk_text_buffer_create_mark(main_text_buf, NULL, &main_scroll_iter, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scroll_sidebar) {
|
if (scroll_sidebar) {
|
||||||
scroll_to_bottom(self->sidebar_output, gtk_text_buffer_create_mark(sidebar_text_buf, NULL, &sidebar_scroll_iter, true));
|
text_view_scroll_to_bottom(self->sidebar_output, gtk_text_buffer_create_mark(sidebar_text_buf, NULL, &sidebar_scroll_iter, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
struct _PrinterWindow {
|
struct _PrinterWindow {
|
||||||
GtkWindowClass parent_class;
|
GtkWindowClass parent_class;
|
||||||
|
|
||||||
|
GtkScrolledWindow *scrolled_window;
|
||||||
GtkDrawingArea *printer_canvas;
|
GtkDrawingArea *printer_canvas;
|
||||||
GtkButton *printer_save_button;
|
GtkButton *printer_save_button;
|
||||||
GtkButton *printer_clear_button;
|
GtkButton *printer_clear_button;
|
||||||
@ -73,6 +74,7 @@ static void printer_window_finalize(GObject *object) {
|
|||||||
static void printer_window_class_init(PrinterWindowClass *class) {
|
static void printer_window_class_init(PrinterWindowClass *class) {
|
||||||
gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS(class), RESOURCE_PREFIX "ui/printer_window.ui");
|
gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS(class), RESOURCE_PREFIX "ui/printer_window.ui");
|
||||||
|
|
||||||
|
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), PrinterWindow, scrolled_window);
|
||||||
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), PrinterWindow, printer_canvas);
|
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), PrinterWindow, printer_canvas);
|
||||||
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), PrinterWindow, printer_save_button);
|
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), PrinterWindow, printer_save_button);
|
||||||
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), PrinterWindow, printer_clear_button);
|
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), PrinterWindow, printer_clear_button);
|
||||||
@ -115,13 +117,13 @@ void printer_window_update(PrinterWindow *self, struct PrinterData *data) {
|
|||||||
cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, 160)
|
cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, 160)
|
||||||
);
|
);
|
||||||
|
|
||||||
// cairo_surface_finish(self->surface);
|
|
||||||
|
|
||||||
g_mutex_unlock(&self->surface_mutex);
|
g_mutex_unlock(&self->surface_mutex);
|
||||||
|
|
||||||
gtk_widget_set_size_request(GTK_WIDGET(self->printer_canvas), 160 * 2, self->current_height * 2);
|
gtk_widget_set_size_request(GTK_WIDGET(self->printer_canvas), 160 * 2, self->current_height * 2);
|
||||||
|
|
||||||
gtk_window_present_with_time(GTK_WINDOW(self), time(NULL));
|
gtk_window_present_with_time(GTK_WINDOW(self), time(NULL));
|
||||||
|
|
||||||
|
// queue scrolling, so that it will execute after the size request
|
||||||
|
g_idle_add((GSourceFunc)scrolled_window_scroll_to_bottom, self->scrolled_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printer_window_clear(PrinterWindow *self) {
|
void printer_window_clear(PrinterWindow *self) {
|
||||||
|
Loading…
Reference in New Issue
Block a user