1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
use crate::application::*; use iced_wgpu::Renderer; use iced_winit::{Column, Container, Element, Slider, Text, slider, Length, Space}; #[derive(Debug, Clone, Copy)] pub enum Message { SolventRadiusChanged(f32), MaxNeighboursChanged(f32), } pub struct UserInterface { solvent_radius_slider: slider::State, max_neighbours_slider: slider::State, } impl UserInterface { pub fn new() -> Self { Self { solvent_radius_slider: iced_wgpu::slider::State::new(), max_neighbours_slider: iced_wgpu::slider::State::new(), } } pub fn update(&self, message: Message, application: &mut Application) { match message { Message::SolventRadiusChanged(solvent_radius) => { application.set_solvent_radius(solvent_radius); }, Message::MaxNeighboursChanged(max_neighbours) => { application.set_max_neighbours(max_neighbours.round() as i32); } }; } pub fn view<'a>(&'a mut self, application: &Application) -> Element<'a, Message, Renderer> { Container::new( Column::new() .push(Text::new("Options").size(24)) .push(Space::new(Length::Fill, Length::Units(12))) .push(Text::new("Solvent radius").size(18)) .push(Slider::new( &mut self.solvent_radius_slider, 0.0..=2.0, application.solvent_radius(), move |n| Message::SolventRadiusChanged(n), )) .push(Text::new("Max neighbours").size(18)) .push(Slider::new( &mut self.max_neighbours_slider, 1.0..=45.0, application.max_neighbours() as f32, move |n| Message::MaxNeighboursChanged(n), )) .padding(12), ).width(Length::Units(200)) .into() } }