Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awtk.ts中的类型提问 #2

Open
cake221 opened this issue Dec 25, 2019 · 26 comments
Open

awtk.ts中的类型提问 #2

cake221 opened this issue Dec 25, 2019 · 26 comments

Comments

@cake221
Copy link

cake221 commented Dec 25, 2019

image

button_create 声明的是返回 TWidget。

image

但是在 TButton.create()中使用的时候,返回的是nativeObj。

是不是个bug?

@xianjimli
Copy link
Member

好的,谢谢。是BUG。

@cake221
Copy link
Author

cake221 commented Dec 25, 2019

TBitmap
TCanvas
TRect
TVgcanvas
TValue
TInputMethod
TFontManager
TObject
TImageManager
TLocaleInfo
TStyle
TTheme
TNamedValue
TEvent
TEmitter
TColor
TDateTime
TAssetInfo
TAssetsManager
还有些 Event和info也存在类似的问题。

@cake221
Copy link
Author

cake221 commented Dec 25, 2019

我刚才尝试的解决了一下这个问题。我觉得,这个问题的根源是没有把awtk的 原生js接口 和 js封装 分开。我觉得,应该按照awtk释放出来的接口,先写一个native.d.ts文件,然后在这个文件的基础上写awtk.ts。具体的话,就是

  1. 把现在awtk.ts里面的大部分enum抽离到native.d.ts,因为它本身就是awtk原来定义的。
  2. 把原生函数抽离到native.d.ts中。这个过程中,就需要将用了类似于TWidget等的错误的声明,重新定义一下。比如定义成 interface TWidgetNativeObj{}。然后替换原先的Twidget。

@xianjimli
Copy link
Member

你更新一下再试试。谢谢

@cake221
Copy link
Author

cake221 commented Dec 25, 2019

嗯嗯。谢谢您。

@cake221
Copy link
Author

cake221 commented Dec 26, 2019

请问一下,可以用nodejs调用AWTK么?

@xianjimli
Copy link
Member

周末我加个nodejs绑定吧

@cake221
Copy link
Author

cake221 commented Dec 26, 2019

感觉你太强了。敬佩之情油然而生。

@cake221
Copy link
Author

cake221 commented Dec 28, 2019

捕获

请问一下,TCheckButton 的create、 createRadio函数返回的事 TCheckButton类型还是 TWidget 类型。

@xianjimli
Copy link
Member

好的,谢谢。你更新一下。

@xianjimli
Copy link
Member

nodejs绑定基本功能可以用了(nodejs可能需要比较新的版本),你有空试试:https://github.com/zlgopen/awtk-nodejs

@cake221
Copy link
Author

cake221 commented Dec 28, 2019

嗯嗯。谢谢,谢谢。

@xianjimli
Copy link
Member

完善了Linux和Windows编译,你再更新一下。谢谢

@cake221
Copy link
Author

cake221 commented Dec 29, 2019

windows 现在没有任何问题。
linux还是昨天的问题。我在想可能是我把代码放在windows的共享文件夹里的原因。我找个时间,把代码都导在linux环境下,试一下。谢谢您了。

@xianjimli
Copy link
Member

好的。node-gyp要安装成全局的。

@cake221
Copy link
Author

cake221 commented Dec 29, 2019

果然是因为代码在windows的共享文件夹里的原因。全部安装在linux下,就好使了。

谢谢您了。

@xianjimli
Copy link
Member

好的,不客气。

@cake221
Copy link
Author

cake221 commented Dec 30, 2019

请问一下,通过事件函数找到原控件的接口是 XXX.cast(evt.target)么?

比如:

var btn = TCheckButton.createRadio(null, 0, 0, 0, 0);
 btn.on(TEventType.VALUE_CHANGED, function(evt) { 
    var btnCast = TCheckButton.cast(evt.target)
    return TRet.OK;
  });

btnCast 是 btn 么?

@xianjimli
Copy link
Member

你参考一下button.js:

  ok.on(TEventType.CLICK, function(evt) {
    var e = TPointerEvent.cast(evt);
    var target = TButton.cast(e.target);

    console.log("click at " + e.x + " " + e.y + " on " + target.name);
    console.log("global: " + TGlobal.getPointerX() + " " + TGlobal.getPointerY() + " " + TGlobal.isPointerPressed());

    return TRet.OK;
  });

@cake221
Copy link
Author

cake221 commented Dec 30, 2019

在 awtk-nodejs 中的 .\demos\check_button.js。如下,

var awtk = require('../awtk').init(320, 480, 'Hello-AWTK');
for(key in awtk)  global[key] = awtk[key];

function createCheckButton(win, radio, text, x, y, w, h) {
  var btn = null;
  
  if(radio) {
    btn = TCheckButton.createRadio(win, x, y, w, h);
  } else {
    btn = TCheckButton.create(win, x, y, w, h);
  }

  btn.on(TEventType.VALUE_CHANGED, function(evt) { 
    var test = TCheckButton.cast(evt.target)
    console.log(test.name + ' changed. ' + (test.value))
    console.log(btn.name + ' changed. ' + (btn.value))
    return TRet.OK;
  });

  btn.setName(text);
  btn.setText(text);

  return btn;
}

function applicationInit() {
  var win = TWindow.create(null, 0, 0, 0, 0);

  var btn1 = createCheckButton(win, false, 'Zzzzzz', 10, 10, 128, 30);
  var btn2 = createCheckButton(win, false, 'Lzzzzz', 10, 50, 128, 30);
  var btn3 = createCheckButton(win, false, 'Gzzzzz', 10, 90, 128, 30);
   
  var btn4 = createCheckButton(win, true, 'Aaaaaa', 10, 10+128, 128, 30);
  var btn5 = createCheckButton(win, true, 'Waaaaa', 10, 50+128, 128, 30);
  var btn6 = createCheckButton(win, true, 'Tttttt', 10, 90+128, 128, 30);
  var btn7 = createCheckButton(win, true, 'Kkkkkk', 10, 130+128, 128, 30);

  win.layout();
}

applicationInit()

btn.on(TEventType.VALUE_CHANGED 函数中, 我添加了

var test = TCheckButton.cast(evt.target)
console.log(test.name + ' changed. ' + (test.value))

当我点击时候,出现了错误。报错如下:
捕获

请问一下,这个错误在哪?

@xianjimli
Copy link
Member

xianjimli commented Dec 31, 2019

这样试试:

var target = TEvent.cast(evt).target;
var test = TCheckButton.cast(target)

@cake221
Copy link
Author

cake221 commented Jan 1, 2020

抱歉抱歉。没有仔细看button的例子。谢谢您的耐心解答。确实可以。

2020.1.1。新年快乐。祝您身体健康,工作顺利。祝awtk生态越来越好,来年有更多的人加入其中。

@xianjimli
Copy link
Member

好的,新年快乐!

@cake221
Copy link
Author

cake221 commented Jan 1, 2020

在./demo/js/progress_bar.js中,
捕获
TTimer.add(),有三个输入,但是目前只有两个。

@cake221
Copy link
Author

cake221 commented Jan 1, 2020

上个问题是,500是 duration ,应该是放在第三个参数上。现在放在了第二个参数里。

@xianjimli
Copy link
Member

好的,谢谢。已修改,你更新代码试试。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants