Skip to content

Commit

Permalink
optimize gui and uitemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalgust committed Jul 28, 2024
1 parent d005c68 commit 9febe23
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 185 deletions.
76 changes: 41 additions & 35 deletions extlib/xgui/src/main/java/org/mini/apploader/AppManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.mini.apploader.bean.LangBean;
import org.mini.explorer.ExplorerScriptLib;
import org.mini.explorer.XExplorerHolder;
import org.mini.gui.HttpRequestReply;
import org.mini.explorer.XExplorer;
import org.mini.explorer.XPage;
Expand Down Expand Up @@ -39,47 +40,47 @@ public class AppManager extends GApplication {
static final String STR_PLUGIN = "PLUGIN";
static final String STR_DISCOVERY = "DISCOVERY";
static final String STR_MY = "MY";
static final String STR_EXIT = "Exit";
static final String STR_EXIT = "STR_EXIT";
static final String STR_SETTING = "SETTING";
static final String STR_TITLE = "PLUGIN MANAGER";
static final String STR_START_WEB_SRV_FOR_UPLOAD = "Lan webserver for upload plugin";
static final String STR_DOWN_APP_FROM_WEB = "Download plugin from website:";
static final String STR_DOWNLOAD = "Download";
static final String STR_START = "Start";
static final String STR_STOP = "Stop";
static final String STR_CLOSE = "Close";
static final String STR_WEB_LISTEN_ON = "Lan webserver on:";
static final String STR_APP_LIST = "Plugin list : ";
static final String STR_BACK = "Back";
static final String STR_RUN = "Run";
static final String STR_SET_AS_BOOT = "Put on top";
static final String STR_UPGRADE = "upgrade";
static final String STR_DELETE = "Delete";
static final String STR_VERSION = "Version: ";
static final String STR_UPGRADE_URL = "Upgrade url: ";
static final String STR_FILE_SIZE = "File size: ";
static final String STR_FILE_DATE = "File date: ";
static final String STR_DESC = "Description: ";
static final String STR_SERVER_STARTED = "Webserver started";
static final String STR_SERVER_STOPED = "Webserver stoped";
static final String STR_UPLOAD_FILE = "Uploaded file";
static final String STR_SUCCESS = "Success";
static final String STR_FAIL = "Fail";
static final String STR_OPEN_APP_FAIL = "Open plugin failed";
static final String STR_BRIGHT_STYLE = "Bright appearance";
static final String STR_DARK_STYLE = "Dark appearance";
static final String STR_MESSAGE = "Message";
static final String STR_CONFIRM_DELETE = "Do you confirm to delete the plugin ";
static final String STR_APP_NOT_RUNNING = "Plugin is not running ";
static final String STR_INSTALL_FROM_LOCAL = "Install plugin from local file:";
static final String STR_SELECT_FILE = "Browse File";
static final String STR_START_WEB_SRV_FOR_UPLOAD = "STR_START_WEB_SRV_FOR_UPLOAD";
static final String STR_DOWN_APP_FROM_WEB = "STR_DOWN_APP_FROM_WEB";
static final String STR_DOWNLOAD = "STR_DOWNLOAD";
static final String STR_START = "STR_START";
static final String STR_STOP = "STR_STOP";
static final String STR_CLOSE = "STR_CLOSE";
static final String STR_WEB_LISTEN_ON = "STR_WEB_LISTEN_ON";
static final String STR_APP_LIST = "STR_APP_LIST";
static final String STR_BACK = "STR_BACK";
static final String STR_RUN = "STR_RUN";
static final String STR_SET_AS_BOOT = "STR_SET_AS_BOOT";
static final String STR_UPGRADE = "STR_UPGRADE";
static final String STR_DELETE = "STR_DELETE";
static final String STR_VERSION = "STR_VERSION";
static final String STR_UPGRADE_URL = "STR_UPGRADE_URL";
static final String STR_FILE_SIZE = "STR_FILE_SIZE";
static final String STR_FILE_DATE = "STR_FILE_DATE";
static final String STR_DESC = "STR_DESC";
static final String STR_SERVER_STARTED = "STR_SERVER_STARTED";
static final String STR_SERVER_STOPED = "STR_SERVER_STOPED";
static final String STR_UPLOAD_FILE = "STR_UPLOAD_FILE";
static final String STR_SUCCESS = "STR_SUCCESS";
static final String STR_FAIL = "STR_FAIL";
static final String STR_OPEN_APP_FAIL = "STR_OPEN_APP_FAIL";
static final String STR_BRIGHT_STYLE = "STR_BRIGHT_STYLE";
static final String STR_DARK_STYLE = "STR_DARK_STYLE";
static final String STR_MESSAGE = "STR_MESSAGE";
static final String STR_CONFIRM_DELETE = "STR_CONFIRM_DELETE";
static final String STR_APP_NOT_RUNNING = "STR_APP_NOT_RUNNING";
static final String STR_INSTALL_FROM_LOCAL = "STR_INSTALL_FROM_LOCAL";
static final String STR_SELECT_FILE = "STR_SELECT_FILE";


static AppManager instance = new AppManager();

// GApplication preApp;

GForm mgrForm;
PluginMgrForm mgrForm;
XExplorer explorer;

GViewSlot mainSlot;
Expand Down Expand Up @@ -497,7 +498,7 @@ void initExplorer() {
GContainer wv = GToolkit.getComponent(mgrForm, "TD_DISCOVERY");
explorer = new XExplorer(wv, eventHandler, assist);
queryServerPolicy();
wv.getInterpreter("ROOT_PAN").reglib(new ExplorerScriptLib(getForm(), explorer));
wv.getInterpreter("ROOT_PAN").reglib(new ExplorerScriptLib(getForm(), mgrForm));
}

void queryServerPolicy() {
Expand Down Expand Up @@ -732,7 +733,7 @@ public static String getDateString(long millis) {
}


class PluginMgrForm extends GForm implements GuiScriptEnvVarAccessor {
class PluginMgrForm extends GForm implements GuiScriptEnvVarAccessor, XExplorerHolder {

public PluginMgrForm(GForm form) {
super(form);
Expand Down Expand Up @@ -836,6 +837,11 @@ public String getEnv(String key) {
public void setEnv(String key, String value) {
AppLoader.setProperty(key, value);
}

@Override
public XExplorer getExplorer() {
return explorer;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
*/
public class ExplorerScriptLib extends Lib {
GForm form;
XExplorer explorer;
XExplorerHolder holder;

/**
*
*/
public ExplorerScriptLib(GForm form, XExplorer explorer) {
public ExplorerScriptLib(GForm form, XExplorerHolder holder) {
this.form = form;
this.explorer = explorer;
this.holder = holder;

// script method register
{
Expand All @@ -58,11 +58,11 @@ public DataType openPage(ArrayList<DataType> para) {
String href = Interpreter.popBackStr(para);
String callback = Interpreter.popBackStr(para);
if (href != null) {
XPage page = explorer.getCurrentPage();
XPage page = holder.getExplorer().getCurrentPage();
if (page != null) {// may be href="/abc/c.xml"
href = XUrlHelper.normalizeUrl(page.getUrl(), href); //fix as : http://www.abc.com/abc/c.xml
}
explorer.gotoPage(href);
holder.getExplorer().gotoPage(href);
GuiScriptLib.doCallback(form, callback, href, 0, "");
}
return null;
Expand All @@ -73,7 +73,7 @@ public DataType downloadInstall(ArrayList<DataType> para) {
String href = Interpreter.popBackStr(para);
String callback = Interpreter.popBackStr(para);
if (href != null) {
XPage page = explorer.getCurrentPage();
XPage page = holder.getExplorer().getCurrentPage();
if (page != null) {// may be href="/abc/c.xml"
href = XUrlHelper.normalizeUrl(page.getUrl(), href); //fix as : http://www.abc.com/abc/c.zip
}
Expand All @@ -96,7 +96,7 @@ public DataType downloadSave(ArrayList<DataType> para) {
String href = Interpreter.popBackStr(para);
String callback = Interpreter.popBackStr(para);
if (href != null) {
XPage page = explorer.getCurrentPage();
XPage page = holder.getExplorer().getCurrentPage();
if (page != null) {// may be href="/abc/c.xml"
href = XUrlHelper.normalizeUrl(page.getUrl(), href); //fix as : http://www.abc.com/abc/c.zip
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.mini.explorer;

public interface XExplorerHolder {
XExplorer getExplorer();
}
2 changes: 1 addition & 1 deletion extlib/xgui/src/main/java/org/mini/explorer/XPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public XPage(String homeUrl, XExplorer explorer) {

this.assistDelegate = new XmlExtAssist(explorer.getAssist().getForm());
this.assistDelegate.copyFrom(explorer.getAssist());
this.assistDelegate.addExtScriptLib(new ExplorerScriptLib(assistDelegate.getForm(), explorer));
this.assistDelegate.addExtScriptLib(new ExplorerScriptLib(assistDelegate.getForm(), (XExplorerHolder) assistDelegate.getForm()));
}

public GContainer getGui(float width, float height) {
Expand Down
2 changes: 1 addition & 1 deletion extlib/xgui/src/main/java/org/mini/gui/GListItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public boolean paint(long vg) {
float th = list.list_item_heigh - pad;

// nvgSave(vg);
Nanovg.nvgScissor(vg, tx, ty, tw, th);
// Nanovg.nvgScissor(vg, tx, ty, tw, th);


if (list.isSelected(getIndex())) {
Expand Down
2 changes: 1 addition & 1 deletion extlib/xgui/src/main/java/org/mini/gui/GStyleBright.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public float[] getPopBackgroundColor() {
return popBackgroundColor;
}

float[] highColor = nvgRGBA(0x65, 0xc4, 0x67, 0xff);//65c467
float[] highColor = nvgRGBA(0xff, 0xff, 0xff, 0xd0);//0x006080ff

public float[] getHighColor() {
return highColor;
Expand Down
2 changes: 1 addition & 1 deletion extlib/xgui/src/main/java/org/mini/gui/GStyleDark.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public float[] getPopBackgroundColor() {
return popBackgroundColor;
}

float[] highColor = nvgRGBA(0x65, 0xc4, 0x67, 0xff);//65c467
float[] highColor = nvgRGBA(0xff, 0xff, 0xff, 0x80);//

public float[] getHighColor() {
return highColor;
Expand Down
4 changes: 2 additions & 2 deletions extlib/xgui/src/main/java/org/mini/gui/GSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void drawSliderH(long vg, float x, float y, float w, float h) {
float dy = h * .5f;
byte[] bg, knob;

float[] back1 = switcher ? GToolkit.getStyle().getHighColor() : nvgRGBA(0, 0, 0, 32);
float[] back1 = nvgRGBA(0, 0, 0, 32);
float[] back2 = nvgRGBA(0, 0, 0, 128);
// Slot
bg = nvgBoxGradient(vg, x, y, w, h, r, 3.0f, back1, back2);
Expand All @@ -123,7 +123,7 @@ void drawSliderH(long vg, float x, float y, float w, float h) {
knob = nvgLinearGradient(vg, x + dx + 1, y + dy + 1, r - 3, r - 3, nvgRGBA(255, 255, 255, 0x30), nvgRGBA(0, 0, 0, 16));
nvgBeginPath(vg);
nvgCircle(vg, x + dx, y + dy, r - 5 * zoom);
nvgFillColor(vg, GToolkit.getStyle().getBackgroundColor());
nvgFillColor(vg, switcher ? GToolkit.getStyle().getHighColor() : GToolkit.getStyle().getLowColor());
nvgFill(vg);
nvgFillPaint(vg, knob);
nvgFill(vg);
Expand Down
11 changes: 7 additions & 4 deletions extlib/xgui/src/main/java/org/mini/gui/GTextBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -801,15 +801,18 @@ int getCaretIndexFromArea(int x, int y) {
}
}
int ci = detail[AREA_LINE_END_AT] + 1;
if (textsb.codePointAt(ci - 1) == '\n') {//
if (ci > textsb.length()) {
ci= textsb.length();
}
if (textsb.codePointAt(ci - 1) == '\n') {//取得离光标最近的字符位置,如果光标在行尾,则返回光标所在行尾字符位置
return detail[AREA_LINE_END_AT];
}
return ci;
}
}
}
}
return textsb.length() - 1; //只可能在下方空白区域点,那就把光标放在最后的位置
return textsb.length(); //只可能在下方空白区域点,那就把光标放在最后的位置
}


Expand Down Expand Up @@ -915,8 +918,8 @@ void drawTextBox(long vg, float x, float y, float w, float h) {
int nrows, i, char_count;
float caretx = 0, carety = 0;

Nanovg.nvgScissor(vg, text_area[LEFT], text_area[TOP], text_area[WIDTH], text_area[HEIGHT]);
Nanovg.nvgIntersectScissor(vg, tbox.getX(), tbox.getY(), tbox.getW(), tbox.getH());
// Nanovg.nvgScissor(vg, text_area[LEFT], text_area[TOP], text_area[WIDTH], text_area[HEIGHT]);
// Nanovg.nvgIntersectScissor(vg, tbox.getX(), tbox.getY(), tbox.getW(), tbox.getH());
//需要恢复现场
try {

Expand Down
2 changes: 1 addition & 1 deletion extlib/xgui/src/main/java/org/mini/layout/UITemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public UITemplate(String data) {
* @param data
*/
void load(String data) {
Pattern p = Pattern.compile("\\{[^\\{^\\}]+\\}");
Pattern p = Pattern.compile("\\{[a-zA-Z_0-9]+\\}");
Matcher m = p.matcher(data);
ArrayList<String> p_array = new ArrayList();
ArrayList<String> v_array = new ArrayList();
Expand Down
1 change: 1 addition & 0 deletions extlib/xgui/src/main/java/org/mini/layout/XContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ public void parseText(KXmlParser parser) throws Exception {
if (tmp.length() > 0) {
XLabel label = new XLabel(this);
label.assist = assist;
label.multiLine = true;
label.setText(tmp);
children.add(label);
}
Expand Down
4 changes: 2 additions & 2 deletions extlib/xgui/src/main/resource/res/base.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cver=1.0.0
sver=2
jar=pc
from=ysbit
jar=ios
from=apple
policyUrl=http://127.0.0.1:30005/account/policy
Loading

0 comments on commit 9febe23

Please sign in to comment.