I wrote a control: timed scrolling snapshot.
Right now it just contains a GtkLabel. When I set the label, it can receive the size_allocate event, not the snapshot event.
Although gtkLabel will call the gtk_widget_queue_draw function.
I wrote a control: timed scrolling snapshot.
Right now it just contains a GtkLabel. When I set the label, it can receive the size_allocate event, not the snapshot event.
Although gtkLabel will call the gtk_widget_queue_draw function.
Is it something to do with my snapshot function?
static void lx_scroll_snapshot_snapshot( GtkWidget* widget, GtkSnapshot* snapshot )
{
_SELF( widget );
GtkSnapshot* text_snapshot = gtk_snapshot_new();
GTK_WIDGET_GET_CLASS( self->widget )->snapshot( self->widget, text_snapshot );
int w = gtk_widget_get_width( widget );
int h = gtk_widget_get_height( widget );
cairo_t* cr = gtk_snapshot_append_cairo( snapshot, &GRAPHENE_RECT_INIT( 0, 0, w, h ) );
GskRenderNode* node = gtk_snapshot_free_to_node( text_snapshot );
cairo_save( cr );
cairo_translate( cr, 0.0 - self->offset, 0 );
gsk_render_node_draw( node, cr );
cairo_restore( cr );
int target_width = gtk_widget_get_width( self->widget );
if ( target_width > w ) {
int overflow_width = w - target_width;
int tail_position = target_width - self->offset;
if ( w - tail_position > self->trailing_blank_size ) {
cairo_translate( cr, 0.0 + tail_position + self->trailing_blank_size, 0 );
gsk_render_node_draw( node, cr );
}
}
cairo_destroy( cr );
gsk_render_node_unref( node );
}
The important step I missed: Should call the method of the parent class
GTK_ WIDGET_ CLASS( lx_scroll_snapshot_parent_class )->snapshot( widget, snapshot );
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.