Skip to content

Commit 1f2ffee

Browse files
committed
Update the desired width of the edit widget dynamically to remove column jitter. Thanks to #8
1 parent f4e39a5 commit 1f2ffee

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

examples/simple/main.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use crate::frame_history::FrameHistory;
21
use eframe::{Frame, NativeOptions};
32
use egui::Context;
3+
44
use egui_memory_editor::MemoryEditor;
55

6+
use crate::frame_history::FrameHistory;
7+
68
mod frame_history;
79

810
pub fn main() {
@@ -34,6 +36,7 @@ impl Default for App {
3436

3537
// You can set the column count in the UI, but also here. There are a variety of options available in mem_editor.options
3638
mem_editor.options.column_count = 16;
39+
3740
App {
3841
mem_editor,
3942
memory: Default::default(),
@@ -72,6 +75,7 @@ impl Default for Memory {
7275
}
7376
}
7477
}
78+
7579
impl Memory {
7680
pub fn read_value(&mut self, address: usize) -> u8 {
7781
self.memory[address]

src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl MemoryEditor {
301301
// For Editing
302302
let response = ui.add(
303303
TextEdit::singleline(&mut frame_data.selected_edit_address_string)
304-
.desired_width(6.0)
304+
.desired_width(frame_data.previous_frame_text_edit_size)
305305
.font(options.memory_editor_text_style.clone())
306306
.hint_text(label_text)
307307
.id_source(frame_data.selected_edit_address),
@@ -355,6 +355,8 @@ impl MemoryEditor {
355355
}
356356

357357
let response = Label::new(text).sense(Sense::click()).ui(ui);
358+
// For use with the `Edit` widget, keep track of the size of ordinary display to keep column jitter at bay
359+
frame_data.previous_frame_text_edit_size = response.rect.width();
358360

359361
// Right click always selects.
360362
if response.secondary_clicked() {

src/option_data.rs

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl Default for MemoryEditorOptions {
132132
pub(crate) struct BetweenFrameData {
133133
/// Used to ensure we can resize the window in height, but not in width.
134134
pub previous_frame_editor_width: f32,
135+
pub previous_frame_text_edit_size: f32,
135136
/// The address a user clicked on in the UI in the previous frame, used for DataPreview
136137
pub selected_edit_address: Option<Address>,
137138
pub selected_edit_address_string: String,

0 commit comments

Comments
 (0)