mirror of
https://github.com/servo/servo.git
synced 2025-07-25 16:20:36 +01:00
Minibrowser: Add Back and Forward navigation (#30805)
* add back and forward button * use left_to_right egui layout * use nested allocate_ui_with_layout
This commit is contained in:
parent
8ded1072ce
commit
a326a60c16
1 changed files with 49 additions and 18 deletions
|
@ -10,6 +10,7 @@ use egui::{Key, Modifiers, TopBottomPanel};
|
|||
use euclid::Length;
|
||||
use log::{trace, warn};
|
||||
use servo::compositing::windowing::EmbedderEvent;
|
||||
use servo::msg::constellation_msg::TraversalDirection;
|
||||
use servo::servo_geometry::DeviceIndependentPixel;
|
||||
use servo::servo_url::ServoUrl;
|
||||
use servo::webrender_surfman::WebrenderSurfman;
|
||||
|
@ -34,6 +35,8 @@ pub struct Minibrowser {
|
|||
pub enum MinibrowserEvent {
|
||||
/// Go button clicked.
|
||||
Go,
|
||||
Back,
|
||||
Forward,
|
||||
}
|
||||
|
||||
impl Minibrowser {
|
||||
|
@ -83,29 +86,43 @@ impl Minibrowser {
|
|||
TopBottomPanel::top("toolbar").show(ctx, |ui| {
|
||||
ui.allocate_ui_with_layout(
|
||||
ui.available_size(),
|
||||
egui::Layout::right_to_left(egui::Align::Center),
|
||||
egui::Layout::left_to_right(egui::Align::Center),
|
||||
|ui| {
|
||||
if ui.button("go").clicked() {
|
||||
event_queue.borrow_mut().push(MinibrowserEvent::Go);
|
||||
location_dirty.set(false);
|
||||
if ui.button("back").clicked() {
|
||||
event_queue.borrow_mut().push(MinibrowserEvent::Back);
|
||||
}
|
||||
if ui.button("forward").clicked() {
|
||||
event_queue.borrow_mut().push(MinibrowserEvent::Forward);
|
||||
}
|
||||
|
||||
let location_field = ui.add_sized(
|
||||
ui.allocate_ui_with_layout(
|
||||
ui.available_size(),
|
||||
egui::TextEdit::singleline(&mut *location.borrow_mut()),
|
||||
egui::Layout::right_to_left(egui::Align::Center),
|
||||
|ui| {
|
||||
if ui.button("go").clicked() {
|
||||
event_queue.borrow_mut().push(MinibrowserEvent::Go);
|
||||
location_dirty.set(false);
|
||||
}
|
||||
|
||||
let location_field = ui.add_sized(
|
||||
ui.available_size(),
|
||||
egui::TextEdit::singleline(&mut *location.borrow_mut()),
|
||||
);
|
||||
|
||||
if location_field.changed() {
|
||||
location_dirty.set(true);
|
||||
}
|
||||
if ui.input(|i| i.clone().consume_key(Modifiers::COMMAND, Key::L)) {
|
||||
location_field.request_focus();
|
||||
}
|
||||
if location_field.lost_focus() &&
|
||||
ui.input(|i| i.clone().key_pressed(Key::Enter))
|
||||
{
|
||||
event_queue.borrow_mut().push(MinibrowserEvent::Go);
|
||||
location_dirty.set(false);
|
||||
}
|
||||
},
|
||||
);
|
||||
if location_field.changed() {
|
||||
location_dirty.set(true);
|
||||
}
|
||||
if ui.input(|i| i.clone().consume_key(Modifiers::COMMAND, Key::L)) {
|
||||
location_field.request_focus();
|
||||
}
|
||||
if location_field.lost_focus() &&
|
||||
ui.input(|i| i.clone().key_pressed(Key::Enter))
|
||||
{
|
||||
event_queue.borrow_mut().push(MinibrowserEvent::Go);
|
||||
location_dirty.set(false);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
@ -139,6 +156,20 @@ impl Minibrowser {
|
|||
break;
|
||||
}
|
||||
},
|
||||
MinibrowserEvent::Back => {
|
||||
let browser_id = browser.browser_id().unwrap();
|
||||
app_event_queue.push(EmbedderEvent::Navigation(
|
||||
browser_id,
|
||||
TraversalDirection::Back(1),
|
||||
));
|
||||
},
|
||||
MinibrowserEvent::Forward => {
|
||||
let browser_id = browser.browser_id().unwrap();
|
||||
app_event_queue.push(EmbedderEvent::Navigation(
|
||||
browser_id,
|
||||
TraversalDirection::Forward(1),
|
||||
));
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue