Skip to content

Commit

Permalink
Make location bar text yellow when dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
delan committed Mar 8, 2024
1 parent d31d512 commit d2fa6be
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions ports/servoshell/minibrowser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use std::sync::Arc;
use std::time::Instant;

use egui::{
CentralPanel, Frame, InnerResponse, Key, Modifiers, PaintCallback, Pos2, TopBottomPanel, Vec2,
CentralPanel, Color32, Frame, InnerResponse, Key, Modifiers, PaintCallback, Pos2,
TopBottomPanel, Vec2,
};
use egui_glow::CallbackFn;
use egui_winit::EventResponse;
Expand Down Expand Up @@ -187,11 +188,12 @@ impl Minibrowser {
);
});

let mut location_dirty = None;
let mut location_dirty = false;
let mut location = location.borrow_mut();
if let Some(webview_location) = webviews.focused_webview_mut().map(|w| &w.location) {
if webview_location != &*location {
*location = webview_location.clone();
if let Some(webview) = webviews.focused_webview_mut() {
location_dirty = webview.location_dirty;
if webview.location != *location {
*location = webview.location.clone();
}
}

Expand All @@ -213,16 +215,16 @@ impl Minibrowser {
|ui| {
if ui.button("go").clicked() {
event_queue.borrow_mut().push(MinibrowserEvent::Go);
location_dirty = Some(false);
location_dirty = false;
}

let location_field = ui.add_sized(
ui.available_size(),
egui::TextEdit::singleline(&mut *location),
);
let location_field = egui::TextEdit::singleline(&mut *location)
.text_color_opt(location_dirty.then_some(Color32::YELLOW));
let location_field =
ui.add_sized(ui.available_size(), location_field);

if location_field.changed() {
location_dirty = Some(true);
location_dirty = true;
}
if ui.input(|i| {
i.clone().consume_key(Modifiers::COMMAND, Key::L)
Expand All @@ -233,7 +235,7 @@ impl Minibrowser {
ui.input(|i| i.clone().key_pressed(Key::Enter))
{
event_queue.borrow_mut().push(MinibrowserEvent::Go);
location_dirty = Some(false);
location_dirty = false;
}
},
);
Expand All @@ -244,9 +246,7 @@ impl Minibrowser {

*toolbar_height = Length::new(height);
if let Some(webview) = webviews.focused_webview_mut() {
if let Some(location_dirty) = location_dirty {
webview.location_dirty = location_dirty;
}
webview.location_dirty = location_dirty;
if *location != webview.location {
webview.location = location.clone();
}
Expand Down

0 comments on commit d2fa6be

Please sign in to comment.