xref: /StarryEngine/starry_toolkit/src/main.rs (revision 731cae0674923fcc85c6e683a2eee596eb642796)
1 use starry_client::base::color::Color;
2 use starry_server::core::{SCREEN_HEIGHT, SCREEN_WIDTH};
3 use starry_toolkit::base::{
4     panel::{Panel, PanelRendererMode},
5     rect::Rect,
6 };
7 use starry_toolkit::{
8     layout::grid::{Grid, GridArrangeType},
9     widgets::image::Image,
10 };
11 
main()12 fn main() {
13     let panel = Panel::new(
14         Rect::new(0, 0, SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32),
15         "Title",
16         Color::rgb(255, 255, 255),
17     );
18     // 显示矩形线框
19     panel.set_renderer_mode(PanelRendererMode::WithWireframe);
20 
21     let image1 = Image::new_from_color(32, 32, Color::rgb(128, 255, 255));
22     let image2 = Image::new_from_color(32, 32, Color::rgb(128, 255, 255));
23     let image3 = Image::new_from_color(32, 32, Color::rgb(128, 255, 255));
24     let image4 = Image::new_from_color(32, 32, Color::rgb(128, 255, 255));
25     let image5 = Image::new_from_color(32, 32, Color::rgb(128, 255, 255));
26 
27     let grid = Grid::new();
28     grid.set_arrange_type(GridArrangeType::Horizontal); //优先横向排列
29     grid.set_upper_limit(3); //每行最大元素个数为3
30 
31     grid.set_space(20, 20);
32     grid.add_element(&image1);
33     grid.add_element(&image2);
34     grid.add_element(&image3);
35     grid.add_element(&image4);
36     grid.add_element(&image5);
37 
38     panel.add_child(&grid);
39     panel.draw();
40 
41     // 便于观察结果
42     loop {}
43 }
44