More work on TUI (buttons in the viewer window)
authorNiki Roo <niki@nikiroo.be>
Wed, 28 Jun 2017 11:27:19 +0000 (13:27 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 28 Jun 2017 11:27:19 +0000 (13:27 +0200)
src/be/nikiroo/fanfix/reader/TuiReaderApplication.java
src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java
src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java

index 3e9d1d77ed9be35cbb73c31a74096534cd6adb60..94ecfd52104b636e6ad2a4af5bd6c77541403afb 100644 (file)
@@ -48,7 +48,7 @@ public class TuiReaderApplication extends TApplication {
                addWindowMenu();
                addHelpMenu();
 
-               getBackend().setTitle("Testy");
+               getBackend().setTitle("Fanfix");
 
                new TuiReaderMainWindow(this, stories);
        }
index 1de9488ae604a6ac3b070521692cafdaddad01db..55072664e9ae9376a0f7e4f119cbfb81f7d7f8bc 100644 (file)
@@ -3,12 +3,7 @@ package be.nikiroo.fanfix.reader;
 import java.util.ArrayList;
 import java.util.List;
 
-import jexer.TAction;
-import jexer.TList;
-import jexer.TRadioGroup;
-import jexer.TTreeItem;
-import jexer.TTreeView;
-import jexer.TWindow;
+import jexer.*;
 import be.nikiroo.fanfix.data.MetaData;
 
 public class TuiReaderMainWindow extends TWindow {
@@ -29,7 +24,7 @@ public class TuiReaderMainWindow extends TWindow {
                        List<MetaData> stories) {
                // Construct a demo window. X and Y don't matter because it will be
                // centered on screen.
-               super(reader, "Demo Window", 0, 0, 60, 18, CENTERED | RESIZABLE
+               super(reader, "Library", 0, 0, 60, 18, CENTERED | RESIZABLE
                                | UNCLOSABLE);
 
                this.reader = reader;
@@ -54,6 +49,10 @@ public class TuiReaderMainWindow extends TWindow {
                                }
                        }
                });
+               
+               // TODO: add the current "type" or filter
+               statusBar = newStatusBar("Library");
+               statusBar.addShortcutKeypress(TKeypress.kbF10, TCommand.cmExit, "Exit");
 
                if (false) {
                        addLabel("Label (1,1)", 1, 1);
index 47a644edf5789174cf632e8a2dc4692f3103f6c2..9572566fe9e462a14efdb39c09f6dc42cc037612 100644 (file)
@@ -1,8 +1,6 @@
 package be.nikiroo.fanfix.reader;
 
-import jexer.TApplication;
-import jexer.TText;
-import jexer.TWindow;
+import jexer.*;
 import jexer.event.TResizeEvent;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.Chapter;
@@ -23,17 +21,38 @@ public class TuiReaderStoryWindow extends TWindow {
                // : xxx.. > >> (max size for name = getWith() - X)
 
                // TODO: show all meta info before
-
+               // TODO: text.append("Resume:\n\n  "); -> to status bar
+               
+               // -2 because 0-based, 2 for borders, -1 to hide the HScroll
+               textField = addText("", 0, 0, getWidth() - 2, getHeight() - 2);
+               
                Chapter resume = getStory().getMeta().getResume();
-               StringBuilder text = new StringBuilder();
                if (resume != null) {
-                       // TODO: why does \n not work but \n\n do? bug in jexer?
-                       text.append("Resume:\n\n  "); // -> to status bar
                        for (Paragraph para : resume) {
-                               text.append(para.getContent()).append("\n\n  ");
+                               // TODO: This is not efficient, should be changed
+                               for (String line : para.getContent().split("\n")) {
+                                       textField.addLine(line);
+                               }
                        }
                }
-               textField = addText(text.toString(), 0, 0, getWidth(), getHeight());
+               
+               statusBar = newStatusBar(desc(meta));
+               statusBar.addShortcutKeypress(TKeypress.kbF10, TCommand.cmExit, "Exit");
+               
+               // -3 because 0-based and 2 for borders
+               TButton first = addButton("<<", 0,  getHeight() - 3,
+                   new TAction() {
+                       public void DO() {
+                           // TODO
+                       }
+                   }
+               );
+               addButton("<", 3,  getHeight() - 3, null);
+               addButton(">", 5,  getHeight() - 3, null);
+               addButton(">>", 7,  getHeight() - 3, null);
+               // TODO: pad with space up to end of window
+               // TODO: do not show "0/x: " for desc, only for other chapters
+               addLabel(String.format(" %d/%d: %s", resume.getNumber(), getStory().getChapters().size(), resume.getName()), 11, getHeight() - 3);
        }
 
        @Override
@@ -42,7 +61,7 @@ public class TuiReaderStoryWindow extends TWindow {
 
                // Resize the text field
                textField.setWidth(resize.getWidth());
-               textField.setHeight(resize.getHeight());
+               textField.setHeight(resize.getHeight() - 2);
                textField.reflow();
        }