Building GUIs with druid

Last Update: 2023-04-16

With druid you can build GUI applications with Rust.

Checkout the folder druid/druid/examples of the repository for working examples.

Examples

Footer which sticks to the bottom

Flex::column()
  with_child(Align::centered(layout))
  with_flex_spacer(f64::MAX)
  with_child(statusbar.align_horizontal(druid::UnitPoint::BOTTOM))

Access an attribute in an array in the data structure

#[derive(Clone, Data, Len)]
struct ServerData {
  fq_domain: String,
  ipv4: [u8; 4]
}

#[derive(Data, Len)]
struct DNSServer {
  servers: Vec<ServerData>
}

let i = ...;
DNSServer::servers.as_ref().index(i).then(ServerData::fq_domain)

Modify anything other than text or disabled

This examples modifies the color of a label.

#[derive(Data, Len)]
struct DataState {
  i0: f64,
  i1: f64
}

let temp_label = Label::new(move |data: &DataState, _env: &Env| {
    format!("{} < {}?", data.i0, data.i1)
  })
  .env_scope(move |env, data| {
    env.set(druid::theme::TEXT_COLOR,
      if data.i0 < data.i1 {
        Color::WHITE
      }
      else {
        Color::RED
      });
  });