Skip to content

Commit

Permalink
Add status tooltip, navigation buttons, and location field to TopBott…
Browse files Browse the repository at this point in the history
…omPanel

Closes servo#31690
  • Loading branch information
MunishMummadi committed Mar 18, 2024
1 parent a0e4c67 commit b2a3365
Showing 1 changed file with 58 additions and 44 deletions.
102 changes: 58 additions & 44 deletions ports/servoshell/minibrowser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,51 +143,65 @@ impl Minibrowser {
let widget_fbo = *widget_surface_fbo;
let _duration = context.run(window, |ctx| {
let InnerResponse { inner: height, .. } =
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.available_size(),
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()),
);
TopBottomPanel::top("toolbar").show(ctx, |ui| {
ui.allocate_ui_with_layout(
ui.available_size(),
egui::Layout::left_to_right(egui::Align::Center),
|ui| {
// Check if there is status text to show a tooltip for
if let Some(status_text) = &minibrowser.status {
// Calculate position for the tooltip at the bottom left corner
let tooltip_position = ui
.cursor()
.set(egui::Pos2::new(ui.layout().screen_rect().left(), ui.layout().screen_rect().bottom()));

// Show tooltip for status text
egui::containers::popup::show_tooltip_at(&ctx, Id::new("status_tooltip"), Some(tooltip_position), |ui| {
ui.label(status_text);
});
}

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.available_size(),
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);
}
},
);
},
);
ui.cursor().min.y
});

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);
}
},
);
},
);
ui.cursor().min.y
});
*toolbar_height = Length::new(height);

CentralPanel::default()
Expand Down

0 comments on commit b2a3365

Please sign in to comment.