Skip to content

Commit a3e4dba

Browse files
committed
fixing clippy lints and slight ui rearrange
1 parent bc0bb1a commit a3e4dba

File tree

7 files changed

+97
-55
lines changed

7 files changed

+97
-55
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ druid = { git = "https://github.com/linebender/druid.git" }
1212
rust_fractal = {path = "../rust-fractal-core"}
1313
config = "^0.9"
1414
parking_lot = { version = "0.11", features = ["nightly"] }
15+
float_eq = "^0.6.0"
1516

1617
[build-dependencies]
1718
vergen = "4.2.0"

src/custom.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ impl NoUpdateLabel {
2323
}
2424
}
2525

26-
fn make_layout_if_needed(&mut self, value: &String, t: &mut PietText, env: &Env) {
26+
fn make_layout_if_needed(&mut self, value: &str, t: &mut PietText, env: &Env) {
2727
if self.needs_update {
2828
self.text
29-
.set_text(value.clone().into());
29+
.set_text(value.into());
3030
self.text
3131
.set_font(FontDescriptor::new(FontFamily::MONOSPACE).with_size(self.font_size));
3232
self.text.set_text_color(Color::WHITE);

src/main.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use druid::commands::{
1414
SHOW_SAVE_PANEL
1515
};
1616

17+
use float_eq::float_eq;
18+
1719
use rust_fractal::{renderer::FractalRenderer};
1820
use rust_fractal::util::{ComplexFixed, ComplexExtended, FloatExtended, FloatArbitrary, get_delta_top_left, extended_to_string_long, string_to_extended, linear_interpolation_between_zoom};
1921
use rust_fractal::util::data_export::{DataExport, DataType, ColoringType};
@@ -478,7 +480,7 @@ impl<'a> Widget<FractalData> for FractalWidget<'a> {
478480

479481
// These options require the entire renderer to be refreshed
480482
if renderer.center_reference.data_storage_interval != data.iteration_interval as usize ||
481-
renderer.center_reference.glitch_tolerance != data.glitch_tolerance {
483+
!float_eq!(renderer.center_reference.glitch_tolerance, data.glitch_tolerance, ulps <= 4) {
482484
if data.iteration_interval < 1 {
483485
data.iteration_interval = 1;
484486
}
@@ -508,10 +510,10 @@ impl<'a> Widget<FractalData> for FractalWidget<'a> {
508510
renderer.progress.reset_series_approximation();
509511

510512
refresh_type = 2;
511-
} else if renderer.glitch_percentage != data.glitch_percentage ||
513+
} else if !float_eq!(renderer.glitch_percentage, data.glitch_percentage, ulps <= 4) ||
512514
renderer.jitter != data.jitter ||
513515
renderer.remove_centre != data.remove_centre ||
514-
(renderer.jitter && renderer.jitter_factor != data.jitter_factor) {
516+
(renderer.jitter && !float_eq!(renderer.jitter_factor, data.jitter_factor, ulps <= 4)) {
515517

516518
if data.glitch_percentage > 100.0 {
517519
data.glitch_percentage = 100.0;
@@ -604,7 +606,7 @@ impl<'a> Widget<FractalData> for FractalWidget<'a> {
604606
// Check if the zoom has decreased or is near to the current level
605607
if current_zoom.to_uppercase() == data.zoom.to_uppercase() {
606608
// nothing has changed
607-
if current_rotation == data.rotation && current_iterations == data.iteration_limit {
609+
if float_eq!(current_rotation, data.rotation, ulps <= 4) && current_iterations == data.iteration_limit {
608610
// println!("nothing");
609611
return;
610612
}
@@ -616,7 +618,7 @@ impl<'a> Widget<FractalData> for FractalWidget<'a> {
616618
return;
617619
}
618620

619-
if current_rotation == data.rotation {
621+
if float_eq!(current_rotation, data.rotation, ulps <= 4) {
620622
// println!("iterations");
621623
ctx.submit_command(SET_ITERATIONS.with(data.iteration_limit));
622624
return;
@@ -813,11 +815,11 @@ impl<'a> Widget<FractalData> for FractalWidget<'a> {
813815

814816
let mut changed = false;
815817

816-
if current_palette_iteration_span != data.palette_iteration_span
817-
|| current_palette_offset != data.palette_offset
818+
if !float_eq!(current_palette_iteration_span, data.palette_iteration_span, ulps <= 4)
819+
|| !float_eq!(current_palette_offset, data.palette_offset, ulps <= 4)
818820
|| current_cyclic != data.palette_cyclic
819-
|| current_stripe_scale != data.stripe_scale
820-
|| current_distance_transition != data.distance_transition
821+
|| !float_eq!(current_stripe_scale, data.stripe_scale, ulps <= 4)
822+
|| !float_eq!(current_distance_transition, data.distance_transition, ulps <= 4)
821823
|| current_lighting != data.lighting
822824
|| current_distance_color != data.distance_color {
823825
settings.set("palette_iteration_span", data.palette_iteration_span).unwrap();
@@ -833,12 +835,12 @@ impl<'a> Widget<FractalData> for FractalWidget<'a> {
833835
changed = true;
834836
}
835837

836-
if current_lighting_direction != data.lighting_direction
837-
|| current_lighting_azimuth != data.lighting_azimuth
838-
|| current_lighting_opacity != data.lighting_opacity
839-
|| current_lighting_ambient != data.lighting_ambient
840-
|| current_lighting_diffuse != data.lighting_diffuse
841-
|| current_lighting_specular != data.lighting_specular
838+
if !float_eq!(current_lighting_direction, data.lighting_direction, ulps <= 4)
839+
|| !float_eq!(current_lighting_azimuth, data.lighting_azimuth, ulps <= 4)
840+
|| !float_eq!(current_lighting_opacity, data.lighting_opacity, ulps <= 4)
841+
|| !float_eq!(current_lighting_ambient, data.lighting_ambient, ulps <= 4)
842+
|| !float_eq!(current_lighting_diffuse, data.lighting_diffuse, ulps <= 4)
843+
|| !float_eq!(current_lighting_specular, data.lighting_specular, ulps <= 4)
842844
|| current_lighting_shininess != data.lighting_shininess {
843845
settings.set("lighting_direction", data.lighting_direction).unwrap();
844846
settings.set("lighting_azimuth", data.lighting_azimuth).unwrap();
@@ -857,7 +859,7 @@ impl<'a> Widget<FractalData> for FractalWidget<'a> {
857859
return;
858860
}
859861

860-
if current_stripe_scale == data.stripe_scale {
862+
if float_eq!(current_stripe_scale, data.stripe_scale, ulps <= 4) {
861863
renderer.data_export.lock().regenerate();
862864
ctx.submit_command(UPDATE_PALETTE);
863865
ctx.submit_command(REPAINT);

src/render_thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub fn testing_renderer(
187187
},
188188
Err(_) => {
189189
// do some processing to get back to the original coordinates
190-
test.submit_command(UPDATE_ROOT_PROGRESS, (thread_counter_1.load(Ordering::Relaxed), thread_counter_2.load(Ordering::Relaxed), current_estimate_difference_1.lock().clone()), Target::Auto).unwrap();
190+
test.submit_command(UPDATE_ROOT_PROGRESS, (thread_counter_1.load(Ordering::Relaxed), thread_counter_2.load(Ordering::Relaxed), *current_estimate_difference_1.lock()), Target::Auto).unwrap();
191191
}
192192
}
193193

src/theme.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use druid::theme::{
1515
BUTTON_BORDER_RADIUS,
1616
BUTTON_BORDER_WIDTH,
1717
BUTTON_LIGHT,
18-
BUTTON_DARK
18+
BUTTON_DARK,
19+
// BASIC_WIDGET_HEIGHT
1920
};
2021

2122
pub fn configure_env(env: &mut Env) {
@@ -31,6 +32,8 @@ pub fn configure_env(env: &mut Env) {
3132

3233
env.set(BORDERED_WIDGET_HEIGHT, 12.0);
3334

35+
// env.set(BASIC_WIDGET_HEIGHT, 10.0);
36+
3437
// env.set(BORDER_DARK, Color::from_hex_str("#191414").unwrap());
3538

3639
env.set(PRIMARY_LIGHT, Color::from_hex_str("#1DB954").unwrap());

src/ui.rs

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub fn window_main(renderer: Arc<Mutex<FractalRenderer>>) -> impl Widget<Fractal
149149
.with_child(Label::new("Root Zoom:").with_text_size(14.0))
150150
.with_flex_spacer(1.0)
151151
.with_child(NoUpdateLabel::new(24.0).lens(FractalData::root_zoom.map(|val| {
152-
let output = if val.len() > 0 {
152+
let output = if !val.is_empty() {
153153
extended_to_string_short(string_to_extended(val))
154154
} else {
155155
String::new()
@@ -282,21 +282,21 @@ pub fn window_main(renderer: Arc<Mutex<FractalRenderer>>) -> impl Widget<Fractal
282282
.with_child(Flex::row()
283283
.with_child(Label::new("Direction:").fix_width(100.0))
284284
.with_flex_child(Slider::new()
285-
.with_range(0.0, 360.0)
285+
.with_range(0.0, 180.0)
286286
.expand_width()
287-
.lens(FractalData::lighting_direction), 1.0)
287+
.lens(FractalData::lighting_direction.map(|val| *val / 2.0, |new, val| *new = 2.0 * val.round())), 1.0)
288288
.with_child(Label::<f64>::new(|data: &f64, _env: &_| {
289-
format!("{:>.3}", *data)
289+
format!("{:>3.0}°", *data)
290290
}).lens(FractalData::lighting_direction)))
291291
.with_spacer(4.0)
292292
.with_child(Flex::row()
293293
.with_child(Label::new("Azimuth:").fix_width(100.0))
294294
.with_flex_child(Slider::new()
295295
.with_range(0.0, 90.0)
296296
.expand_width()
297-
.lens(FractalData::lighting_azimuth), 1.0)
297+
.lens(FractalData::lighting_azimuth.map(|val| *val, |new, val| *new = val.round())), 1.0)
298298
.with_child(Label::<f64>::new(|data: &f64, _env: &_| {
299-
format!("{:>.3}", *data)
299+
format!("{:>3.0}°", *data)
300300
}).lens(FractalData::lighting_azimuth)))
301301
.with_spacer(4.0)
302302
.with_child(Flex::row()
@@ -306,7 +306,7 @@ pub fn window_main(renderer: Arc<Mutex<FractalRenderer>>) -> impl Widget<Fractal
306306
.expand_width()
307307
.lens(FractalData::lighting_opacity), 1.0)
308308
.with_child(Label::<f64>::new(|data: &f64, _env: &_| {
309-
format!("{:>.3}", *data)
309+
format!("{:>4.1}%", 100.0 * *data)
310310
}).lens(FractalData::lighting_opacity)))
311311
.with_spacer(4.0)
312312
.with_child(Flex::row()
@@ -316,7 +316,7 @@ pub fn window_main(renderer: Arc<Mutex<FractalRenderer>>) -> impl Widget<Fractal
316316
.expand_width()
317317
.lens(FractalData::lighting_ambient), 1.0)
318318
.with_child(Label::<f64>::new(|data: &f64, _env: &_| {
319-
format!("{:>.3}", *data)
319+
format!("{:>4.1}%", 100.0 * *data)
320320
}).lens(FractalData::lighting_ambient)))
321321
.with_spacer(4.0)
322322
.with_child(Flex::row()
@@ -326,7 +326,7 @@ pub fn window_main(renderer: Arc<Mutex<FractalRenderer>>) -> impl Widget<Fractal
326326
.expand_width()
327327
.lens(FractalData::lighting_diffuse), 1.0)
328328
.with_child(Label::<f64>::new(|data: &f64, _env: &_| {
329-
format!("{:>.3}", *data)
329+
format!("{:>4.1}%", 100.0 * *data)
330330
}).lens(FractalData::lighting_diffuse)))
331331
.with_spacer(4.0)
332332
.with_child(Flex::row()
@@ -336,17 +336,17 @@ pub fn window_main(renderer: Arc<Mutex<FractalRenderer>>) -> impl Widget<Fractal
336336
.expand_width()
337337
.lens(FractalData::lighting_specular), 1.0)
338338
.with_child(Label::<f64>::new(|data: &f64, _env: &_| {
339-
format!("{:>.3}", *data)
339+
format!("{:>4.1}%", 100.0 * *data)
340340
}).lens(FractalData::lighting_specular)))
341341
.with_spacer(4.0)
342342
.with_child(Flex::row()
343343
.with_child(Label::new("Shininess:").fix_width(100.0))
344344
.with_flex_child(Slider::new()
345-
.with_range(0.0, 20.0)
345+
.with_range(0.0, 50.0)
346346
.expand_width()
347347
.lens(FractalData::lighting_shininess.map(|val| *val as f64, |new, val| *new = val as i64)), 1.0)
348348
.with_child(Label::<i64>::new(|data: &i64, _env: &_| {
349-
format!("{:>3}", *data)
349+
format!("{:>4}", *data)
350350
}).lens(FractalData::lighting_shininess)))
351351
.with_spacer(4.0)
352352
.with_child(Button::new("SET").on_click(|ctx, _data: &mut FractalData, _env| {
@@ -451,25 +451,33 @@ pub fn window_main(renderer: Arc<Mutex<FractalRenderer>>) -> impl Widget<Fractal
451451
.with_child(Label::new(format!("{} {} {}", env!("VERGEN_GIT_SHA_SHORT"), env!("VERGEN_GIT_COMMIT_DATE"), env!("VERGEN_GIT_COMMIT_TIME"))))
452452
.with_child(Label::new(format!("{} {}", env!("VERGEN_RUSTC_SEMVER"), env!("VERGEN_RUSTC_HOST_TRIPLE"))));
453453

454-
let button_save_advanced_options = Button::new("SAVE & UPDATE").on_click(|ctx, _data, _env| {
455-
ctx.submit_command(SET_ADVANCED_OPTIONS);
456-
}).expand_width().fix_height(40.0);
457-
458454
let group_advanced_options = Flex::column()
459-
.with_child(create_checkbox_row("Show glitched pixels").lens(FractalData::display_glitches))
460-
.with_spacer(4.0)
461-
.with_child(create_checkbox_row("Enable series approximation").lens(FractalData::series_approximation_enabled))
455+
.with_child(create_checkbox_row("Automatically adjust iterations").lens(FractalData::auto_adjust_iterations))
462456
.with_spacer(4.0)
463-
.with_child(create_checkbox_row("Tiled series approximation").lens(FractalData::series_approximation_tiled))
457+
.with_child(create_checkbox_row("Remove image centre").lens(FractalData::remove_centre))
464458
.with_spacer(4.0)
465-
.with_child(create_checkbox_row("Jitter pixels").lens(FractalData::jitter))
459+
.with_child(create_checkbox_row("Show glitched pixels").lens(FractalData::display_glitches))
466460
.with_spacer(4.0)
467-
.with_child(create_checkbox_row("Automatically adjust iterations").lens(FractalData::auto_adjust_iterations))
461+
.with_child(Flex::row()
462+
.with_child(Label::new("Glitch tolerance:"))
463+
.with_flex_child(Slider::new()
464+
.with_range(-8.0, -3.0)
465+
.expand_width()
466+
.lens(FractalData::glitch_tolerance.map(
467+
|val| (*val).log10(),
468+
|val, new| *val = 10.0f64.powf(new.floor() + ((10.0 * 10.0f64.powf(new - new.floor())).round() / 10.0).log10() ))), 1.0)
469+
.with_child(Label::<f64>::new(|data: &f64, _env: &_| {
470+
let temp = data.log10();
471+
let exponent = temp.floor();
472+
let mantissa = 10.0f64.powf(temp - exponent);
473+
474+
format!("{:.2}E{:1}", mantissa, exponent)
475+
}).lens(FractalData::glitch_tolerance)))
468476
.with_spacer(4.0)
469-
.with_child(create_checkbox_row("Remove image centre").lens(FractalData::remove_centre))
477+
.with_child(create_checkbox_row("Series approximation").lens(FractalData::series_approximation_enabled))
470478
.with_spacer(4.0)
471479
.with_child(Flex::row()
472-
.with_child(Label::new("S.A. Order:").fix_width(100.0))
480+
.with_child(Label::new("Series order:"))
473481
.with_flex_child(Slider::new()
474482
.with_range(1.0, 16.0)
475483
.expand_width()
@@ -480,11 +488,36 @@ pub fn window_main(renderer: Arc<Mutex<FractalRenderer>>) -> impl Widget<Fractal
480488
format!("{:>3}", *data)
481489
}).lens(FractalData::order)))
482490
.with_spacer(4.0)
483-
.with_child(create_label_textbox_row("GLITCH TOL:", 120.0).lens(FractalData::glitch_tolerance))
491+
.with_child(create_checkbox_row("Tiled series approximation").lens(FractalData::series_approximation_tiled))
492+
.with_spacer(4.0)
493+
.with_child(Flex::row()
494+
.with_child(Label::new("Tiled sampling:"))
495+
.with_flex_child(Slider::new()
496+
.with_range(1.0, 100.0)
497+
.expand_width()
498+
.lens(FractalData::probe_sampling.map(
499+
|val| *val as f64,
500+
|val, new| *val = new as i64)), 1.0)
501+
.with_child(Label::<i64>::new(|data: &i64, _env: &_| {
502+
format!("{:>3}", *data)
503+
}).lens(FractalData::probe_sampling)))
504+
.with_spacer(4.0)
505+
.with_child(create_checkbox_row("Jitter pixels").lens(FractalData::jitter))
484506
.with_spacer(4.0)
485-
.with_child(create_label_textbox_row("GLITCH %:", 120.0).lens(FractalData::glitch_percentage))
486507
.with_child(Flex::row()
487-
.with_child(Label::new("Data Int.:").fix_width(100.0))
508+
.with_child(Label::new("Jitter spread:"))
509+
.with_flex_child(Slider::new()
510+
.with_range(0.0, 1.0)
511+
.expand_width()
512+
.lens(FractalData::jitter_factor.map(
513+
|val| *val,
514+
|val, new| *val = new)), 1.0)
515+
.with_child(Label::<f64>::new(|data: &f64, _env: &_| {
516+
format!("{:>3.2}", *data)
517+
}).lens(FractalData::jitter_factor)))
518+
.with_spacer(4.0)
519+
.with_child(Flex::row()
520+
.with_child(Label::new("Data interval:"))
488521
.with_flex_child(Slider::new()
489522
.with_range(0.0, 5.0)
490523
.expand_width()
@@ -495,13 +528,9 @@ pub fn window_main(renderer: Arc<Mutex<FractalRenderer>>) -> impl Widget<Fractal
495528
format!("{:>6}", *data)
496529
}).lens(FractalData::iteration_interval)))
497530
.with_spacer(4.0)
498-
.with_child(create_label_textbox_row("PROBE SAMPLING:", 100.0).lens(FractalData::probe_sampling))
499-
.with_spacer(4.0)
500-
.with_child(create_label_textbox_row("JITTER FACTOR:", 100.0).lens(FractalData::jitter_factor));
501-
502-
let group_extra = Flex::column()
503-
.with_child(button_save_advanced_options)
504-
.with_child(group_advanced_options);
531+
.with_child(Button::new("SET").on_click(|ctx, _data, _env| {
532+
ctx.submit_command(SET_ADVANCED_OPTIONS);
533+
}).expand_width().fix_height(40.0));
505534

506535
let tabs_menu = Either::new(|data: &FractalData, _env| data.current_tab)
507536
.add_branch(Flex::column()
@@ -510,7 +539,7 @@ pub fn window_main(renderer: Arc<Mutex<FractalRenderer>>) -> impl Widget<Fractal
510539
.with_child(group_palette)
511540
)
512541
.add_branch(group_location)
513-
.add_branch(group_extra);
542+
.add_branch(group_advanced_options);
514543

515544
let tabs_selector = Flex::row()
516545
.with_flex_child(Button::from_label(Label::new("IMAGE").with_text_size(16.0)).on_click(|_ctx, data: &mut FractalData, _env| {

0 commit comments

Comments
 (0)