Skip to content

Commit

Permalink
Add destory & messagebox & beep & inputbox support
Browse files Browse the repository at this point in the history
  • Loading branch information
malisipi committed Jan 18, 2023
1 parent 659376d commit c0d850a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
18 changes: 15 additions & 3 deletions c_bindings/mui.h
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
*/
35 changes: 35 additions & 0 deletions c_bindings/mui.v
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
8 changes: 5 additions & 3 deletions c_bindings/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#include <string.h>

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){
Expand All @@ -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);
Expand Down

0 comments on commit c0d850a

Please sign in to comment.