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

Prevents slight encroachment on the title outer line in egui::Window. #4154

Closed
wants to merge 9 commits into from

Conversation

rustbasic
Copy link
Contributor

@rustbasic rustbasic commented Mar 10, 2024

Prevents slight encroachment on the title outer line in egui::Window.

You can easy checkable when title has a background natural color.

@rustbasic
Copy link
Contributor Author

@emilk

Please be sure to approve this.

@rustbasic
Copy link
Contributor Author

rustbasic commented Mar 16, 2024

@varphone

Would you adjust the rest to match this?

@emilk emilk added the egui label Mar 20, 2024
@emilk
Copy link
Owner

emilk commented Mar 20, 2024

A screenshot would make this easier to review!

@emilk
Copy link
Owner

emilk commented Mar 21, 2024

Ok, I took a screenshot myself.

master:

Screenshot 2024-03-21 at 10 59 08

this PR:

Screenshot 2024-03-21 at 10 59 30

This looks worse to me.

@emilk emilk closed this Mar 21, 2024
@rustbasic
Copy link
Contributor Author

rustbasic commented Mar 22, 2024

@emilk

Dear, emilk.

This is an essential part .
If we don't like this, you'll need to modify other parts.

I will explain with screenshots later.
( emilk's screenshot also looks better with this applied. )

@varphone
Copy link
Contributor

varphone commented May 4, 2024

@emilk

Dear, emilk.

This is an essential part . If we don't like this, you'll need to modify other parts.

I will explain with screenshots later. ( emilk's screenshot also looks better with this applied. )

Is it necessary to add a stroke to the title bar background?
Considering that the window area already has a stroke, it might be redundant.

@rustbasic
Copy link
Contributor Author

rustbasic commented May 4, 2024

Is it necessary to add a stroke to the title bar background? Considering that the window area already has a stroke, it might be redundant.

@varphone

If you apply color to the title bar, it will intrude slightly. In particular, the right end is invaded by about 0.5 to 2.0, and the left side is invaded by about 0.1 to 1.0. So I think we need to apply this and apply the rest accordingly.
(When selecting focus)

test example

// bug test example : Custom Thick Frame
use eframe::egui::*;

fn main() -> Result<(), eframe::Error> {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default().with_inner_size([800.0, 600.0]),
        ..Default::default()
    };

    eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.heading("My egui Application");

            ui.label("LoremIpsum label");
            let mut job = egui::text::LayoutJob::default();
            job.append("Lorem", 0.0, TextFormat::default());
            job.append("Ipsum", 0.0, TextFormat::default());
            job.append(" LayoutJob", 0.0, TextFormat::default());
            ui.label(job);
            ui.label(RichText::new("LoremIpsum RichText::size(14.0)").size(14.0));

            let frame = egui::containers::Frame::none() // <-- new
                .fill(egui::Color32::from_rgb(180, 220, 160)) // <-- new
                .stroke(egui::Stroke::new(
                    20.0,
                    egui::Color32::from_rgb(40, 100, 30),
                )) // <-- new
                .inner_margin(egui::Margin::symmetric(20.0, 20.0)); // <-- new
                                                                    // .outer_margin(egui::Margin::symmetric(0.0, 0.0)); // <-- new
            let _response_w = egui::Window::new("test")
                .id(egui::Id::new("demo_window_options1"))
                .default_size([400.0, 300.0])
                .frame(frame) // <-- new
                .resizable(true)
                .constrain(true)
                .collapsible(true)
                .title_bar(true)
                // .scroll2([true, true])
                .enabled(true)
                .show(ui.ctx(), |ui| {
                    let (response, _painter) =
                        ui.allocate_painter(vec2(300.0, 150.0), Sense::click());
                    let clicked_pos = response.interact_pointer_pos();
                    if response.clicked() {
                        let text =
                            format!("clicked_pos: {:?}", clicked_pos.unwrap_or(pos2(0.0, 0.0)));
                        ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                        ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                        ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                    }
                    if response.is_pointer_button_down_on() {
                        let text = format!("down_pos: {:?}", clicked_pos.unwrap_or(pos2(0.0, 0.0)));
                        ui.label(text);
                    }
                });

            let frame = egui::containers::Frame::none() // <-- new
                .fill(egui::Color32::from_rgb(180, 220, 160)) // <-- new
                .stroke(egui::Stroke::new(1.0, egui::Color32::from_rgb(40, 100, 30))) // <-- new
                .inner_margin(egui::Margin::symmetric(20.0, 20.0)); // <-- new
                                                                    // .outer_margin(egui::Margin::symmetric(0.0, 0.0)); // <-- new
            let _response_w = egui::Window::new("test")
                .id(egui::Id::new("demo_window_options2"))
                .default_size([400.0, 300.0])
                .frame(frame) // <-- new
                .resizable(true)
                .constrain(true)
                .collapsible(true)
                .title_bar(true)
                // .scroll2([true, true])
                .enabled(true)
                .show(ui.ctx(), |ui| {
                    let (response, _painter) =
                        ui.allocate_painter(vec2(300.0, 150.0), Sense::click());
                    let clicked_pos = response.interact_pointer_pos();
                    if response.clicked() {
                        let text =
                            format!("clicked_pos: {:?}", clicked_pos.unwrap_or(pos2(0.0, 0.0)));
                        ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                        ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                        ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                    }
                    if response.is_pointer_button_down_on() {
                        let text = format!("down_pos: {:?}", clicked_pos.unwrap_or(pos2(0.0, 0.0)));
                        ui.label(text);
                    }
                });

            let _response_w = egui::Window::new("test")
                .id(egui::Id::new("demo_window_options3"))
                .default_size([400.0, 300.0])
                .resizable(true)
                .constrain(true)
                .collapsible(true)
                .title_bar(true)
                // .scroll2([true, true])
                .enabled(true)
                .show(ui.ctx(), |ui| {
                    let (response, _painter) =
                        ui.allocate_painter(vec2(300.0, 150.0), Sense::click());
                    let clicked_pos = response.interact_pointer_pos();
                    if response.clicked() {
                        let text =
                            format!("clicked_pos: {:?}", clicked_pos.unwrap_or(pos2(0.0, 0.0)));
                        ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                        ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                        ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                    }
                    if response.is_pointer_button_down_on() {
                        let text = format!("down_pos: {:?}", clicked_pos.unwrap_or(pos2(0.0, 0.0)));
                        ui.label(text);
                    }
                });

            let (response, _painter) = ui.allocate_painter(vec2(300.0, 150.0), Sense::click());
            let clicked_pos = response.interact_pointer_pos();
            if response.clicked() {
                let text = format!("clicked_pos: {:?}", clicked_pos.unwrap_or(pos2(0.0, 0.0)));
                ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
                ui.label(RichText::new(text.clone()).color(Color32::LIGHT_RED));
            }
            if response.is_pointer_button_down_on() {
                let text = format!("down_pos: {:?}", clicked_pos.unwrap_or(pos2(0.0, 0.0)));
                ui.label(text);
            }
        });
    })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants