progress
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ edition = "2024"
|
||||
description = "a basic text editor widget with line numbers"
|
||||
|
||||
[dependencies]
|
||||
egui = "0.31.1"
|
||||
egui = "0.32.0"
|
||||
serde = "1"
|
||||
|
||||
[lib]
|
||||
|
||||
+11
-19
@@ -1,7 +1,6 @@
|
||||
|
||||
|
||||
use egui::{text::LayoutJob, Color32};
|
||||
use egui::TextBuffer;
|
||||
use egui::widgets::text_edit::TextEditOutput;
|
||||
use egui::{Color32, text::LayoutJob};
|
||||
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
@@ -137,9 +136,10 @@ impl CodeEditor {
|
||||
text.lines().count()
|
||||
} as isize;
|
||||
|
||||
let max_indent = total.to_string().len().max(
|
||||
!self.numlines_only_natural as usize * self.numlines_shift.to_string().len(),
|
||||
);
|
||||
let max_indent = total
|
||||
.to_string()
|
||||
.len()
|
||||
.max(!self.numlines_only_natural as usize * self.numlines_shift.to_string().len());
|
||||
let mut counter = (1..=total)
|
||||
.map(|i| {
|
||||
let num = i + self.numlines_shift;
|
||||
@@ -160,16 +160,12 @@ impl CodeEditor {
|
||||
let width = max_indent as f32
|
||||
* self.fontsize
|
||||
* 0.5
|
||||
* !(total + self.numlines_shift <= 0 && self.numlines_only_natural) as u8
|
||||
as f32;
|
||||
* !(total + self.numlines_shift <= 0 && self.numlines_only_natural) as u8 as f32;
|
||||
|
||||
let mut layouter = |ui: &egui::Ui, string: &str, _wrap_width: f32| {
|
||||
let mut layouter = |ui: &egui::Ui, string: &dyn TextBuffer, _wrap_width: f32| {
|
||||
let layout_job = egui::text::LayoutJob::single_section(
|
||||
string.to_string(),
|
||||
egui::TextFormat::simple(
|
||||
egui::FontId::monospace(self.fontsize),
|
||||
Color32::WHITE,
|
||||
),
|
||||
string.as_str().to_string(), // Convert TextBuffer to String
|
||||
egui::TextFormat::simple(egui::FontId::monospace(self.fontsize), Color32::WHITE),
|
||||
);
|
||||
ui.fonts(|f| f.layout_job(layout_job))
|
||||
};
|
||||
@@ -186,11 +182,7 @@ impl CodeEditor {
|
||||
}
|
||||
|
||||
/// Show Code Editor
|
||||
pub fn show(
|
||||
&mut self,
|
||||
ui: &mut egui::Ui,
|
||||
text: &mut dyn egui::TextBuffer,
|
||||
) -> TextEditOutput {
|
||||
pub fn show(&mut self, ui: &mut egui::Ui, text: &mut dyn egui::TextBuffer) -> TextEditOutput {
|
||||
let mut text_edit_output: Option<TextEditOutput> = None;
|
||||
let code_editor = |ui: &mut egui::Ui| {
|
||||
ui.horizontal_top(|h| {
|
||||
|
||||
Reference in New Issue
Block a user