remove output text concept, instead make it clear what text is being operated on
This commit is contained in:
parent
854ba3f83e
commit
22dea213aa
1 changed files with 4 additions and 26 deletions
30
src/main.rs
30
src/main.rs
|
@ -15,11 +15,6 @@ struct InputText {
|
||||||
value: String,
|
value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource, Debug)]
|
|
||||||
struct OutputText {
|
|
||||||
value: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Resource, Debug)]
|
#[derive(Resource, Debug)]
|
||||||
struct NeedsSort {
|
struct NeedsSort {
|
||||||
value: bool,
|
value: bool,
|
||||||
|
@ -36,9 +31,6 @@ fn main() {
|
||||||
.insert_resource(InputText {
|
.insert_resource(InputText {
|
||||||
value: "".to_string(),
|
value: "".to_string(),
|
||||||
})
|
})
|
||||||
.insert_resource(OutputText {
|
|
||||||
value: "".to_string(),
|
|
||||||
})
|
|
||||||
.insert_resource(NeedsSort { value: false })
|
.insert_resource(NeedsSort { value: false })
|
||||||
.insert_resource(NeedsStrip { value: false })
|
.insert_resource(NeedsStrip { value: false })
|
||||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||||
|
@ -55,10 +47,9 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_text(
|
fn process_text(
|
||||||
mut output_text: ResMut<OutputText>,
|
|
||||||
mut needs_sort: ResMut<NeedsSort>,
|
mut needs_sort: ResMut<NeedsSort>,
|
||||||
mut needs_strip: ResMut<NeedsStrip>,
|
mut needs_strip: ResMut<NeedsStrip>,
|
||||||
input_text: Res<InputText>,
|
mut input_text: ResMut<InputText>,
|
||||||
) {
|
) {
|
||||||
let needs_processing = needs_sort.value || needs_strip.value;
|
let needs_processing = needs_sort.value || needs_strip.value;
|
||||||
|
|
||||||
|
@ -75,7 +66,7 @@ fn process_text(
|
||||||
needs_sort.value = false;
|
needs_sort.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
output_text.value = arr.join(LINE_ENDING);
|
input_text.value = arr.join(LINE_ENDING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +75,6 @@ fn ui_system(
|
||||||
mut input_text: ResMut<InputText>,
|
mut input_text: ResMut<InputText>,
|
||||||
mut needs_sort: ResMut<NeedsSort>,
|
mut needs_sort: ResMut<NeedsSort>,
|
||||||
mut needs_strip: ResMut<NeedsStrip>,
|
mut needs_strip: ResMut<NeedsStrip>,
|
||||||
output_text: Res<OutputText>,
|
|
||||||
) {
|
) {
|
||||||
contexts.ctx_mut().set_visuals(egui::Visuals::light());
|
contexts.ctx_mut().set_visuals(egui::Visuals::light());
|
||||||
|
|
||||||
|
@ -106,13 +96,12 @@ fn ui_system(
|
||||||
|
|
||||||
let copy_button = ui.button("Copy");
|
let copy_button = ui.button("Copy");
|
||||||
if copy_button.clicked() {
|
if copy_button.clicked() {
|
||||||
ui.output_mut(|o| o.copied_text = output_text.value.clone());
|
ui.output_mut(|o| o.copied_text = input_text.value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
let clear_button = ui.button("Clear");
|
let clear_button = ui.button("Clear");
|
||||||
if clear_button.clicked() {
|
if clear_button.clicked() {
|
||||||
input_text.value = "".to_string();
|
input_text.value = "".to_string();
|
||||||
needs_sort.value = true;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -123,21 +112,10 @@ fn ui_system(
|
||||||
.id_source("left")
|
.id_source("left")
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.add_sized(
|
ui.add_sized(
|
||||||
[ui.available_width() / 2., height],
|
[ui.available_width(), height],
|
||||||
egui::TextEdit::multiline(&mut input_text.value),
|
egui::TextEdit::multiline(&mut input_text.value),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
egui::ScrollArea::vertical()
|
|
||||||
.id_source("right")
|
|
||||||
.show(ui, |ui| {
|
|
||||||
ui.with_layout(
|
|
||||||
egui::Layout::top_down_justified(egui::Align::LEFT),
|
|
||||||
|ui| {
|
|
||||||
ui.add(egui::Label::new(&output_text.value).selectable(true));
|
|
||||||
},
|
|
||||||
)
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue