diff --git a/c_bindings/mui.h b/c_bindings/mui.h index 84c4157..0fa74ea 100644 --- a/c_bindings/mui.h +++ b/c_bindings/mui.h @@ -1,5 +1,16 @@ #warning "The API is unstable and a lot of thing will be changed in future. Please don't use in real-world application before stable-release." +#define MUI_OK "ok" +#define MUI_OK_CANCEL "okcancel" +#define MUI_YES_NO "yesno" +#define MUI_YES_NO_CANCEL "yesnocancel" +#define MUI_INFO "info" +#define MUI_WARNING "warning" +#define MUI_ERROR "error" +#define MUI_RETURN_CANCEL_NO 0 +#define MUI_RETURN_OK_YES 1 +#define MUI_RETURN_NO 2 //On Yes/No/Cancel + typedef struct mui_window mui_window; typedef struct mui_event_details mui_event_details; typedef struct mui_parsed_event_details mui_parsed_event_details; @@ -38,20 +49,21 @@ void mui_run(mui_window* window); void mui_change_object_property(mui_window* window, char* id, char* config); struct mui_parsed_event_details mui_parse_event_details(mui_event_details); void mui_empty_fn(mui_event_details details, mui_window* window, void** app_data){} +void mui_destroy(mui_window* window); +int mui_messagebox(char* title, char* message, char* typ, char* icon); +void mui_beep(); +char* mui_inputbox(char* title, char* text, char* default_text); /* ### Not Implemented Yet ### void mui_get_object_by_id(); void mui_sort_widgets_with_zindex(); -void mui_destroy(); void mui_notifypopup(); void mui_openfiledialog(); void mui_passwordbox(); void mui_savefiledialog(); void mui_selectfolderdialog(); void mui_inputbox(); -void mui_messagebox(); -void mui_beep(); void mui_colorchooser(); */ diff --git a/c_bindings/mui.v b/c_bindings/mui.v index 22114b9..8e53b02 100644 --- a/c_bindings/mui.v +++ b/c_bindings/mui.v @@ -101,3 +101,38 @@ fn mui_parse_event_details(event_details mui.EventDetails) ParsedEventDetails { fn mui_run(mut window &mui.Window){ window.run() } + +[export: "mui_messagebox"] +fn mui_messagebox(title &char, message &char, _type &char, icon &char) int { + unsafe { + return mui.messagebox( + title.vstring(), + message.vstring(), + _type.vstring(), + icon.vstring() + ) + } + return 0 +} + +[export: "mui_inputbox"] +fn mui_inputbox(title &char, text &char, default_text &char) &char { + unsafe { + return &char(mui.inputbox( + title.vstring(), + text.vstring(), + default_text.vstring() + ).str) + } + return c"" +} + +[export: "mui_beep"] +fn mui_beep(){ + mui.beep() +} + +[export: "mui_destroy"] +fn mui_destroy(mut window &mui.Window){ + window.destroy() +} diff --git a/c_bindings/test.c b/c_bindings/test.c index d7f9525..d51f0be 100644 --- a/c_bindings/test.c +++ b/c_bindings/test.c @@ -2,8 +2,10 @@ #include void button_event_handler(mui_event_details details, mui_window* window, void** app_data){ - mui_change_object_property(window, "label1", "{\"property\":\"text\",\"value\":\"Hello World!\"}"); - mui_change_object_property(window, "textbox1", "{\"property\":\"text\",\"value\":\"Hello World 2!\"}"); + mui_messagebox("Goodbye!", + mui_inputbox("Say last words!","The last words:","Last words") + , MUI_OK, MUI_INFO); + mui_destroy(window); } void textbox_event_handler(mui_event_details details, mui_window* window, void** app_data){ @@ -17,7 +19,7 @@ void textbox_event_handler(mui_event_details details, mui_window* window, void** void main(int argc, char** argv){ mui_init(argc, argv); mui_window* window = mui_create("{\"title\":\"Hello World\", \"width\":450, \"height\":250}"); - mui_button(window, "{\"id\":\"button1\", \"x\":\"10%x\", \"y\":\"10\", \"width\":\"80%x\", \"text\": \"Button\"}", *button_event_handler); + mui_button(window, "{\"id\":\"button1\", \"x\":\"10%x\", \"y\":\"10\", \"width\":\"80%x\", \"text\": \"Destroy the window\"}", *button_event_handler); mui_label(window, "{\"id\":\"label1\", \"x\":\"10%x\", \"y\":\"50\", \"width\":\"80%x\", \"text\": \"This is a label\"}", *mui_empty_fn); mui_textbox(window, "{\"id\":\"textbox1\", \"x\":\"10%x\", \"y\":\"90\", \"width\":\"80%x\", \"text\": \"This is a textbox\"}", *textbox_event_handler); mui_run(window);