Skip to content

Commit

Permalink
Add Keybindings Support
Browse files Browse the repository at this point in the history
  • Loading branch information
malisipi committed Jul 19, 2022
1 parent 30aea59 commit 3584306
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 25 deletions.
49 changes: 26 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ app.run()
* Codefield
* Scrollbar (Verical & Horizontal)
* Custom/Thirdparty Widget Support (Not Finished Completely Yet)
* Screen Reader Support (Experimental - Desktop Only)
* Screen Reader Support (Experimental - Linux & Windows Only)
* Emoji Icon Support (Desktop Only)
* Dialogs
* Messagebox (Tinyfiledialogs & built-in & web)
Expand All @@ -71,31 +71,34 @@ app.run()
* Transition Animations (Supports Anchors)
* File Drag-n-Drop (Desktop Only)
* Ask Quit Dialog & Quit Function (Desktop Only)
* Keybindings (Ctrl+Key Combinations for now) _Will be ignored pressed keys/key combinations that used by widgets if the assigned function to the key/key combination._

## To-Do List

* Syntax Highlighting For Codefield
* Tabs
* Treeview
* Status Bar
* Spinner
* Spin Button
* Editable Label
* Disable Status (for Buttons, Checkboxs, Selectboxs, etc.)
* Custom Colors for Widgets (except Themes)
* Handle Appearance Preferences (like Background Color, Text Color)
* Improve Light Theme
* GUI Builder
* Hot Code Reloading
* Load UI from External XML/JSON File
* Improve Documentation
* Context Menu
* Bar Chart
* Pie Chart
* Column Chart
* Gauge chart
* Area Graph
* Keybindings
* Widgets:
* Tabs
* Treeview
* Status Bar
* Spinner
* Spin Button
* Editable Label
* Bar Chart
* Pie Chart
* Column Chart
* Gauge chart
* Area Graph
* Themes:
* Custom Colors for Widgets (except Themes)
* Handle Appearance Preferences (like Background Color, Text Color)
* Improve Light Theme
* Other:
* Context Menu
* Syntax Highlighting For Codefield
* Hot Code Reloading
* Disable Status (for Buttons, Checkboxs, Selectboxs, etc.)
* Load UI from External XML/JSON File
* Improve Documentation
* GUI Builder

## Installation

Expand Down
9 changes: 8 additions & 1 deletion events.v
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,14 @@ fn char_fn(chr u32, mut app &Window){
$if android{
return
}
keyboard_fn(chr, mut app)
if app.gg.key_modifiers==.ctrl {
chr_keybinding:="ctrl|"+utf32_to_str(chr).to_lower()
if app.keybindings[chr_keybinding].num!=120 {
app.keybindings[chr_keybinding].fun(EventDetails{event:"keypress",trigger:"keyboard",value:chr_keybinding}, mut app, mut app.app_data)
}
} else {
keyboard_fn(chr, mut app)
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions examples/keybindings.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import malisipi.mui as m

mut app:=m.create(m.WindowConfig{ title:"Keybindings - MUI Example", height:400, width:400 })

app.label(m.Widget{ id:"label", x:"5%x", y:"5%y", width:"90%x", height:"90%y", text_size:20, text_align:0,
text:"Keybindings:\n Ctrl+P:Print Hello! to console\n Ctrl+C:Change the text\n Ctrl+Q:Quit application",
text_multiline:true })

app.keybindings["ctrl|p"].fun=fn (event_details m.EventDetails, mut app &m.Window, mut app_data voidptr){ print("Hello!\n") }

app.keybindings["ctrl|c"].fun=fn (event_details m.EventDetails, mut app &m.Window, mut app_data voidptr){ unsafe {
app.get_object_by_id("label")[0]["text"].str="The text changed!"
} }

app.keybindings["ctrl|q"].fun=fn (event_details m.EventDetails, mut app &m.Window, mut app_data voidptr){ app.destroy() }

app.run()
3 changes: 2 additions & 1 deletion types.v
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ pub mut:
ask_quit bool
quit_fn OnEvent
active_dialog string //= "" //messagebox, input, password, progress, color, date, notification, openfile, savefile, openfolder, custom
dialog_answer string = dialogs_null_answer
dialog_answer string = dialogs_null_answer
dialog_objects []map[string]WindowData // for dialogs
custom_widgets []CustomWidget
keybindings map[string]WindowData = map[string]WindowData{}
}

pub struct Widget {
Expand Down

0 comments on commit 3584306

Please sign in to comment.