mirror of
https://github.com/servo/servo.git
synced 2025-07-27 01:00:41 +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 euclid::Length;
|
||||||
use log::{trace, warn};
|
use log::{trace, warn};
|
||||||
use servo::compositing::windowing::EmbedderEvent;
|
use servo::compositing::windowing::EmbedderEvent;
|
||||||
|
use servo::msg::constellation_msg::TraversalDirection;
|
||||||
use servo::servo_geometry::DeviceIndependentPixel;
|
use servo::servo_geometry::DeviceIndependentPixel;
|
||||||
use servo::servo_url::ServoUrl;
|
use servo::servo_url::ServoUrl;
|
||||||
use servo::webrender_surfman::WebrenderSurfman;
|
use servo::webrender_surfman::WebrenderSurfman;
|
||||||
|
@ -34,6 +35,8 @@ pub struct Minibrowser {
|
||||||
pub enum MinibrowserEvent {
|
pub enum MinibrowserEvent {
|
||||||
/// Go button clicked.
|
/// Go button clicked.
|
||||||
Go,
|
Go,
|
||||||
|
Back,
|
||||||
|
Forward,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Minibrowser {
|
impl Minibrowser {
|
||||||
|
@ -81,6 +84,17 @@ impl Minibrowser {
|
||||||
} = self;
|
} = self;
|
||||||
let _duration = context.run(window, |ctx| {
|
let _duration = context.run(window, |ctx| {
|
||||||
TopBottomPanel::top("toolbar").show(ctx, |ui| {
|
TopBottomPanel::top("toolbar").show(ctx, |ui| {
|
||||||
|
ui.allocate_ui_with_layout(
|
||||||
|
ui.available_size(),
|
||||||
|
egui::Layout::left_to_right(egui::Align::Center),
|
||||||
|
|ui| {
|
||||||
|
if ui.button("back").clicked() {
|
||||||
|
event_queue.borrow_mut().push(MinibrowserEvent::Back);
|
||||||
|
}
|
||||||
|
if ui.button("forward").clicked() {
|
||||||
|
event_queue.borrow_mut().push(MinibrowserEvent::Forward);
|
||||||
|
}
|
||||||
|
|
||||||
ui.allocate_ui_with_layout(
|
ui.allocate_ui_with_layout(
|
||||||
ui.available_size(),
|
ui.available_size(),
|
||||||
egui::Layout::right_to_left(egui::Align::Center),
|
egui::Layout::right_to_left(egui::Align::Center),
|
||||||
|
@ -94,6 +108,7 @@ impl Minibrowser {
|
||||||
ui.available_size(),
|
ui.available_size(),
|
||||||
egui::TextEdit::singleline(&mut *location.borrow_mut()),
|
egui::TextEdit::singleline(&mut *location.borrow_mut()),
|
||||||
);
|
);
|
||||||
|
|
||||||
if location_field.changed() {
|
if location_field.changed() {
|
||||||
location_dirty.set(true);
|
location_dirty.set(true);
|
||||||
}
|
}
|
||||||
|
@ -108,6 +123,8 @@ impl Minibrowser {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
toolbar_height.set(Length::new(ctx.used_rect().height()));
|
toolbar_height.set(Length::new(ctx.used_rect().height()));
|
||||||
|
@ -139,6 +156,20 @@ impl Minibrowser {
|
||||||
break;
|
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