mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
feat: add status tooltips (#32011)
* feat: add status tooltips * rebase and review fix --------- Co-authored-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
parent
67e556e3be
commit
9d57c0de77
2 changed files with 39 additions and 5 deletions
|
@ -8,8 +8,8 @@ use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use egui::{
|
use egui::{
|
||||||
CentralPanel, Color32, Frame, Key, Modifiers, PaintCallback, Pos2, Spinner, TopBottomPanel,
|
pos2, CentralPanel, Color32, Frame, Key, Modifiers, PaintCallback, Pos2, Spinner,
|
||||||
Vec2,
|
TopBottomPanel, Vec2,
|
||||||
};
|
};
|
||||||
use egui_glow::CallbackFn;
|
use egui_glow::CallbackFn;
|
||||||
use egui_winit::EventResponse;
|
use egui_winit::EventResponse;
|
||||||
|
@ -49,6 +49,8 @@ pub struct Minibrowser {
|
||||||
location_dirty: Cell<bool>,
|
location_dirty: Cell<bool>,
|
||||||
|
|
||||||
load_status: LoadStatus,
|
load_status: LoadStatus,
|
||||||
|
|
||||||
|
status_text: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum MinibrowserEvent {
|
pub enum MinibrowserEvent {
|
||||||
|
@ -86,6 +88,7 @@ impl Minibrowser {
|
||||||
location: RefCell::new(initial_url.to_string()),
|
location: RefCell::new(initial_url.to_string()),
|
||||||
location_dirty: false.into(),
|
location_dirty: false.into(),
|
||||||
load_status: LoadStatus::LoadComplete,
|
load_status: LoadStatus::LoadComplete,
|
||||||
|
status_text: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +238,19 @@ impl Minibrowser {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let mut embedder_events = vec![];
|
let mut embedder_events = vec![];
|
||||||
|
|
||||||
|
if let Some(status_text) = &self.status_text {
|
||||||
|
let position = Some(pos2(0.0, ctx.available_rect().max.y));
|
||||||
|
egui::containers::popup::show_tooltip_at(
|
||||||
|
ctx,
|
||||||
|
"tooltip_for_status_text".into(),
|
||||||
|
position,
|
||||||
|
|ui| {
|
||||||
|
ui.label(status_text.clone());
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
CentralPanel::default()
|
CentralPanel::default()
|
||||||
.frame(Frame::none())
|
.frame(Frame::none())
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
|
@ -389,6 +405,15 @@ impl Minibrowser {
|
||||||
need_update
|
need_update
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_status_text(
|
||||||
|
&mut self,
|
||||||
|
browser: &mut WebViewManager<dyn WindowPortsMethods>,
|
||||||
|
) -> bool {
|
||||||
|
let need_update = browser.status_text() != self.status_text;
|
||||||
|
self.status_text = browser.status_text();
|
||||||
|
need_update
|
||||||
|
}
|
||||||
|
|
||||||
/// Updates all fields taken from the given [WebViewManager], such as the location field.
|
/// Updates all fields taken from the given [WebViewManager], such as the location field.
|
||||||
/// Returns true iff the egui needs an update.
|
/// Returns true iff the egui needs an update.
|
||||||
pub fn update_webview_data(
|
pub fn update_webview_data(
|
||||||
|
@ -399,6 +424,8 @@ impl Minibrowser {
|
||||||
// because logical OR would short-circuit if any of the functions return true.
|
// because logical OR would short-circuit if any of the functions return true.
|
||||||
// We want to ensure that all functions are called. The "bitwise OR" operator
|
// We want to ensure that all functions are called. The "bitwise OR" operator
|
||||||
// does not short-circuit.
|
// does not short-circuit.
|
||||||
self.update_location_in_toolbar(browser) | self.update_spinner_in_toolbar(browser)
|
self.update_location_in_toolbar(browser) |
|
||||||
|
self.update_spinner_in_toolbar(browser) |
|
||||||
|
self.update_status_text(browser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ use crate::window_trait::{WindowPortsMethods, LINE_HEIGHT};
|
||||||
pub struct WebViewManager<Window: WindowPortsMethods + ?Sized> {
|
pub struct WebViewManager<Window: WindowPortsMethods + ?Sized> {
|
||||||
current_url: Option<ServoUrl>,
|
current_url: Option<ServoUrl>,
|
||||||
current_url_string: Option<String>,
|
current_url_string: Option<String>,
|
||||||
|
status_text: Option<String>,
|
||||||
|
|
||||||
/// List of top-level browsing contexts.
|
/// List of top-level browsing contexts.
|
||||||
/// Modified by EmbedderMsg::WebViewOpened and EmbedderMsg::WebViewClosed,
|
/// Modified by EmbedderMsg::WebViewOpened and EmbedderMsg::WebViewClosed,
|
||||||
|
@ -87,6 +88,7 @@ where
|
||||||
title: None,
|
title: None,
|
||||||
current_url: None,
|
current_url: None,
|
||||||
current_url_string: None,
|
current_url_string: None,
|
||||||
|
status_text: None,
|
||||||
webviews: HashMap::default(),
|
webviews: HashMap::default(),
|
||||||
creation_order: vec![],
|
creation_order: vec![],
|
||||||
focused_webview_id: None,
|
focused_webview_id: None,
|
||||||
|
@ -131,6 +133,10 @@ where
|
||||||
self.load_status
|
self.load_status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn status_text(&self) -> Option<String> {
|
||||||
|
self.status_text.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_events(&mut self) -> Vec<EmbedderEvent> {
|
pub fn get_events(&mut self) -> Vec<EmbedderEvent> {
|
||||||
std::mem::take(&mut self.event_queue)
|
std::mem::take(&mut self.event_queue)
|
||||||
}
|
}
|
||||||
|
@ -442,8 +448,9 @@ where
|
||||||
trace_embedder_msg!(msg, "{msg:?}");
|
trace_embedder_msg!(msg, "{msg:?}");
|
||||||
}
|
}
|
||||||
match msg {
|
match msg {
|
||||||
EmbedderMsg::Status(_status) => {
|
EmbedderMsg::Status(status) => {
|
||||||
// FIXME: surface this status string in the UI somehow
|
self.status_text = status;
|
||||||
|
need_update = true;
|
||||||
},
|
},
|
||||||
EmbedderMsg::ChangePageTitle(title) => {
|
EmbedderMsg::ChangePageTitle(title) => {
|
||||||
self.title = title;
|
self.title = title;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue