'Background in iced rust

Trying to implement something like the iced example solar system background. But I have 1 problem left

2. Adjust the size I would only like the background to be a title bar thing. I tried to change the Path::rectangle(Point::new(0.0, 0.0), Frame::new(100.0, width as f32) Although this does not achieve what I think is supposed to happen

my code looks like this w/o the edits

impl<Message> canvas::Program<Message> for State {
      fn draw(
          &self,
          bounds: Rectangle,
          _cursor: Cursor,
      ) -> Vec<canvas::Geometry> {
⚠         let (width, height) = window::Settings::default().size;
⚠         use std::f32::consts::PI;
          // draw the background using the frame
          // Create the rectangle (bckgnd) point starting at 0, 0
          let background = self.space_cache.draw(bounds.size(), |frame| {
              let space = Path::rectangle(Point::new(0.0, 0.0), frame.size());
              let stars = Path::new(|path| {
                  for (p, size) in &self.stars {
                      path.rectangle(*p, Size::new(*size, *size));
                  }
              });
              
              frame.fill(&space, Color::from_rgb(0., 0., 0.)); // fill the background
  
              frame.translate(frame.center() - Point::ORIGIN); // make the stars cover full screen
              frame.fill(&stars, Color::WHITE); // fill the stars with the color white
          });
          vec![background]
      }
  }
fn generate_stars(width: u32, height: u32) -> Vec<(Point, f32)> {
          use rand::Rng;
  
          let mut rng = rand::thread_rng();
  
          (0..100)
              .map(|_| {
                  (
                      Point::new(
                          rng.gen_range(
                              (-(width as f32) / 2.0)..(width as f32 / 2.0),
                          ),
                          rng.gen_range(
                              (-(height as f32) / 2.0)..(height as f32 / 2.0),
                          ),
                      ),
                      rng.gen_range(0.5..1.5),
                  )
              })
              .collect()
      }

The example lives at https://github.com/iced-rs/iced/blob/master/examples/solar_system/src/main.rs



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source