reduf / search

GUI built on ripgrep for recursive file content searching.
MIT License
48 stars 5 forks source link

UI size values are hardcoded #28

Closed Frenzie closed 11 months ago

Frenzie commented 1 year ago

Also see #27, but this one's simultaneously easier to fix and less bothersome.

For the sizing, playing with the following values is about 90% of the work, but there are some other hardcoded widget pixel size values as well. Presumably a default scaling factor based on DPI optionally to be overridden in config would be the best approach. [Edit: there's a reasonable looking sample here https://gist.github.com/loloof64/d0377776781be9d2af6c24e225efa5cf#file-src_support_mod-rs-L48-L59]

diff --git a/src/support.rs b/src/support.rs
index d9ea528..2f8291f 100755
--- a/src/support.rs
+++ b/src/support.rs
@@ -74,7 +74,7 @@ pub fn init(title: &str) -> System {
     imgui.fonts().add_font(&[
         FontSource::TtfData {
             data: include_bytes!("../resources/Lucon.ttf"),
-            size_pixels: 12.0,
+            size_pixels: 24.0,
             config: Some(FontConfig {
                 // As imgui-glium-renderer isn't gamma-correct with
                 // it's font rendering, we apply an arbitrary
@@ -90,7 +90,7 @@ pub fn init(title: &str) -> System {
         },
         FontSource::TtfData {
             data: include_bytes!("../resources/mplus-1p-regular.ttf"),
-            size_pixels: 15.0,
+            size_pixels: 30.0,
             config: Some(FontConfig {
                 // Oversampling font helps improve text rendering at
                 // expense of larger font atlas texture.

Screenshot_20230910_113245

reduf commented 1 year ago

Thanks a lot for those link. I will have a look how it can be improve. I'm in an unfortunate situation where I know the app is pretty broken on HDPI, but I have no way to test or debug it. I will try to do it with the links you provided.

reduf commented 1 year ago

I did some work and found weird stuff. So scaling the ui seems to mostly work multiplying the font size by the scaling factor and calling imgui.style_mut().scale_all_sizes(hidpi_factor);, but the mouse is broken, at least on my test on Windows.

I need to investigate this handling as it seems to multiply by two when I don't want. You can comment that out, but that's probably not a good fix in general.

Frenzie commented 1 year ago

but the mouse is broken, at least on my test on Windows.

Yup, that's #27.

You can comment that out, but that's probably not a good fix in general.

Funny, that's basically exactly what I ended up with a few days ago.

I think this is the intended solution, even though it looks odd to me. First it's been scaled up, then you scale it down again… sigh. :-)

            Event::WindowEvent {
                event: WindowEvent::CursorMoved { position, ..},
                ..
            } => imgui.io_mut().add_mouse_pos_event([
                (position.x as f32) / hidpi_factor,
                (position.y as f32) / hidpi_factor,
            ]),
Frenzie commented 1 year ago

Here they do that too: https://github.com/ExPixel/rust-imgui/blob/f7e8941405b720ea29f7a535794f3d0a0fa8bfc2/examples/imgui_demo.rs#L175

reduf commented 1 year ago

I'll check with imgui-winit-support crate if it's intended.

I tested with a friend on a Mac that has hidpi and the imgui.io_mut().font_global_scale = (1.0 / hidpi_factor) as f32; wasn't good. The updating of the mouse was also necessary, but there was a weird bug were a lot of widget were offset to the right. For instance, the settings window would be seemingly empty, but when increasing the horizontal size, you would start to see the widgets.

Did you also experience that?

Also are you sure about the / hidpi_factor in your snippet? I'm pretty sure, I did it without.

Frenzie commented 1 year ago

I'll check with imgui-winit-support crate if it's intended.

I'd say almost certainly, since it's not just on Windows. (I never even checked Windows. ;-) )

Did you also experience that?

Yes, see the screenshot in the OP. Then I thought it was just because I'd only adjusted those two font sizes, but imgui.style_mut().scale_all_sizes(hidpi_factor); has exactly the same effect

Frenzie commented 1 year ago

Also are you sure about the / hidpi_factor in your snippet? I'm pretty sure, I did it without.

The position.x and y as reported are exactly right, but in the UI they're interpreted as twice the size. So in principle you'd need to divide them by hidpi_factor to fix them, but in practice that doesn't seem to have any effect.

reduf commented 11 months ago

Was fixed in https://github.com/reduf/search/tree/v0.8.0, will re-open if it wasn't correctly.

garry-ut99 commented 1 month ago

Still mouse-coord is broken on Windows 7 and 10 (didn't try on 8 and 11), when DPI scaling is set to 125% (also might occur at other DPI values, I didn't check so far).