Giter Club home page Giter Club logo

Comments (47)

ying32 avatar ying32 commented on May 26, 2024 1

AnchorHorizontalCenterTo,AnchorVerticalCenterTo只有继承自TControl的才有的,绘制这里确实像出了问题,我在找原因

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

是特意不导出的,至于*const c_char这些要像govcl的做法才能消除

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

好的 感谢回答。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

请教一下,
tv1.Items().AddChild(nil, "首个")
这里nil应该传什么

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

有一个单独的函数 Null()

tv1.Items().AddChild(&Null(), "首个")

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

我知道,但是似乎不能用

253 |         let node = self.tv1.Items().AddChild(&Null(), "首个");
    |                                              ^^^^^^^ expected struct `rust_vcl::vcl::TTreeNode`, found struct `rus
t_vcl::vcl::TNull`
    |

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

好像是哦,唉,明天改吧。。。睡觉了

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

晚安。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

这样倒是可以用:

        let first_node = unsafe {
             transmute::<TNull, TTreeNode>(Null())
        };

另外

let node = tv1.GetNodeAt(x, y);

rust-vcl里似乎没有TTreeNode::IsVaild方法,没法判断是否有效。

缺少TCanvas::TextRect2方法

Draw1方法需要TGraphic类型,TJPEGImage无法绘制。

canvas.Draw1(0, 80, &self.jpg);

rust里好像实现From和Into的trait来提供from和into接口用来做类型转换,类似:

TTreeNode::from(Null())
TJPEGImage::into() -> TGraphic

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

更新了一些,可以这样写:

  • Nil对象
// TTreeNode::Nil()

let node = self.tv1.Items().AddChild(&TTreeNode::Nil(), "First");
self.tv1.Items().AddChild(&node, "Sec");
node.Expand(true);
  • 判断IsNil
// obj.IsNil()  

let node = self.tv1.Selected();
if !node.IsNil() {
    println!("node.text = {:}", node.Text());
} else {
    println!("node is nil.");
}
  • 图形对象TGraphic现在都做了接口,可以了。

* TextRect2这个不知道怎么写好,原型为:
pub fn TextRect2(&self, rect: *mut TRect, text: &str, aOutStr: *mut &str, textFormat: TTextFormat) -> i32
其中aOutStr这个不知道咋写好, lclapi包中Canvas_TextRect2AOutStr参数类型为*mut *const c_char

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

好的 谢了。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

再请教一下,关于TListView::SetOnData的回调方法中,签名是:
fn (&self, sender: usize, item: usize)

这个item应该怎么使用,试了几个都会报错。

知道了,用TListItem::As就可以了。

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

嗯:XX::As是专门转换usize到对象的,XX::from是将另一个对象转为当前对象,另外XX.Instance()是原对象的实例指针。

已经实现TextRect2方法:

brush.SetStyle(TBrushStyle::bsClear);
let text = "Test darw text! 你好!";
let font = canvas.Font();
font.SetStyle(0).SetSize(9).SetColor(clBlue);

let mut r2 = cliRect.clone();
canvas.TextRect2(&mut r2, &text, Include!(0, TTextFormats::tfCenter, TTextFormats::tfVerticalCenter, TTextFormats::tfSingleLine));

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

好的 感谢。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

请教一下,我按照https://github.com/ying32/govcl/blob/master/samples/imagebutton/main.go的代码实现,但是效果跟https://z-kit.cc/screenshot.html的截图不一致,是正常的还是代码有问题:
1

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

你这个显示得有点怪异哦,是2k及以上的屏么?这个按钮目前没做dpi处理的。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

不是 就是1080分辨率。

代码

        self.form.SetCaption("Hello")
            .SetPosition(TPosition::poScreenCenter)
            .SetDoubleBuffered(true)
            .EnabledMaximize(false)
            .SetShowHint(true)
            .SetWidth(300)
            .SetHeight(400);

        self.btnClose.SetParent(self)
                     .SetImageCount(4)
                   // .SetAutoSize(true)
                     .SetLeft(self.form.ClientWidth() - self.btnClose.ClientWidth() - 3)
                     .SetHint("关闭")
                     .Picture().LoadFromFile("./img/btn_close.png");

        self.btnMax.SetParent(self)
                   .SetImageCount(4)
                   .SetAutoSize(true)
                   .SetLeft(self.btnClose.Left() - self.btnMax.Width())
                   .SetHint("最大化")
                   .Picture().LoadFromFile("./img/btn_max.png");

        self.btnMin.SetParent(self)
                   .SetImageCount(4)
                   .SetAutoSize(true)
                   .SetLeft(self.btnMax.Left() - self.btnMin.Width())
                   .SetHint("最小化")
                   .Picture().LoadFromFile("./img/btn_min.png");

        self.btnSkin.SetParent(self)
                    .SetImageCount(3)
                    .SetAutoSize(true)
                    .SetLeft(self.btnMin.Left() - self.btnSkin.Width())
                    .SetHint("皮肤")
                    .Picture().LoadFromFile("./img/btn_skin.png");

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

.SetImageCount(4) 是3吧,我记得我提供的图每个上面只有3个

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

知道了,链式调用在这里有问题必须得先:

        self.btnSkin.SetAutoSize(true)
                    .SetImageCount(3)
                    .Picture().LoadFromFile("./img/btn_skin.png");

        self.btnSkin.SetLeft(self.form.ClientWidth() - self.btnSkin.Width());

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

请教下在实现TListbox::SetOnDrawItem的时候,用
// let text = cls.listbox.Items().Strings(index);
就会Access violation错误,应该怎么获取

self.listbox.SetOnDrawItem(sid, |cls: &TMainForm, control: usize, index: i32, aRect: *mut TRect, state: TOwnerDrawState|{
                let canvas = cls.listbox.Canvas();
                println!("{}", index);
                // cls.listbox.Items().ToString();
                let text = cls.listbox.Items().Strings(index);

                let rect: &TRect = unsafe { &*aRect };
                // // let (w, h) = (canvas.TextWidth(&text), canvas.TextHeight(&text));
                //
                // canvas.Font().SetColor(clBlack);
                // canvas.Brush().SetColor(clBtnFace);
                println!("{:?}", rect);
                // canvas.FillRect(rect);
            });

还有好像缺少AnchorHorizontalCenterTo,AnchorVerticalCenterTo方法,这两个需要自己实现么。

尝试了下,只能用:

self.listbox.SetOnDrawItem(sid, |cls: &TMainForm, control: usize, index: i32, aRect: *mut TRect, state: TOwnerDrawState|{
        // 出现Access violation
        // println!("{}", cls.listbox.Items().Strings(index));
        let listbox: TListBox = TListBox::As(control);
        println!("{}", listbox.Items().Strings(index));
});

这里TDrawItemEvent的第一个参数似乎接收的不对。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

另外个问题:

            self.form.SetOnWndProc(sid, |cls: &TMainForm, msg: *mut TMessage|{
                println!("{}", cls.counter);
                cls.form.InheritedWndProc(msg);

                // match (*msg).msg {
                //      => statement,
                //     _ => statement,
                // }
            });

一设置这个回调运行窗口就无法显示,控制台会出现:

TWinControl.UpdateShowing.ChangeShowing failed for :TGoForm, Showing reset to False

messages.WM_MOUSEMOVE这些常量似乎也没定义。

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

SetOnWndProc的原因是lclapi.rs中的消息回调是空的,没实现。。。
那些消息值引入winapi应该有的。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

哦 好的,麻烦你了。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

@ying32 SetOnDrawItem这里问题是我自己的问题,我省略了几个行代码导致的:

impl TApp {

    fn new() -> Self {
        let app : &TApplication = &Application;

        app.SetMainFormOnTaskBar(true)
            .SetTitle("LCL App")
            .Initialize();

        let form = TMainForm::new();
        form.build();

        Self {
            mainForm: form,
        }
    }
}

fn main() {
    TApp::new().run();
}

不打扰你了 晚安。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

补充下,

        self.listbox.SetOnDrawItem(sid, |cls: &mut TMainForm, control: usize, index: i32, aRect: *mut TRect, state: TOwnerDrawState|{
                let canvas = cls.listbox.Canvas();
		let text = cls.listbox.Items().Strings(index);

                let rect: &TRect = unsafe { &*aRect };
                let (w, h) = (canvas.TextWidth(&text), canvas.TextHeight(&text));
                canvas.Font().SetColor(clBlack);
                canvas.Brush().SetColor(clBtnFace);
                println!("{:?}", rect);
                canvas.FillRect(rect);
                canvas.Brush().SetColor(0x00FFF7F7);
                canvas.Pen().SetColor(clSkyblue);
                canvas.Rectangle(rect.left+1, rect.top+1, rect.right-1, rect.bottom-1);
                canvas.Rectangle(rect.left, rect.top, rect.right, rect.bottom);
                if InSet!(state, TOwnerDrawStateType::odSelected) {
                    canvas.Brush().SetColor(0x00FFB2B5);
                    canvas.Rectangle(rect.left, rect.top, rect.right, rect.bottom);
                //
                    if InSet!(state, TOwnerDrawStateType::odFocused) {
                        canvas.DrawFocusRect(rect);
                    }
                }
                canvas.Font().SetColor(clBlue);
                canvas.TextOut(rect.left+(rect.right-w)/2, rect.top+(ITEM_HEIGHT-h)/2, &text);
            });
    }

绘制的时候时不时会出现:
2

开始以为是坐标位负的问题,偏移几次还是偶尔会出现。

堆栈信息:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NulError(0, [0, 0, 0, 0, 0, 0, 0, 0, 0])', E:\3r
dParty\cargo\git\checkouts\rust-vcl-7a0be4a69e88d19f\9fdfb1f\src\vcl.rs:36043:56
stack backtrace:
   0: core::fmt::write
             at /rustc/6c8927b0cf80ceee19386026cf9d7fd4fd9d486f\/src\libcore\fmt\mod.rs:1117
   1: std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
             at /rustc/6c8927b0cf80ceee19386026cf9d7fd4fd9d486f\/src\libstd\io\mod.rs:1508
   2: std::sys_common::backtrace::_print
             at /rustc/6c8927b0cf80ceee19386026cf9d7fd4fd9d486f\/src\libstd\sys_common\backtrace.rs:62
   3: std::sys_common::backtrace::print
             at /rustc/6c8927b0cf80ceee19386026cf9d7fd4fd9d486f\/src\libstd\sys_common\backtrace.rs:49
   4: std::panicking::default_hook::{{closure}}
             at /rustc/6c8927b0cf80ceee19386026cf9d7fd4fd9d486f\/src\libstd\panicking.rs:198
   5: std::panicking::default_hook
             at /rustc/6c8927b0cf80ceee19386026cf9d7fd4fd9d486f\/src\libstd\panicking.rs:217
   6: std::panicking::rust_panic_with_hook
             at /rustc/6c8927b0cf80ceee19386026cf9d7fd4fd9d486f\/src\libstd\panicking.rs:526
   7: std::panicking::begin_panic_handler
             at /rustc/6c8927b0cf80ceee19386026cf9d7fd4fd9d486f\/src\libstd\panicking.rs:437
   8: core::panicking::panic_fmt
             at /rustc/6c8927b0cf80ceee19386026cf9d7fd4fd9d486f\/src\libcore\panicking.rs:85
   9: core::option::expect_none_failed
             at /rustc/6c8927b0cf80ceee19386026cf9d7fd4fd9d486f\/src\libcore\option.rs:1273
  10: core::result::Result<std::ffi::c_str::CString, std::ffi::c_str::NulError>::unwrap<std::ffi::c_str::CString,std::ff
i::c_str::NulError>
             at D:\Develop\Rust\toolchains\nightly-i686-pc-windows-msvc\lib\rustlib\src\rust\src\libcore\result.rs:1005
  11: rust_vcl::vcl::TCanvas::TextOut
             at E:\3rdParty\cargo\git\checkouts\rust-vcl-7a0be4a69e88d19f\9fdfb1f\src\vcl.rs:36043
  12: listboxcustomdraw::{{impl}}::build::{{closure}}
             at .\src\main.rs:80
  13: core::ops::function::FnOnce::call_once<closure-0,tuple<mut listboxcustomdraw::TMainForm*, usize, i32, mut rust_vcl
::types::TRect*, u32>>
             at D:\Develop\Rust\toolchains\nightly-i686-pc-windows-msvc\lib\rustlib\src\rust\src\libcore\ops\function.rs
:233
  14: rust_vcl::lclapi::doEventCallback
             at E:\3rdParty\cargo\git\checkouts\rust-vcl-7a0be4a69e88d19f\9fdfb1f\src\lclapi.rs:14140

还是代码问题:

		let text = cls.listbox.Items().Strings(index).into_owned();
                let (w, h) = (canvas.TextWidth(&text), canvas.TextHeight(&text));
                canvas.TextOut(rect.left+(rect.right-w)/2, rect.top+(ITEM_HEIGHT-h)/2, &text);

得用into_owned获取所有权不然就会出现上面的问题。

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

我遇到的是x64下的奇怪问题,跟你这差不多,但32位没问题。。。汗Nim和go都没问题,只有Rust有问题,😰😰😰

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

fns.rs中导出了ToRustString替换了原来的宏。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

建议把to_CString也导出,TGetCellHintEvent等方法有*mut *const c_char参数方便使用。

TCheckBoxState实现Copy triat,不然在这样用的时候会出现:

167 |                 *value = self.data[(aRow-1) as usize].CheckBox;
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because value has type `rust_vcl::types::TCheckBoxState`, which does not implement the `Copy` trait

目前得:

                *value = self.data[(aRow-1) as usize].CheckBox.clone();

As和from是不是在rust改成from和into比较好,不然为了避免跟关键字冲突一个大写一个小写不方便记忆。

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

As和from其实我是想合并的,但貌似没找着这法写。。into我看他自带有这个,但貌似跟现在的from功能不相符。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

好的,谢谢。

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

我重新看了下,可能你说的是对的,所以我将原来的As改成from了,from改为into了。

本想实现From这个triat,可惜没成功。。。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

Into那个用法有点问题吧,用起来应该类似这样:

let btn: TButton = comp.into();

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

这样能推导成功?我试试

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

我试了下,不知道咋实现了。。。。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

我也试试了下,只要实现From trait就可以这样使用:

impl From<usize> for TComponent {
    fn from(inst: usize) -> Self {
        TComponent { 0: inst, 1: false }
    }
}

示例:

    let i: usize = 1;

    let comp2 = TComponent::from(i);
    let comp: TComponent = comp2.Instance().into();

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

你这样感觉不对吧。。。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

什么不对

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

假设按你的这样,当 let comp: TButton = comp2.Instance().into()这就不对了吧,而且像这样对象的转换,只需要第self.0的,是不可以去复制sefl.1字段的值的。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024
let comp: TButton = comp2.Instance().into()

我这里可以编译过,
let comp: TButton = comp2.Instance().into() 不就相当于 let comp: TButton = 1.into(),self.1不都是false么

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

不是的,有些不是false

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

但是我看

        pub fn from(inst: usize) -> Self {
            $class { 0: inst, 1: false }
        }

        #[inline]
        pub fn into(obj: &dyn IObject) -> Self {
            $class {
                0: obj.Instance(),
                1: false,
            }
        }

这一段都是false,我这里的代码只是替代了这部分应该没影响吧

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

要是能直接.into就好些,多加个instance感觉就麻烦了

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

from这个是没问题,这个我之前试了

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

确实,有好处有坏处,比如这里:

pub fn SetClipboard(aNewClipboard: &TClipboard) -> TClipboard {
    unsafe { return TClipboard::from(lclapi::DSetClipboard(aNewClipboard.Instance()))}
}

就可以改成

pub fn SetClipboard(aNewClipboard: &TClipboard) -> TClipboard {
    unsafe { return lclapi::DSetClipboard(aNewClipboard.Instance()).into()}
}

还有

        self.btn.SetParent(self)
            .SetCaption("asdfasdf")
            .SetOnClick(self, |cls: &TMainForm, sender: usize|{
                let btn: TButton = sender.into();
                println!("{}", btn.Caption());
            });

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

得再想想, sender.from是可弄成这样,至于into这个得想想。。。我还是想能直接转对象

from rust-vcl.

ying32 avatar ying32 commented on May 26, 2024

得我还是先维持原状,现在什么都编译不通过了。。

from rust-vcl.

bstaint avatar bstaint commented on May 26, 2024

好的。

from rust-vcl.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.