RustのフレームワークにはTauri, Druid, egiなどがある
### eguiを準備
Cargo.tomlのdependenciesを修正
eframeとeguiの2つのパッケージをインストールする
eframeはアプリケーション開発の基本機能を提供、eguiはguiライブラリ
[dependencies] eframe = "0.21.0" egui = "0.21.0"
アプリケーションの実行はeframeのrun_nativeを使う
eframe::run_native(name,
nativeOptionsはオプション設定などの情報管理
AppCreatorは構造体
AppCreatorのBox生成
### アプリの実行
fn main() {
let native_options = eframe::NativeOptions::default();
let _ = eframe::run_native("My egui App", native_options,
Box::new(|cc| Box::new(MyEguiApp::new(cc))));
}
#[derive(Default)]
struct MyEguiApp {}
impl MyEguiApp {
fn new(_cc: &eframe::CreationContext<'_>)-> Self {
Self::default()
}
}
impl eframe::App for MyEguiApp {
fn update(&mut self, _ctx: &egui::Context, _frame: &mut eframe::Frame){}
}
impl eframe::App for MyEguiApp {
fn update(&mut self, _ctx: &egui::Context, _frame: &mut eframe::Frame){
egui::CentralPanel::default().show(ctx, |ui|{
ui.heading("Hello World!");
})
}
}
テーマを変える
fn main() {
let native_options = eframe::NativeOptions::default();
native_options.default_theme = eframe::Theme::Light;
let _ = eframe::run_native("My egui App", native_options,
Box::new(|cc| Box::new(MyEguiApp::new(cc))));
}
ラベルのテキストサイズを変更
impl eframe::App for MyEguiApp {
fn update(&mut self, _ctx: &egui::Context, _frame: &mut eframe::Frame){
egui::CentralPanel::default().show(ctx, |ui|{
ui.heading("Hello World!");
let label_txt = egui::RichText::new("This is sample message.")
.font(egui::FontId::proportional(32.0));
let label = egui::Label::new(label_text);
ui.add(label);
});
}
}
impl eframe::App for MyEguiApp {
fn update(&mut self, _ctx: &egui::Context, _frame: &mut eframe::Frame){
egui::CentralPanel::default().show(ctx, |ui|{
ui.heading("Hello World!");
let label_txt = egui::RichText::new("This is sample message.")
.size(32.0)
.color(egui::Color32::from_rgba_premultiplied(255,0,0,100))
.italics();
let label = egui::Label::new(label_text);
ui.add(label);
});
}
}