Skip to content

Commit 1967c2e

Browse files
committed
Use monospace font in script editors
1 parent 0b4580b commit 1967c2e

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

examples/common/script_editor.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::{
77
use bevy_egui::egui;
88
use vm::{DebugCommandBridge, DebugCommandBridgeError, SourceError, SourceMap, compile_source};
99

10+
const CODE_FONT_SIZE: f32 = 13.0;
11+
1012
#[derive(Debug, Clone)]
1113
pub struct ScriptTab {
1214
pub title: &'static str,
@@ -516,7 +518,7 @@ impl LiveScriptEditor {
516518
let remaining_height = ui.available_height().max(panel_height - 140.0);
517519
let code_height = (remaining_height - console_height - 48.0).max(240.0);
518520
let line_count = tab.buffer.lines().count().max(1);
519-
let row_height = ui.text_style_height(&egui::TextStyle::Monospace).max(16.0);
521+
let row_height = (CODE_FONT_SIZE + 4.0).max(16.0);
520522
let content_height = (line_count as f32 * row_height + 24.0).max(code_height);
521523
let gutter_width = 42.0;
522524
let text_width = (code_width - gutter_width - 8.0).max(140.0);
@@ -594,7 +596,7 @@ impl LiveScriptEditor {
594596
.scope(|ui| {
595597
ui.set_min_size(egui::vec2(text_width, content_height));
596598
egui::TextEdit::multiline(&mut tab.buffer)
597-
.font(egui::TextStyle::Monospace)
599+
.font(code_font_id())
598600
.desired_width(text_width)
599601
.desired_rows(line_count)
600602
.lock_focus(true)
@@ -730,7 +732,7 @@ fn render_debug_console(
730732
let response = ui.add_enabled(
731733
editor.debug_attached,
732734
egui::TextEdit::singleline(&mut editor.console_input)
733-
.font(egui::TextStyle::Monospace)
735+
.font(code_font_id())
734736
.desired_width(input_width)
735737
.hint_text("help | locals | print name | where"),
736738
);
@@ -1204,6 +1206,10 @@ fn append_script_text(job: &mut egui::text::LayoutJob, text: &str, format: egui:
12041206
job.append(text, 0.0, format);
12051207
}
12061208

1209+
fn code_font_id() -> egui::FontId {
1210+
egui::FontId::monospace(CODE_FONT_SIZE)
1211+
}
1212+
12071213
fn token_format(
12081214
kind: ScriptTokenKind,
12091215
start: usize,
@@ -1234,7 +1240,7 @@ fn plain_format(
12341240
source: &str,
12351241
) -> egui::TextFormat {
12361242
let mut format = egui::TextFormat {
1237-
font_id: egui::FontId::monospace(11.0),
1243+
font_id: code_font_id(),
12381244
color: egui::Color32::from_rgb(220, 228, 238),
12391245
..Default::default()
12401246
};

examples/shooter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,7 @@ fn script_panel(
26042604
ui.add(
26052605
egui::TextEdit::multiline(&mut editor.buffer)
26062606
.code_editor()
2607+
.font(egui::FontId::monospace(13.0))
26072608
.desired_rows(26)
26082609
.desired_width(f32::INFINITY)
26092610
.layouter(&mut layouter),

0 commit comments

Comments
 (0)