一、窗口颜色和透明度
(一)效果预览
(二)透明窗体主要代码
use eframe:: egui;
use egui:: Color32 ; fn main ( ) -> eframe:: Result < ( ) > { let options = eframe:: NativeOptions { viewport: egui:: ViewportBuilder :: default ( ) . with_inner_size ( [ 600 . , 500 . ] ) . with_transparent ( true ) , centered: true , .. Default :: default ( ) } ; eframe:: run_simple_native ( "窗体颜色和透明度" , options, move | ctx, _frame| { ctx. set_visuals ( egui:: Visuals { panel_fill: Color32 :: from_rgba_premultiplied ( 25 , 0 , 55 , 76 , ) , .. ctx. style ( ) . visuals. clone ( ) } ) ; egui:: CentralPanel :: default ( ) . show ( ctx, | ui| { load_fonts ( ctx) ; ui. label ( "窗体内容…………" ) ; } ) ; } )
}
二、程序中随意调整窗口颜色和透明度
(一)效果预览
(二)控制窗口颜色和透明度的主要代码
use eframe:: egui;
use egui:: Color32 ; fn main ( ) -> eframe:: Result < ( ) > { let options = eframe:: NativeOptions { viewport: egui:: ViewportBuilder :: default ( ) . with_inner_size ( [ 600 . , 500 . ] ) . with_transparent ( true ) , centered: true , .. Default :: default ( ) } ; let mut opacity = 0.3 ; let mut r = 25 ; let mut g = 0 ; let mut b = 55 ; eframe:: run_simple_native ( "窗体颜色和透明度" , options, move | ctx, _frame| { ctx. set_visuals ( egui:: Visuals { panel_fill: Color32 :: from_rgba_premultiplied ( r, g, b, ( opacity * 255.0 ) as u8 , ) , .. ctx. style ( ) . visuals. clone ( ) } ) ; egui:: CentralPanel :: default ( ) . show ( ctx, | ui| { load_fonts ( ctx) ; ui. add ( egui:: Slider :: new ( & mut opacity, 0.0 ..= 1.0 ) . text ( "透明度" ) ) ; ui. add ( egui:: Slider :: new ( & mut r, 0 ..= 255 ) . text ( "红色" ) ) ; ui. add ( egui:: Slider :: new ( & mut g, 0 ..= 255 ) . text ( "绿色" ) ) ; ui. add ( egui:: Slider :: new ( & mut b, 0 ..= 255 ) . text ( "蓝色" ) ) ; ui. label ( format! ( "当前颜色: ({}, {}, {})" , r, g, b) ) ; } ) ; } )
}