Haxe bindings for koreader
修訂 | 136d1542ceb50887873b813bc5fc4d7d559d7381 (tree) |
---|---|
時間 | 2021-03-22 07:51:52 |
作者 | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fast...> |
Commiter | Jaime Marquínez Ferrándiz |
Reuse code from the plugin
@@ -1,3 +1,4 @@ | ||
1 | +import haxeplug.HaxePlugin; | |
1 | 2 | import koreader.ui.widget.container.FrameContainer; |
2 | 3 | import koreader.ui.widget.container.MovableContainer; |
3 | 4 | import koreader.ui.widget.container.CenterContainer; |
@@ -5,8 +6,6 @@ | ||
5 | 6 | import koreader.ui.widget.Button; |
6 | 7 | import koreader.ui.widget.HorizontalGroup; |
7 | 8 | import koreader.ui.UIManager; |
8 | -import koreader.ui.widget.InfoMessage; | |
9 | -import koreader.ui.widget.ConfirmBox; | |
10 | 9 | import koreader.Device; |
11 | 10 | import koreader.Logger; |
12 | 11 |
@@ -15,28 +14,11 @@ | ||
15 | 14 | trace("Haxe trace"); |
16 | 15 | Logger.instance.dbg("Debug information:", 1); |
17 | 16 | |
18 | - var confirm = ConfirmBox.create({ | |
19 | - text: "Confirm box from Haxe", | |
20 | - ok_text: "OK text", | |
21 | - cancel_text: "Cancel text", | |
22 | - // ok_callback: blah, | |
23 | - ok_callback: function ok() { | |
24 | - var message = InfoMessage.create({text: "Accepted"}); | |
25 | - UIManager.show(message); | |
26 | - }, | |
27 | - cancel_callback: function cancel() { | |
28 | - var message = InfoMessage.create({text: "Canceled"}); | |
29 | - UIManager.show(message); | |
30 | - }, | |
31 | - }); | |
32 | - | |
33 | 17 | var grp = HorizontalGroup.create({ |
34 | 18 | widgets: [ |
35 | 19 | Button.create({ |
36 | 20 | text: "Left", |
37 | - callback: function left() { | |
38 | - UIManager.show(confirm); | |
39 | - } | |
21 | + callback: HaxePlugin.displayWindow, | |
40 | 22 | }), |
41 | 23 | VerticalGroup.create({ |
42 | 24 | widgets: [ |
@@ -11,23 +11,25 @@ | ||
11 | 11 | override function addToMainMenu(menu_items : Dynamic) { |
12 | 12 | Plugin.registerTool(menu_items, "hxplugDemo", { |
13 | 13 | text: "Demo haxe plugin", |
14 | - callback: function hxplug() { | |
15 | - var confirm = ConfirmBox.create({ | |
16 | - text: "Confirm box from Haxe plugin", | |
17 | - ok_text: "OK text", | |
18 | - cancel_text: "Cancel text", | |
19 | - ok_callback: function ok() { | |
20 | - var response = HttpHelper.request("https://worldtimeapi.org/api/ip.txt"); | |
21 | - var message = InfoMessage.create({text: "Accepted\n" + response}); | |
22 | - UIManager.show(message); | |
23 | - }, | |
24 | - cancel_callback: function cancel() { | |
25 | - var message = InfoMessage.create({text: "Canceled"}); | |
26 | - UIManager.show(message); | |
27 | - }, | |
28 | - }); | |
29 | - UIManager.show(confirm); | |
14 | + callback: displayWindow, | |
15 | + }); | |
16 | + } | |
17 | + | |
18 | + public static function displayWindow() { | |
19 | + var confirm = ConfirmBox.create({ | |
20 | + text: "Confirm box from Haxe plugin", | |
21 | + ok_text: "OK text", | |
22 | + cancel_text: "Cancel text", | |
23 | + ok_callback: function ok() { | |
24 | + var response = HttpHelper.request("https://worldtimeapi.org/api/ip.txt"); | |
25 | + var message = InfoMessage.create({text: "Accepted\n" + response}); | |
26 | + UIManager.show(message); | |
27 | + }, | |
28 | + cancel_callback: function cancel() { | |
29 | + var message = InfoMessage.create({text: "Canceled"}); | |
30 | + UIManager.show(message); | |
30 | 31 | }, |
31 | 32 | }); |
33 | + UIManager.show(confirm); | |
32 | 34 | } |
33 | 35 | } |
\ No newline at end of file |