例子
// Package ui defines the user interface APIs in fyne #include <stdio.h> #include <stdlib.h> #include <string.h> struct Window { char* title; void (*SetTitle)(struct Window*, char*); void (*Show)(struct Window*); void (*Hide)(struct Window*); void (*Close)(struct Window*); Canvas (*Canvas)(); }; char* Title(struct Window* w) { return w->title; } void SetTitle(struct Window* w, char* newTitle) { w->title = (char*)malloc(strlen(newTitle) * sizeof(char)); strcpy(w->title, newTitle); } void Show(struct Window* w) { printf("Showing window: %s\n", w->title); } void Hide(struct Window* w) { printf("Hiding window: %s\n", w->title); } void Close(struct Window* w) { printf("Closing window: %s\n", w->title); } struct Canvas {}; struct Canvas Canvas() { struct Canvas c; return c; } struct Window Window() { struct Window w; w.title = (char*)malloc(1 * sizeof(char)); w.title[0] = '\0'; w.SetTitle = SetTitle; w.Show = Show; w.Hide = Hide; w.Close = Close; w.Canvas = Canvas; return w; }