Skip to content

Commit

Permalink
Add -> Ask Quit Dialog & Quit Function
Browse files Browse the repository at this point in the history
Warnings:
Deprecated -> mui.run(mut app)
Use Instead -> app.run()
  • Loading branch information
malisipi committed Jul 11, 2022
1 parent 89117d5 commit 36ed830
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 21 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mut app:=m.create(m.WindowConfig{ title:"Counter - MUI Example", height:100, wid
app.label(m.Widget{ id:"count", x:"5%x", y:"5%y", width:"45%x", height:"90%y" text:"0" })
app.button(m.Widget{ id:"count_button", x:"# 5%x", y:"5%y", width:"45%x", height:"90%y", text:"Count", onclick:increase_count })
m.run(mut app)
app.run()
```

You can find more examples in `./examples/` folder.
Expand All @@ -49,7 +49,7 @@ You can find more examples in `./examples/` folder.
* Graphs
* Menubar
* Map
* Scrollbar
* Scrollbar (Verical & Horizontal)
* Screen Reader Support (Experimental)
* Emoji Icon Support
* Dialogs
Expand All @@ -63,6 +63,7 @@ You can find more examples in `./examples/` folder.
* Anchor System
* Transition Animations (Supports Anchors)
* File Drag-n-Drop
* Ask Quit Dialog & Quit Function

## To-Do List

Expand Down
2 changes: 1 addition & 1 deletion examples/anchor_example.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ fn main(){
app.rect(m.Widget{ id:"rect", x:"# 10%x", y:"10%y", width:"30%x", height:"30%y" })
app.rect(m.Widget{ id:"rect", x:"10%x", y:"# 10%y", width:"30%x", height:"30%y" })
app.rect(m.Widget{ id:"rect", x:"# 10%x", y:"# 10%y", width:"30%x", height:"30%y" })
m.run(mut app)
app.run()

}
2 changes: 1 addition & 1 deletion examples/cells.v
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ for r in 0..rows {

app.rect(m.Widget{ id:"rect3", x:"& 0", y:"& 0", width:cell_size[0], height:cell_size[1], placeholder:"0", ph_as_text:true })

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/change_object_type.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ fn change_type(event_details m.EventDetails, mut app &m.Window, app_data voidptr

mut app:=m.create(m.WindowConfig{ title:"Change Type - MUI Example", width:165, height:60, color:m.theme_light})
app.password(m.Widget{ id:"widget", x:"20", y:"20", onchange:change_type })
m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/counter.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ mut app:=m.create(m.WindowConfig{ title:"Counter - MUI Example", height:100, wid
app.label(m.Widget{ id:"count", x:"5%x", y:"5%y", width:"45%x", height:"90%y" text:"0" })
app.button(m.Widget{ id:"count_button", x:"# 5%x", y:"5%y", width:"45%x", height:"90%y", text:"Count", onclick:increase_count })

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/demo.v
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ app.table(m.Widget{ id:"table", table:[["Sam","Johnson","29","United States"],["

app.image(m.Widget{ id:"vlogo", x: "# 0", y:"# 0", path:"v-logo.png", width:128, height:128})

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/demo_with_menubar.v
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ app.table(m.Widget{ id:"table", table:[["Sam","Johnson","29","United States"],["

app.image(m.Widget{ id:"vlogo", x: "# 0", y:"# 0", path:"v-logo.png", width:128, height:128})

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/line_graph.v
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ app.line_graph(m.Widget{ id:"back", x:"25", y:"25", width:"100%x -50", height:"1
]
})

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/map.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mut app:=m.create(m.WindowConfig{ title:"Maps - MUI Examples", width:296, height

app.map(m.Widget{ id:"map", x: "20", y:"20", width:256, height:256})

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/messagebox.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ app.selectbox(m.Widget{ id:"type", x:"5%x", y:"35%y", width:"43%x", height:"10%y
app.selectbox(m.Widget{ id:"icon", x:"# 5%x", y:"35%y", width:"43%x", height:"10%y", list:["info", "warning", "error"] })
app.button(m.Widget{ id:"create", x:"5%x", y:"# 5%y", width:"90%x", height:"10%y", text:"Create", onclick:create_messagebox })

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/player.v
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,5 @@ fn main(){
app.slider(mui.Widget{ id:"volume_slider", x: "# 40", y:"# 10", width:"60", height:25, value:100, value_max:100, step:10, onunclick:change_vol })

go update_play_slider(mut app, mut &app_data)
mui.run(mut app)
app.run()
}
9 changes: 9 additions & 0 deletions examples/quit_dialog.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import malisipi.mui as m

mut app:=m.create(m.WindowConfig{ title:"Quit Dialog - MUI Examples", ask_quit:true,
quit_fn: fn (e m.EventDetails, mut app &m.Window, a voidptr){
m.messagebox("Goodbye!","Bye","ok","info")
}
})

app.run()
2 changes: 1 addition & 1 deletion examples/remove_object.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ fn delete_me(event_details m.EventDetails, mut app &m.Window, app_data voidptr){

mut app:=m.create(m.WindowConfig{ title:"Delete Object - MUI Example", width:165, height:60})
app.button(m.Widget{ id:"button", x:"20", y:"20", text:"Delete Me" onclick:delete_me })
m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/scrollbar_control.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mut app:=m.create(m.WindowConfig{title:"Scrollbar Test - MUI Examples", width:40

app.rect(m.Widget{ id:"test", x: "0", y:"0", width:600, height:600})

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/scrollbar_example.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ app.label(m.Widget{ id:"text1", x:"10%x", y:"50", width:"80%x", height:"50" text
app.label(m.Widget{ id:"text2", x:"& 10%x", y:"& 125", width:"80%x", height:"50" text:"Example Text 2 - Fixed Position" })
app.label(m.Widget{ id:"text3", x:"10%x", y:"650", width:"80%x", height:"50" text:"Example Text 3 - Hi!" })

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/transition_example.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ mut app:=m.create(m.WindowConfig{ title:"Transition - MUI Example", height:600,
app.image(id:"image", x:300, y:300, height:100, width:100, path:"v-logo.png")
app.button(id:"move", x:30, y:30, height:30, width:70, text:"Move", onclick:move_image)

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/transition_example_with_anchor.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ mut app:=m.create(m.WindowConfig{ title:"Transition With Anchor - MUI Example",
app.image(id:"image", x:"5%x +15", y:"# 25", height:100, width:100, path:"v-logo.png")
app.button(id:"move", x:30, y:30, height:30, width:70, text:"Move", onclick:move_image)

m.run(mut app)
app.run()
2 changes: 1 addition & 1 deletion examples/vert_slider.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import malisipi.mui
fn main(){
mut app:=mui.create(mui.WindowConfig{ title:"Vertical Slider - MUI Example", height: 350, width:350})
app.slider(mui.Widget{ id:"@scrollbar:horizontal", x: 10, y:10, width:25, height:200, value_max:10, vertical:true})
mui.run(mut app)
app.run()
}


20 changes: 17 additions & 3 deletions mui.v
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub fn create(args &WindowConfig) &Window{
app_data: args.app_data
screen_reader: if args.screen_reader { check_screen_reader() } else { false }
file_handler: args.file_handler
ask_quit: args.ask_quit
quit_fn: args.quit_fn
}

mut emoji_font:=args.font
Expand Down Expand Up @@ -286,11 +288,19 @@ fn unclick_fn(x f32, y f32, mb gg.MouseButton, mut app &Window){

[unsafe]
fn event_fn(event &gg.Event, mut app &Window){
if event.typ==sapp.EventType.files_droped{
if event.typ == sapp.EventType.files_droped{
for q in 0..dropped_files_len(){
app.file_handler(EventDetails{event:"files_drop",trigger:"mouse_left", value:dropped_file_path(q)},mut app, mut app.app_data)
}

} else if event.typ == sapp.EventType.quit_requested {
sapp.cancel_quit()
if app.ask_quit {
if messagebox("Quit?", "Do you want to quit?", "yesno", "quit")==0 { //if no
return
}
}
app.quit_fn(EventDetails{event:"quit",trigger:"quit",value:"true"},mut app, mut app.app_data)
sapp.quit()
}
}

Expand Down Expand Up @@ -480,6 +490,10 @@ fn keydown_fn(c gg.KeyCode, m gg.Modifier, mut app &Window){
}
}

pub fn run(mut app &Window){
pub fn (mut app Window) run () {
app.gg.run()
}

pub fn (mut app Window) destroy () {
sapp.quit()
}
4 changes: 4 additions & 0 deletions types.v
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub mut:
scrollbar bool //= false
view_area []int = [-1,-1]
file_handler OnEvent = empty_fn
ask_quit bool //= false
quit_fn OnEvent = empty_fn
}

pub struct EventDetails{
Expand Down Expand Up @@ -71,6 +73,8 @@ pub mut:
scroll_x int
scroll_y int
file_handler OnEvent
ask_quit bool
quit_fn OnEvent
}

pub struct Widget {
Expand Down

0 comments on commit 36ed830

Please sign in to comment.