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 25, 2024
1 parent 3fa60d5 commit d9cb2ec
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions ports/servoshell/minibrowser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::num::NonZeroU32;
use std::sync::Arc;
use std::time::Instant;

use egui::{CentralPanel, Frame, Key, Modifiers, PaintCallback, Pos2, TopBottomPanel, Vec2};
use egui::{
CentralPanel, Color32, Frame, Key, Modifiers, PaintCallback, Pos2, TopBottomPanel, Vec2,
};
use egui_glow::CallbackFn;
use egui_winit::EventResponse;
use euclid::{Box2D, Length, Point2D, Scale, Size2D};
Expand Down Expand Up @@ -185,11 +187,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 @@ -210,16 +213,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)) {
location_field.request_focus();
Expand All @@ -228,7 +231,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 @@ -242,9 +245,7 @@ impl Minibrowser {
*toolbar_height = Length::new(ctx.available_rect().min.y);

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 d9cb2ec

Please sign in to comment.