语法突出显示Egui Rust

发布于 2025-01-28 17:22:52 字数 1100 浏览 6 评论 0 原文

我正在使用EGUI在Rust中编辑文本编辑器。我正在尝试实现语法突出显示, 因此,我在 syntax_highlighting 。我有Syntect和Egui都安装了他们的最新版本,并拥有它们 作为依赖。

let mut theme = crate::syntax_highlighting::CodeTheme::from_memory(ui.ctx());
ui.collapsing("Theme", |ui| {
    ui.group(|ui| {
        theme.ui(ui);
        theme.clone().store_in_memory(ui.ctx());
    });
});


let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
    let mut layout_job = 
        crate::syntax_highlighting::highlight(ui.ctx(), &theme, string, self.language);
    layout_job.wrap.max_width = wrap_width;
    ui.fonts().layout_job(layout_job)
};

特别是,正是这些行引起的错误是在板条箱根中找不到 stytax_highlighting 。如果有用,这是我的所有代码: https://pastebin.com/mhdhlhsr

我想对我的egui应用程序进行启发,但是我发现 stytax_highlighting 在板条箱根中找不到的错误,我找到的唯一示例使用了。

I'm writing a text editor in Rust using egui. I am trying to implement syntax highlighting,
so I followed the example in the demo. It works there, so I thought it might be useful. But I am getting an error that syntax_highlighting is not found in the crate root. I have syntect and egui both installed at their latest versions and have them
as dependencies.

let mut theme = crate::syntax_highlighting::CodeTheme::from_memory(ui.ctx());
ui.collapsing("Theme", |ui| {
    ui.group(|ui| {
        theme.ui(ui);
        theme.clone().store_in_memory(ui.ctx());
    });
});


let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
    let mut layout_job = 
        crate::syntax_highlighting::highlight(ui.ctx(), &theme, string, self.language);
    layout_job.wrap.max_width = wrap_width;
    ui.fonts().layout_job(layout_job)
};

In particular, it is these lines that raise the error that syntax_highlighting is not found in the crate root. In case it's useful, here is all my code:
https://pastebin.com/mHDhLhSR

I want to implement syntax highlighting to my egui application, but I get the error that syntax_highlighting is not found in the crate root, which the only example I found used.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燃情 2025-02-04 17:22:52

板条:: 表示 syntax_highlighting egui_demo_lib 板条本身的成员。 In this case, you'll find it right here

The crate:: means syntax_highlighting is a member of the egui_demo_lib crate itself. In this case, you'll find it right here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文