fixed scroll behaviour
This commit is contained in:
parent
6c9aac62bd
commit
513d0f42e0
|
@ -2,7 +2,6 @@ use eframe::egui;
|
||||||
//use egui::{text::CCursor, text_edit::CCursorRange};
|
//use egui::{text::CCursor, text_edit::CCursorRange};
|
||||||
use std::{env, path::Path, path::PathBuf, cmp::max, io, fs, cmp::min};
|
use std::{env, path::Path, path::PathBuf, cmp::max, io, fs, cmp::min};
|
||||||
use crate::tools;
|
use crate::tools;
|
||||||
//use tools::themes::CustomColorTheme;
|
|
||||||
|
|
||||||
pub mod code_editor;
|
pub mod code_editor;
|
||||||
use code_editor::CodeEditor;
|
use code_editor::CodeEditor;
|
||||||
|
@ -141,17 +140,14 @@ impl super::Calcifer {
|
||||||
let current_tab = &mut self.tabs[self.selected_tab.to_index()];
|
let current_tab = &mut self.tabs[self.selected_tab.to_index()];
|
||||||
let lines = current_tab.code.chars().filter(|&c| c == '\n').count() + 1;
|
let lines = current_tab.code.chars().filter(|&c| c == '\n').count() + 1;
|
||||||
|
|
||||||
//let scroll_area = egui::ScrollArea::vertical()
|
let _output = CodeEditor::default()
|
||||||
//.vertical_scroll_offset(current_tab.scroll_offset)
|
|
||||||
//.show(ui, |ui| {
|
|
||||||
let mut _output = CodeEditor::default()
|
|
||||||
.id_source("code editor")
|
.id_source("code editor")
|
||||||
.with_rows(max(80, lines))
|
.with_rows(max(80, lines))
|
||||||
.with_fontsize(14.0)
|
.with_fontsize(14.0)
|
||||||
.with_theme(self.theme)
|
.with_theme(self.theme)
|
||||||
.with_syntax(tools::to_syntax(¤t_tab.language))
|
.with_syntax(tools::to_syntax(¤t_tab.language))
|
||||||
.with_numlines(true)
|
.with_numlines(true)
|
||||||
.show(ui, &mut current_tab.code);
|
.show(ui, &mut current_tab.code, &mut current_tab.scroll_offset);
|
||||||
//if !self.search.result_selected {
|
//if !self.search.result_selected {
|
||||||
//output.state.set_ccursor_range(Some(CCursorRange::two(
|
//output.state.set_ccursor_range(Some(CCursorRange::two(
|
||||||
//CCursor::new(self.search.get_cursor_start()),
|
//CCursor::new(self.search.get_cursor_start()),
|
||||||
|
@ -161,7 +157,7 @@ impl super::Calcifer {
|
||||||
//self.search.result_selected = true;
|
//self.search.result_selected = true;
|
||||||
//}
|
//}
|
||||||
//});
|
//});
|
||||||
//ui.label(format!("Scroll : {}", scroll_area.state.offset.y.clone()));
|
ui.label(format!("Scroll : {}", current_tab.scroll_offset));
|
||||||
|
|
||||||
if current_tab.history.len() < 1 {
|
if current_tab.history.len() < 1 {
|
||||||
current_tab.history.push(current_tab.code.clone());
|
current_tab.history.push(current_tab.code.clone());
|
||||||
|
|
|
@ -187,8 +187,8 @@ impl CodeEditor {
|
||||||
|
|
||||||
//#[cfg(feature = "egui")]
|
//#[cfg(feature = "egui")]
|
||||||
/// Show Code Editor
|
/// Show Code Editor
|
||||||
pub fn show(&mut self, ui: &mut egui::Ui, text: &mut String) -> TextEditOutput {
|
pub fn show(&mut self, ui: &mut egui::Ui, text: &mut String, vertical_offset: &mut f32) -> f32 {
|
||||||
let mut text_edit_output: Option<TextEditOutput> = None;
|
//let mut text_edit_output: Option<TextEditOutput> = None;
|
||||||
let mut code_editor = |ui: &mut egui::Ui| {
|
let mut code_editor = |ui: &mut egui::Ui| {
|
||||||
ui.horizontal_top(|h| {
|
ui.horizontal_top(|h| {
|
||||||
self.theme.modify_style(h, self.fontsize);
|
self.theme.modify_style(h, self.fontsize);
|
||||||
|
@ -202,7 +202,7 @@ impl CodeEditor {
|
||||||
let layout_job = highlight(ui.ctx(), self, string);
|
let layout_job = highlight(ui.ctx(), self, string);
|
||||||
ui.fonts(|f| f.layout_job(layout_job))
|
ui.fonts(|f| f.layout_job(layout_job))
|
||||||
};
|
};
|
||||||
let output = egui::TextEdit::multiline(text)
|
let _output = egui::TextEdit::multiline(text)
|
||||||
.id_source(&self.id)
|
.id_source(&self.id)
|
||||||
.lock_focus(true)
|
.lock_focus(true)
|
||||||
.desired_rows(self.rows)
|
.desired_rows(self.rows)
|
||||||
|
@ -210,19 +210,23 @@ impl CodeEditor {
|
||||||
.desired_width(if self.shrink { 0.0 } else { f32::MAX })
|
.desired_width(if self.shrink { 0.0 } else { f32::MAX })
|
||||||
.layouter(&mut layouter)
|
.layouter(&mut layouter)
|
||||||
.show(ui);
|
.show(ui);
|
||||||
text_edit_output = Some(output);
|
//text_edit_output = Some(output);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
if self.vscroll {
|
if self.vscroll {
|
||||||
egui::ScrollArea::vertical()
|
let scroll_area = egui::ScrollArea::vertical()
|
||||||
.id_source(format!("{}_outer_scroll", self.id))
|
.id_source(format!("{}_outer_scroll", self.id))
|
||||||
.stick_to_bottom(self.stick_to_bottom)
|
.stick_to_bottom(self.stick_to_bottom)
|
||||||
|
.vertical_scroll_offset(vertical_offset.clone())
|
||||||
|
//.enable_scrolling(false)
|
||||||
.show(ui, code_editor);
|
.show(ui, code_editor);
|
||||||
|
*vertical_offset = scroll_area.state.offset.y.clone();
|
||||||
} else {
|
} else {
|
||||||
code_editor(ui);
|
code_editor(ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
text_edit_output.expect("TextEditOutput should exist at this point")
|
//text_edit_output.expect("TextEditOutput should exist at this point")
|
||||||
|
*vertical_offset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,14 @@ impl eframe::App for Calcifer {
|
||||||
self.searching = !self.searching.clone();
|
self.searching = !self.searching.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if ctx.input( |i| i.scroll_delta.y > 0.0) {
|
||||||
|
//self.tabs[self.selected_tab.to_index()].scroll_offset += 80.0;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//if ctx.input( |i| i.scroll_delta.y < 0.0) {
|
||||||
|
//self.tabs[self.selected_tab.to_index()].scroll_offset -= 80.0;
|
||||||
|
//}
|
||||||
|
|
||||||
self.draw_settings(ctx);
|
self.draw_settings(ctx);
|
||||||
self.draw_tree_panel(ctx);
|
self.draw_tree_panel(ctx);
|
||||||
self.draw_terminal_panel(ctx);
|
self.draw_terminal_panel(ctx);
|
||||||
|
|
Loading…
Reference in a new issue