Skip to content
Snippets Groups Projects
Commit fb3886b5 authored by Federico Lolli's avatar Federico Lolli
Browse files

CHECKPOINT

parent 10e9d768
Branches
No related tags found
1 merge request!16Implemented a first draft of the new Valve-control-pane
...@@ -427,10 +427,6 @@ impl Behavior<Pane> for AppBehavior { ...@@ -427,10 +427,6 @@ impl Behavior<Pane> for AppBehavior {
fn tab_title_for_pane(&mut self, _pane: &Pane) -> egui::WidgetText { fn tab_title_for_pane(&mut self, _pane: &Pane) -> egui::WidgetText {
"Tab".into() "Tab".into()
} }
fn min_size(&self) -> f32 {
185.0
}
} }
#[derive(Clone)] #[derive(Clone)]
......
...@@ -147,21 +147,21 @@ impl PaneBehavior for ValveControlPane { ...@@ -147,21 +147,21 @@ impl PaneBehavior for ValveControlPane {
// ┌────────────────────────┐ // ┌────────────────────────┐
// │ UI METHODS │ // │ UI METHODS │
// └────────────────────────┘ // └────────────────────────┘
const BTN_WIDTH: f32 = 185.0; const BTN_MAX_WIDTH: f32 = 125.;
const BTN_HEIGHT: f32 = 70.0;
impl ValveControlPane { impl ValveControlPane {
fn pane_ui(&mut self) -> impl FnOnce(&mut Ui) { fn pane_ui(&mut self) -> impl FnOnce(&mut Ui) {
|ui| { |ui| {
ui.set_min_width(BTN_WIDTH); ui.set_min_width(BTN_MAX_WIDTH);
let n = (ui.max_rect().width() / BTN_WIDTH) as usize; let n = ((ui.max_rect().width() / BTN_MAX_WIDTH) as usize).max(1);
let valve_chunks = Valve::iter().enumerate().chunks(n); let symbols: Vec<char> = "123456789-/*".chars().collect();
let valve_chunks = Valve::iter().zip(symbols).chunks(n);
Grid::new("valves_grid") Grid::new("valves_grid")
.num_columns(n) .num_columns(n)
.spacing(Vec2::splat(5.)) .spacing(Vec2::splat(5.))
.show(ui, |ui| { .show(ui, |ui| {
for chunk in &valve_chunks { for chunk in &valve_chunks {
for (i, valve) in chunk { for (valve, symbol) in chunk {
ui.scope(self.valve_frame_ui(valve, i as u8)); ui.scope(self.valve_frame_ui(valve, symbol));
} }
ui.end_row(); ui.end_row();
} }
...@@ -208,7 +208,7 @@ impl ValveControlPane { ...@@ -208,7 +208,7 @@ impl ValveControlPane {
} }
} }
fn valve_frame_ui(&self, valve: Valve, number: u8) -> impl FnOnce(&mut Ui) { fn valve_frame_ui(&self, valve: Valve, symbol: char) -> impl FnOnce(&mut Ui) {
move |ui| { move |ui| {
let valve_str = valve.to_string(); let valve_str = valve.to_string();
let timing = self.valves_state.get_timing_for(valve); let timing = self.valves_state.get_timing_for(valve);
...@@ -225,7 +225,7 @@ impl ValveControlPane { ...@@ -225,7 +225,7 @@ impl ValveControlPane {
}; };
let aperture_str = match aperture { let aperture_str = match aperture {
valves::ParameterValue::Valid(value) => { valves::ParameterValue::Valid(value) => {
format!("{:.2}", value) format!("{:.2}%", value * 100.)
} }
valves::ParameterValue::Missing => "N/A".to_owned(), valves::ParameterValue::Missing => "N/A".to_owned(),
valves::ParameterValue::Invalid(err_id) => { valves::ParameterValue::Invalid(err_id) => {
...@@ -235,23 +235,26 @@ impl ValveControlPane { ...@@ -235,23 +235,26 @@ impl ValveControlPane {
let text_color = ui.visuals().text_color(); let text_color = ui.visuals().text_color();
let valve_title_ui = |ui: &mut Ui| { let valve_title_ui = |ui: &mut Ui| {
ui.set_max_width(100.);
Label::new( Label::new(
RichText::new(valve_str.to_ascii_uppercase()) RichText::new(valve_str.to_ascii_uppercase())
.color(text_color) .color(text_color)
.strong()
.size(15.0), .size(15.0),
) )
.selectable(false) .selectable(false)
.wrap()
.ui(ui); .ui(ui);
}; };
fn big_number_ui( fn big_number_ui(
response: &Response, response: &Response,
number: u8, symbol: char,
text_color: Color32, text_color: Color32,
) -> impl Fn(&mut Ui) { ) -> impl Fn(&mut Ui) {
move |ui: &mut Ui| { move |ui: &mut Ui| {
let visuals = ui.style().interact(response); let visuals = ui.style().interact(response);
let number = RichText::new(number.to_string()) let number = RichText::new(symbol.to_string())
.color(text_color) .color(text_color)
.font(FontId::monospace(20.)); .font(FontId::monospace(20.));
...@@ -273,7 +276,7 @@ impl ValveControlPane { ...@@ -273,7 +276,7 @@ impl ValveControlPane {
} }
let labels_ui = |ui: &mut Ui| { let labels_ui = |ui: &mut Ui| {
let icon_size = Vec2::splat(16.); let icon_size = Vec2::splat(17.);
let text_format = TextFormat { let text_format = TextFormat {
font_id: FontId::proportional(12.), font_id: FontId::proportional(12.),
extra_letter_spacing: 0., extra_letter_spacing: 0.,
...@@ -282,25 +285,24 @@ impl ValveControlPane { ...@@ -282,25 +285,24 @@ impl ValveControlPane {
..Default::default() ..Default::default()
}; };
ui.vertical(|ui| { ui.vertical(|ui| {
ui.set_min_width(80.);
ui.horizontal_top(|ui| { ui.horizontal_top(|ui| {
let rect = Rect::from_min_size(ui.cursor().min, icon_size); let rect = Rect::from_min_size(ui.cursor().min, icon_size);
Icon::Timing.paint(ui, rect); Icon::Timing.paint(ui, rect);
ui.allocate_rect(rect, Sense::hover()); ui.allocate_rect(rect, Sense::hover());
let layout_job = LayoutJob::single_section( ui.allocate_ui(vec2(20., 10.), |ui| {
format!("Timing: {}", timing_str), let layout_job =
text_format.clone(), LayoutJob::single_section(timing_str.clone(), text_format.clone());
);
let galley = ui.fonts(|fonts| fonts.layout_job(layout_job)); let galley = ui.fonts(|fonts| fonts.layout_job(layout_job));
Label::new(galley).selectable(false).ui(ui); Label::new(galley).selectable(false).ui(ui);
}); });
});
ui.horizontal_top(|ui| { ui.horizontal_top(|ui| {
let rect = Rect::from_min_size(ui.cursor().min, icon_size); let rect = Rect::from_min_size(ui.cursor().min, icon_size);
Icon::Aperture.paint(ui, rect); Icon::Aperture.paint(ui, rect);
ui.allocate_rect(rect, Sense::hover()); ui.allocate_rect(rect, Sense::hover());
let layout_job = LayoutJob::single_section( let layout_job =
format!("Aperture: {}", aperture_str), LayoutJob::single_section(aperture_str.clone(), text_format);
text_format,
);
let galley = ui.fonts(|fonts| fonts.layout_job(layout_job)); let galley = ui.fonts(|fonts| fonts.layout_job(layout_job));
Label::new(galley).selectable(false).ui(ui); Label::new(galley).selectable(false).ui(ui);
}); });
...@@ -309,24 +311,19 @@ impl ValveControlPane { ...@@ -309,24 +311,19 @@ impl ValveControlPane {
fn inside_frame( fn inside_frame(
response: &Response, response: &Response,
valve_title_ui: impl Fn(&mut Ui), valve_title_ui: impl FnOnce(&mut Ui),
number: &u8, symbol: char,
text_color: &Color32, text_color: Color32,
labels_ui: &impl Fn(&mut Ui), labels_ui: impl FnOnce(&mut Ui),
) -> impl FnOnce(&mut Ui) { ) -> impl FnOnce(&mut Ui) {
|ui: &mut Ui| { move |ui: &mut Ui| {
StripBuilder::new(ui) ui.vertical(|ui| {
.size(Size::exact(10.)) valve_title_ui(ui);
.size(Size::exact(15.))
.vertical(|mut strip| {
strip.cell(valve_title_ui);
strip.cell(|ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
big_number_ui(response, *number, *text_color)(ui); big_number_ui(response, symbol, text_color)(ui);
labels_ui(ui); labels_ui(ui);
}); });
}); });
});
} }
} }
...@@ -335,8 +332,6 @@ impl ValveControlPane { ...@@ -335,8 +332,6 @@ impl ValveControlPane {
.id_salt("valve_".to_owned() + &valve_str) .id_salt("valve_".to_owned() + &valve_str)
.sense(Sense::click()), .sense(Sense::click()),
|ui| { |ui| {
ui.set_width(BTN_WIDTH);
ui.set_height(BTN_HEIGHT);
let response = ui.response(); let response = ui.response();
let visuals = ui.style().interact(&response); let visuals = ui.style().interact(&response);
...@@ -356,8 +351,8 @@ impl ValveControlPane { ...@@ -356,8 +351,8 @@ impl ValveControlPane {
inside_frame( inside_frame(
&response, &response,
&valve_title_ui, &valve_title_ui,
&number, symbol,
&text_color, text_color,
&labels_ui, &labels_ui,
), ),
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment