mirror of
https://github.com/servo/servo.git
synced 2025-08-08 15:05:35 +01:00
servoshell: make the color picker and select picker closeable (#38373)
Addresses the first half of #38347 by making it possible to close the select picker and the color picker by pressing ESC or clicking off the modal. Marking this as draft since I need some help with squashing a bug - the "clicking off" part only triggers after moving the mouse or pressing any key, and I'm not sure why. Testing: Manual. Fixes: First half of #38347. --------- Signed-off-by: lumiscosity <averyrudelphe@gmail.com>
This commit is contained in:
parent
98522db8be
commit
757dbc0eda
1 changed files with 64 additions and 44 deletions
|
@ -500,39 +500,50 @@ impl Dialog {
|
||||||
if clickable_area.hovered() && option.is_disabled {
|
if clickable_area.hovered() && option.is_disabled {
|
||||||
ui.ctx().set_cursor_icon(egui::CursorIcon::NotAllowed);
|
ui.ctx().set_cursor_icon(egui::CursorIcon::NotAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ui.ctx().input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||||
|
*is_open = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let modal = Modal::new("select_element_picker".into()).area(area);
|
let modal = Modal::new("select_element_picker".into()).area(area);
|
||||||
modal.show(ctx, |ui| {
|
let backdrop_response = modal
|
||||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
.show(ctx, |ui| {
|
||||||
for option_or_optgroup in prompt.options() {
|
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||||
match &option_or_optgroup {
|
for option_or_optgroup in prompt.options() {
|
||||||
SelectElementOptionOrOptgroup::Option(option) => {
|
match &option_or_optgroup {
|
||||||
display_option(
|
SelectElementOptionOrOptgroup::Option(option) => {
|
||||||
ui,
|
|
||||||
option,
|
|
||||||
&mut selected_option,
|
|
||||||
&mut is_open,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
SelectElementOptionOrOptgroup::Optgroup { label, options } => {
|
|
||||||
ui.label(egui::RichText::new(label).strong());
|
|
||||||
|
|
||||||
for option in options {
|
|
||||||
display_option(
|
display_option(
|
||||||
ui,
|
ui,
|
||||||
option,
|
option,
|
||||||
&mut selected_option,
|
&mut selected_option,
|
||||||
&mut is_open,
|
&mut is_open,
|
||||||
true,
|
false,
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
},
|
SelectElementOptionOrOptgroup::Optgroup { label, options } => {
|
||||||
|
ui.label(egui::RichText::new(label).strong());
|
||||||
|
|
||||||
|
for option in options {
|
||||||
|
display_option(
|
||||||
|
ui,
|
||||||
|
option,
|
||||||
|
&mut selected_option,
|
||||||
|
&mut is_open,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
})
|
||||||
});
|
.backdrop_response;
|
||||||
|
|
||||||
|
//FIXME: Doesn't update until you move your mouse or press a key - why?
|
||||||
|
if backdrop_response.clicked() {
|
||||||
|
is_open = false;
|
||||||
|
}
|
||||||
|
|
||||||
prompt.select(selected_option);
|
prompt.select(selected_option);
|
||||||
|
|
||||||
|
@ -560,29 +571,38 @@ impl Dialog {
|
||||||
.fixed_pos(egui::pos2(position.min.x as f32, position.max.y as f32));
|
.fixed_pos(egui::pos2(position.min.x as f32, position.max.y as f32));
|
||||||
|
|
||||||
let modal = Modal::new("select_element_picker".into()).area(area);
|
let modal = Modal::new("select_element_picker".into()).area(area);
|
||||||
modal.show(ctx, |ui| {
|
let backdrop_response = modal
|
||||||
egui::widgets::color_picker::color_picker_color32(
|
.show(ctx, |ui| {
|
||||||
ui,
|
egui::widgets::color_picker::color_picker_color32(
|
||||||
current_color,
|
ui,
|
||||||
egui::widgets::color_picker::Alpha::Opaque,
|
current_color,
|
||||||
);
|
egui::widgets::color_picker::Alpha::Opaque,
|
||||||
|
);
|
||||||
|
|
||||||
ui.add_space(10.);
|
ui.add_space(10.);
|
||||||
|
|
||||||
if ui.button("Dismiss").clicked() {
|
if ui.button("Dismiss").clicked() ||
|
||||||
is_open = false;
|
ui.input(|i| i.key_pressed(egui::Key::Escape))
|
||||||
prompt.select(None);
|
{
|
||||||
}
|
is_open = false;
|
||||||
if ui.button("Select").clicked() {
|
prompt.select(None);
|
||||||
is_open = false;
|
}
|
||||||
let selected_color = RgbColor {
|
if ui.button("Select").clicked() {
|
||||||
red: current_color.r(),
|
is_open = false;
|
||||||
green: current_color.g(),
|
let selected_color = RgbColor {
|
||||||
blue: current_color.b(),
|
red: current_color.r(),
|
||||||
};
|
green: current_color.g(),
|
||||||
prompt.select(Some(selected_color));
|
blue: current_color.b(),
|
||||||
}
|
};
|
||||||
});
|
prompt.select(Some(selected_color));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.backdrop_response;
|
||||||
|
|
||||||
|
//FIXME: Doesn't update until you move your mouse or press a key - why?
|
||||||
|
if backdrop_response.clicked() {
|
||||||
|
is_open = false;
|
||||||
|
}
|
||||||
|
|
||||||
is_open
|
is_open
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue