Skip to content

Commit

Permalink
Default word_wrap to true and set autoshrink to false for the scroll …
Browse files Browse the repository at this point in the history
…area
  • Loading branch information
jleibs committed May 10, 2023
1 parent 7b307ac commit fad78f3
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions crates/re_viewer/src/ui/view_text_box/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@ use super::SceneTextBox;

// --- Main view ---

#[derive(Clone, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[serde(default)]
#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub struct ViewTextBoxState {
monospace: bool,
word_wrap: bool,
}

impl Default for ViewTextBoxState {
fn default() -> Self {
Self {
monospace: false,
word_wrap: true,
}
}
}

impl ViewTextBoxState {
pub fn selection_ui(&mut self, re_ui: &re_ui::ReUi, ui: &mut egui::Ui) {
crate::profile_function!();

re_ui.selection_grid(ui, "log_config").show(ui, |ui| {
re_ui.selection_grid(ui, "text_config").show(ui, |ui| {
re_ui.grid_left_hand_label(ui, "Text style");
ui.vertical(|ui| {
ui.radio_value(&mut self.monospace, false, "Proportional");
Expand All @@ -37,23 +45,25 @@ pub(crate) fn view_text_box(
crate::profile_function!();

ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
egui::ScrollArea::both().show(ui, |ui| {
// TODO(jleibs): better handling for multiple results
if scene.text_entries.len() == 1 {
let mut text = egui::RichText::new(&scene.text_entries[0].body);
egui::ScrollArea::both()
.auto_shrink([false, false])
.show(ui, |ui| {
// TODO(jleibs): better handling for multiple results
if scene.text_entries.len() == 1 {
let mut text = egui::RichText::new(&scene.text_entries[0].body);

if state.monospace {
text = text.monospace();
}
if state.monospace {
text = text.monospace();
}

ui.add(Label::new(text).wrap(state.word_wrap));
} else {
ui.label(format!(
"Unexpected number of text entries: {}. Limit your query to 1.",
scene.text_entries.len()
));
}
})
ui.add(Label::new(text).wrap(state.word_wrap));
} else {
ui.label(format!(
"Unexpected number of text entries: {}. Limit your query to 1.",
scene.text_entries.len()
));
}
})
})
.response
}

0 comments on commit fad78f3

Please sign in to comment.