Haxe bindings for koreader
修訂 | 1d4e7e1afd1f7edab6b2724973ad4707c7e152c0 (tree) |
---|---|
時間 | 2022-03-04 07:27:15 |
作者 | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fast...> |
Commiter | Jaime Marquínez Ferrándiz |
Add ButtonDialog
@@ -6,6 +6,7 @@ | ||
6 | 6 | import koreader.ffi.Blitbuffer; |
7 | 7 | import koreader.ui.UIManager; |
8 | 8 | import koreader.ui.widget.Button; |
9 | +import koreader.ui.widget.ButtonDialog; | |
9 | 10 | import koreader.ui.widget.ConfirmBox; |
10 | 11 | import koreader.ui.widget.container.CenterContainer; |
11 | 12 | import koreader.ui.widget.container.FrameContainer; |
@@ -78,6 +79,10 @@ | ||
78 | 79 | callback: displayRegexTest, |
79 | 80 | }), |
80 | 81 | Button.create({ |
82 | + text: "Button dialog", | |
83 | + callback: displayButtonDialog, | |
84 | + }), | |
85 | + Button.create({ | |
81 | 86 | text: "Close", |
82 | 87 | callback: function close() { |
83 | 88 | UIManager.close(mainWindow, Partial); |
@@ -140,4 +145,14 @@ | ||
140 | 145 | var message = InfoMessage.create({text: "Regex result:\n" + text}); |
141 | 146 | UIManager.show(message); |
142 | 147 | } |
148 | + | |
149 | + public static function displayButtonDialog() { | |
150 | + var callback = () -> UIManager.show(InfoMessage.create({text: "Pressed"})); | |
151 | + UIManager.show(ButtonDialog.create({ | |
152 | + buttons: [[ | |
153 | + { text: "Button 1", callback: callback, enabled: false}, | |
154 | + { text: "Button 2", callback: callback}, | |
155 | + ]], | |
156 | + })); | |
157 | + } | |
143 | 158 | } |
\ No newline at end of file |
@@ -0,0 +1,23 @@ | ||
1 | +package koreader.hxutils; | |
2 | + | |
3 | +import lua.Table; | |
4 | + | |
5 | +/** | |
6 | + Helper class to pass arrays to koreader functions | |
7 | +**/ | |
8 | +abstract LuaArray<T>(lua.Table<Int, T>) | |
9 | +{ | |
10 | + inline function new(t:lua.Table<Int, T>) { | |
11 | + this = t; | |
12 | + } | |
13 | + | |
14 | + @:from | |
15 | + static public function fromArray<T>(arr:Array<T>) { | |
16 | + return new LuaArray(lua.Table.fromArray(arr)); | |
17 | + } | |
18 | + | |
19 | + @:to | |
20 | + public function toArray() { | |
21 | + return Table.toArray(this); | |
22 | + } | |
23 | +} | |
\ No newline at end of file |
@@ -0,0 +1,20 @@ | ||
1 | +package koreader.ui.widget; | |
2 | + | |
3 | +import koreader.hxutils.LuaArray; | |
4 | +import koreader.ui.widget.Button.ButtonParams; | |
5 | +import koreader.ui.widget.container.InputContainer; | |
6 | + | |
7 | +@:luaRequire("ui/widget/buttondialog") | |
8 | +@:build(KoreaderMacros.setupKoreaderExternClass()) | |
9 | +extern class ButtonDialog extends InputContainer { | |
10 | + @:native("new") | |
11 | + @:constructor | |
12 | + private function create(params: ButtonDialogParams) : ButtonDialog; | |
13 | +} | |
14 | + | |
15 | +typedef ButtonDialogParams = { | |
16 | + > InputContainerParams, | |
17 | + ?buttons : LuaArray<LuaArray<ButtonParams>>, | |
18 | + ?tap_close_callback : () -> Void, | |
19 | + ?alpha : Float, | |
20 | +} | |
\ No newline at end of file |