例子

// 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;
}

 

posted @ 2025-01-24 11:11  飞雪飘鸿  阅读(4)  评论(0编辑  收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL