Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed color edit popup going outside the screen #2270

Merged
merged 5 commits into from
Nov 11, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions crates/egui/src/widgets/color_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,29 @@ pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva, alpha: Alpha) -> Res
if button_response.clicked() {
ui.memory().toggle_popup(popup_id);
}

const COLOR_SLIDER_WIDTH: f32 = 210.0;
// TODO(ItsEthra): find a more precise way to evaluate color edit popup height
const WIDTH_TO_HIGHT: f32 = 1.3666667;

let screen_max = ui.input().screen_rect.max;
let mut anchor_pos = button_response.rect.max;

if anchor_pos.x + COLOR_SLIDER_WIDTH > screen_max.x {
anchor_pos.x = screen_max.x - COLOR_SLIDER_WIDTH - ui.spacing().window_margin.right * 2.;
}

if anchor_pos.y + COLOR_SLIDER_WIDTH * WIDTH_TO_HIGHT > screen_max.y {
anchor_pos.y = screen_max.y - COLOR_SLIDER_WIDTH * WIDTH_TO_HIGHT;
}

// TODO(emilk): make it easier to show a temporary popup that closes when you click outside it
if ui.memory().is_popup_open(popup_id) {
let area_response = Area::new(popup_id)
.order(Order::Foreground)
.fixed_pos(button_response.rect.max)
.fixed_pos(anchor_pos)
ItsEthra marked this conversation as resolved.
Show resolved Hide resolved
.show(ui.ctx(), |ui| {
ui.spacing_mut().slider_width = 210.0;
ui.spacing_mut().slider_width = COLOR_SLIDER_WIDTH;
Frame::popup(ui.style()).show(ui, |ui| {
if color_picker_hsva_2d(ui, hsva, alpha) {
button_response.mark_changed();
Expand Down