Flutter Linux Embedder
fl_view.h File Reference
#include <gmodule.h>
#include <gtk/gtk.h>
#include "fl_dart_project.h"
#include "fl_engine.h"

Go to the source code of this file.

Functions

G_BEGIN_DECLS G_MODULE_EXPORT FlView * fl_view_new (FlDartProject *project)
 
FlView * fl_view_new_for_engine (FlEngine *engine)
 
FlEngine * fl_view_get_engine (FlView *view)
 
int64_t fl_view_get_id (FlView *view)
 
void fl_view_set_background_color (FlView *view, const GdkRGBA *color)
 

Function Documentation

◆ fl_view_get_engine()

FlEngine* fl_view_get_engine ( FlView *  view)

fl_view_get_engine: @view: an #FlView.

Gets the engine being rendered in the view.

Returns: an #FlEngine.

Definition at line 789 of file fl_view.cc.

789  {
790  g_return_val_if_fail(FL_IS_VIEW(self), nullptr);
791  return self->engine;
792 }

Referenced by fl_application_activate(), and TEST().

◆ fl_view_get_id()

int64_t fl_view_get_id ( FlView *  view)

fl_view_get_id: @view: an #FlView.

Gets the Flutter view ID used by this view.

Returns: a view ID or -1 if now ID assigned.

Definition at line 795 of file fl_view.cc.

795  {
796  g_return_val_if_fail(FL_IS_VIEW(self), -1);
797  return self->view_id;
798 }

Referenced by create_regular(), and TEST().

◆ fl_view_new()

G_BEGIN_DECLS G_MODULE_EXPORT FlView* fl_view_new ( FlDartProject *  project)

FlView:

#FlView is a GTK widget that is capable of displaying a Flutter application.

The following example shows how to set up a view in a GTK application: |[ FlDartProject *project = fl_dart_project_new (); FlView *view = fl_view_new (project); gtk_widget_show (GTK_WIDGET (view)); gtk_container_add (GTK_CONTAINER (parent), view);

FlBinaryMessenger *messenger = fl_engine_get_binary_messenger (fl_view_get_engine (view)); setup_channels_or_plugins (messenger); ]| fl_view_new: @project: The project to show.

Creates a widget to show a Flutter application.

Returns: a new #FlView.

Definition at line 736 of file fl_view.cc.

736  {
737  g_autoptr(FlEngine) engine = fl_engine_new(project);
738  FlView* self = FL_VIEW(g_object_new(fl_view_get_type(), nullptr));
739 
740  self->view_id = flutter::kFlutterImplicitViewId;
741  self->engine = FL_ENGINE(g_object_ref(engine));
742  FlRenderer* renderer = fl_engine_get_renderer(engine);
743  g_assert(FL_IS_RENDERER_GDK(renderer));
744  self->renderer = FL_RENDERER_GDK(g_object_ref(renderer));
745 
746  self->pointer_manager = fl_pointer_manager_new(self->view_id, engine);
747 
748  self->on_pre_engine_restart_cb_id =
749  g_signal_connect_swapped(self->engine, "on-pre-engine-restart",
750  G_CALLBACK(on_pre_engine_restart_cb), self);
751  self->update_semantics_cb_id = g_signal_connect_swapped(
752  engine, "update-semantics", G_CALLBACK(update_semantics_cb), self);
753 
754  g_signal_connect_swapped(self->gl_area, "create-context",
755  G_CALLBACK(create_context_cb), self);
756  g_signal_connect_swapped(self->gl_area, "realize", G_CALLBACK(realize_cb),
757  self);
758  g_signal_connect_swapped(self->gl_area, "unrealize", G_CALLBACK(unrealize_cb),
759  self);
760 
761  return self;
762 }

References create_context_cb(), fl_engine_get_renderer(), fl_engine_new(), fl_pointer_manager_new(), on_pre_engine_restart_cb(), realize_cb(), unrealize_cb(), and update_semantics_cb().

Referenced by fl_application_activate(), and TEST().

◆ fl_view_new_for_engine()

FlView* fl_view_new_for_engine ( FlEngine *  engine)

fl_view_new_for_engine: @engine: an #FlEngine.

Creates a widget to show a window in a Flutter application. The engine must be not be headless.

Returns: a new #FlView.

Definition at line 764 of file fl_view.cc.

764  {
765  FlView* self = FL_VIEW(g_object_new(fl_view_get_type(), nullptr));
766 
767  self->engine = FL_ENGINE(g_object_ref(engine));
768  FlRenderer* renderer = fl_engine_get_renderer(engine);
769  g_assert(FL_IS_RENDERER_GDK(renderer));
770  self->renderer = FL_RENDERER_GDK(g_object_ref(renderer));
771 
772  self->on_pre_engine_restart_cb_id =
773  g_signal_connect_swapped(engine, "on-pre-engine-restart",
774  G_CALLBACK(on_pre_engine_restart_cb), self);
775 
776  self->view_id = fl_engine_add_view(engine, 1, 1, 1.0, self->cancellable,
777  view_added_cb, self);
778  fl_renderer_add_renderable(FL_RENDERER(self->renderer), self->view_id,
779  FL_RENDERABLE(self));
780 
781  self->pointer_manager = fl_pointer_manager_new(self->view_id, engine);
782 
783  g_signal_connect_swapped(self->gl_area, "realize",
784  G_CALLBACK(secondary_realize_cb), self);
785 
786  return self;
787 }

References fl_engine_add_view(), fl_engine_get_renderer(), fl_pointer_manager_new(), fl_renderer_add_renderable(), on_pre_engine_restart_cb(), secondary_realize_cb(), and view_added_cb().

Referenced by create_regular(), and TEST().

◆ fl_view_set_background_color()

void fl_view_set_background_color ( FlView *  view,
const GdkRGBA *  color 
)

fl_view_set_background_color: @view: an #FlView. @color: a background color.

Set the background color for Flutter (defaults to black).

Definition at line 800 of file fl_view.cc.

801  {
802  g_return_if_fail(FL_IS_VIEW(self));
803  gdk_rgba_free(self->background_color);
804  self->background_color = gdk_rgba_copy(color);
805 }
create_context_cb
static GdkGLContext * create_context_cb(FlView *self)
Definition: fl_view.cc:436
on_pre_engine_restart_cb
static void on_pre_engine_restart_cb(FlView *self)
Definition: fl_view.cc:235
fl_engine_get_renderer
FlRenderer * fl_engine_get_renderer(FlEngine *self)
Definition: fl_engine.cc:597
unrealize_cb
static void unrealize_cb(FlView *self)
Definition: fl_view.cc:513
secondary_realize_cb
static void secondary_realize_cb(FlView *self)
Definition: fl_view.cc:494
realize_cb
static void realize_cb(FlView *self)
Definition: fl_view.cc:453
view_added_cb
static void view_added_cb(GObject *object, GAsyncResult *result, gpointer user_data)
Definition: fl_view.cc:205
fl_engine_add_view
FlutterViewId fl_engine_add_view(FlEngine *self, size_t width, size_t height, double pixel_ratio, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_engine.cc:738
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:580
fl_renderer_add_renderable
void fl_renderer_add_renderable(FlRenderer *self, FlutterViewId view_id, FlRenderable *renderable)
Definition: fl_renderer.cc:341
update_semantics_cb
static void update_semantics_cb(FlView *self, const FlutterSemanticsUpdate2 *update)
Definition: fl_view.cc:225
fl_pointer_manager_new
FlPointerManager * fl_pointer_manager_new(FlutterViewId view_id, FlEngine *engine)
Definition: fl_pointer_manager.cc:94