Update to 0.0.4 #1
@ -19,7 +19,7 @@ impl Default for TextEditor {
|
|||||||
show_line_numbers: false,
|
show_line_numbers: false,
|
||||||
word_wrap: true,
|
word_wrap: true,
|
||||||
auto_hide_toolbar: false,
|
auto_hide_toolbar: false,
|
||||||
auto_hide_tab_bar: false,
|
auto_hide_tab_bar: true,
|
||||||
theme: Theme::default(),
|
theme: Theme::default(),
|
||||||
line_side: false,
|
line_side: false,
|
||||||
font_family: "Proportional".to_string(),
|
font_family: "Proportional".to_string(),
|
||||||
|
|||||||
@ -23,10 +23,19 @@ pub(crate) fn central_panel(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
let editor_height = panel_rect.height();
|
let editor_height = panel_rect.height();
|
||||||
|
|
||||||
if !show_line_numbers || app.get_active_tab().is_none() {
|
if !show_line_numbers || app.get_active_tab().is_none() {
|
||||||
egui::ScrollArea::vertical()
|
let scroll_response = egui::ScrollArea::vertical()
|
||||||
.auto_shrink([false; 2])
|
.auto_shrink([false; 2])
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
editor_view_ui(ui, app);
|
// Create an invisible interaction area for context menu that covers the whole area
|
||||||
|
let full_rect = ui.available_rect_before_wrap();
|
||||||
|
let context_response = ui.allocate_response(full_rect.size(), egui::Sense::click());
|
||||||
|
|
||||||
|
// Reset cursor to render editor at the top
|
||||||
|
ui.allocate_ui_at_rect(full_rect, |ui| {
|
||||||
|
editor_view_ui(ui, app);
|
||||||
|
});
|
||||||
|
|
||||||
|
show_context_menu(ui, app, &context_response);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -87,7 +96,16 @@ pub(crate) fn central_panel(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
egui::vec2(editor_dimensions.text_width, editor_height),
|
egui::vec2(editor_dimensions.text_width, editor_height),
|
||||||
egui::Layout::left_to_right(egui::Align::TOP),
|
egui::Layout::left_to_right(egui::Align::TOP),
|
||||||
|ui| {
|
|ui| {
|
||||||
editor_view_ui(ui, app);
|
// Create an invisible interaction area for context menu
|
||||||
|
let full_rect = ui.available_rect_before_wrap();
|
||||||
|
let context_response = ui.allocate_response(full_rect.size(), egui::Sense::click());
|
||||||
|
|
||||||
|
// Reset cursor to render editor at the top
|
||||||
|
ui.allocate_ui_at_rect(full_rect, |ui| {
|
||||||
|
editor_view_ui(ui, app);
|
||||||
|
});
|
||||||
|
|
||||||
|
show_context_menu(ui, app, &context_response);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
separator_widget(ui);
|
separator_widget(ui);
|
||||||
@ -103,14 +121,26 @@ pub(crate) fn central_panel(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
|ui| {
|
|ui| {
|
||||||
line_numbers_widget(ui);
|
line_numbers_widget(ui);
|
||||||
separator_widget(ui);
|
separator_widget(ui);
|
||||||
editor_view_ui(ui, app);
|
|
||||||
|
// Create an invisible interaction area for context menu
|
||||||
|
let editor_area = ui.available_rect_before_wrap();
|
||||||
|
let context_response = ui.allocate_response(editor_area.size(), egui::Sense::click());
|
||||||
|
|
||||||
|
// Reset cursor to render editor at the current position
|
||||||
|
ui.allocate_ui_at_rect(editor_area, |ui| {
|
||||||
|
editor_view_ui(ui, app);
|
||||||
|
});
|
||||||
|
|
||||||
|
show_context_menu(ui, app, &context_response);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
output.response.context_menu(|ui| {
|
fn show_context_menu(ui: &mut egui::Ui, app: &mut TextEditor, context_response: &egui::Response) {
|
||||||
|
context_response.context_menu(|ui| {
|
||||||
let text_len = app.get_active_tab().unwrap().content.len();
|
let text_len = app.get_active_tab().unwrap().content.len();
|
||||||
let reset_zoom_key = egui::Id::new("editor_reset_zoom");
|
let reset_zoom_key = egui::Id::new("editor_reset_zoom");
|
||||||
|
|
||||||
@ -159,5 +189,4 @@ pub(crate) fn central_panel(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
ui.close_menu();
|
ui.close_menu();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -179,7 +179,14 @@ pub(crate) fn menu_bar(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
ui.close_menu();
|
ui.close_menu();
|
||||||
}
|
}
|
||||||
if ui
|
if ui
|
||||||
.checkbox(&mut app.word_wrap, "Toggle Word Wrap")
|
.checkbox(&mut app.word_wrap, "Word Wrap")
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
app.save_config();
|
||||||
|
ui.close_menu();
|
||||||
|
}
|
||||||
|
if ui
|
||||||
|
.checkbox(&mut app.auto_hide_tab_bar, "Hide Tab Bar")
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
app.save_config();
|
app.save_config();
|
||||||
@ -192,13 +199,6 @@ pub(crate) fn menu_bar(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
app.save_config();
|
app.save_config();
|
||||||
ui.close_menu();
|
ui.close_menu();
|
||||||
}
|
}
|
||||||
if ui
|
|
||||||
.checkbox(&mut app.auto_hide_tab_bar, "Auto Hide Tab Bar")
|
|
||||||
.clicked()
|
|
||||||
{
|
|
||||||
app.save_config();
|
|
||||||
ui.close_menu();
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
@ -282,11 +282,18 @@ pub(crate) fn menu_bar(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let window_width = ctx.screen_rect().width();
|
let window_width = ctx.screen_rect().width();
|
||||||
|
let font_id = ui.style().text_styles[&egui::TextStyle::Body].clone();
|
||||||
|
|
||||||
|
let tab_title = if app.get_active_tab().is_some_and(|tab| tab.is_modified) {
|
||||||
|
format!("{tab_title}*")
|
||||||
|
} else {
|
||||||
|
tab_title
|
||||||
|
};
|
||||||
|
|
||||||
let text_galley = ui.fonts(|fonts| {
|
let text_galley = ui.fonts(|fonts| {
|
||||||
fonts.layout_job(egui::text::LayoutJob::simple_singleline(
|
fonts.layout_job(egui::text::LayoutJob::simple_singleline(
|
||||||
tab_title,
|
tab_title,
|
||||||
ui.style().text_styles[&egui::TextStyle::Body].clone(),
|
font_id,
|
||||||
ui.style().visuals.text_color(),
|
ui.style().visuals.text_color(),
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
|
|||||||
@ -72,7 +72,7 @@ pub(crate) fn preferences_window(app: &mut TextEditor, ctx: &egui::Context) {
|
|||||||
app.font_size_input = Some(app.font_size.to_string());
|
app.font_size_input = Some(app.font_size.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut font_size_text = app.font_size_input.as_ref().unwrap().clone();
|
let mut font_size_text = app.font_size_input.as_ref().unwrap_or(&"14".to_string()).clone();
|
||||||
let response = ui.add(
|
let response = ui.add(
|
||||||
egui::TextEdit::singleline(&mut font_size_text)
|
egui::TextEdit::singleline(&mut font_size_text)
|
||||||
.desired_width(50.0)
|
.desired_width(50.0)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user