Forward declarations are put after variables and constants, but those can reference one of the declarations.
main.c:7:450: error: use of undeclared identifier 'onButtonClick'
7 | static ui_Button button = (ui_Button){.Background = (soglad_Widget){.self = &background, .Draw = ui_RRect_Draw, .GetSize = ui_RRect_GetSize, .Update = ui_RRect_Update}, .HoverBackground = (soglad_Widget){.self = &hoverBackground, .Draw = ui_RRect_Draw, .GetSize = ui_RRect_GetSize, .Update = ui_RRect_Update}, .Content = (soglad_Widget){.self = &buttonContent, .Draw = ui_Text_Draw, .GetSize = ui_Text_GetSize, .Update = ui_Text_Update}, .OnClick = onButtonClick};
| ^
func onButtonClick(w *ui.Button) {
fmt.Println("button clicked")
}
var button = ui.Button{
Background: &background,
HoverBackground: &hoverBackground,
Content: &buttonContent,
OnClick: onButtonClick,
}
// -- Variables and constants --
static ui_RRect background = (ui_RRect){.RRect = (soglad_RRect){.Color = (soglad_Color){.R = 0.4, .G = 0.5, .B = 0.6, .A = 0.8}}};
static ui_RRect hoverBackground = (ui_RRect){.RRect = (soglad_RRect){.Color = (soglad_Color){.R = 0.6, .G = 0.5, .B = 0.4, .A = 0.8}}};
static ui_Text buttonContent = (ui_Text){.Text = (soglad_Text){.Text = so_str("click me"), .Tint = (soglad_Color){.G = 0.7, .B = 0.5, .A = 1}, .Size = 60}};
static ui_Button button = (ui_Button){.Background = (soglad_Widget){.self = &background, .Draw = ui_RRect_Draw, .GetSize = ui_RRect_GetSize, .Update = ui_RRect_Update}, .HoverBackground = (soglad_Widget){.self = &hoverBackground, .Draw = ui_RRect_Draw, .GetSize = ui_RRect_GetSize, .Update = ui_RRect_Update}, .Content = (soglad_Widget){.self = &buttonContent, .Draw = ui_Text_Draw, .GetSize = ui_Text_GetSize, .Update = ui_Text_Update}, .OnClick = onButtonClick};
// -- Forward declarations --
static void onEvent(soglad_Window* win, soglad_EventKind kind, void* event, void* context);
static void onButtonClick(ui_Button* w);
static void onFrame(soglad_Window* win, void* context);
// -- Implementation --
static void onButtonClick(ui_Button* w) {
fmt_Println("button clicked");
}
Forward declarations are put after variables and constants, but those can reference one of the declarations.