FLTK logo

[fltk.general] Pixel perfect resizing of a groups child

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Pixel perfect resizing of a groups child Webb Hinton Jun 19, 2021  
 
I'm trying to figure out how to get a child widget to conform to the dimensions of it's parent widget exactly. While the code below (modeled after the code from Fl_pack.cxx does a decent job of resizing the child widget, when resizing the window the child and parent can differ a pixel or two in size. This is particularly noticeable when when resizing the window quickly.

It seems the drawing of the child is somehow "lagging behind" the drawing of the parent.

use fltk::{app, button::Button, prelude::*, window::Window, enums::*, group::Group, frame::Frame, *};

fn main() {
    let app = app::App::default();
    let mut wind = Window::default().with_size(400, 300);
    wind.make_resizable(true);

    //intialize group
    let mut group = Group::new(50,50,300,200,"");
    group.make_resizable(false);
    group.set_frame(FrameType::FlatBox);
    group.set_color(Color::Red);

    //initialize frame
    let mut left_frame= Frame::new(group.x(),group.y(),50,50,"left");
    left_frame.set_frame(FrameType::FlatBox);
    left_frame.set_color(Color::Blue);

    group.end();

    //create a clone the frame in order to move it into draw callback
    let mut frame_left_cl = left_frame.clone();
    group.draw(move|widg|{
      //get child 0 (the frame we created)
      let mut child = widg.child(0).unwrap();
      // draws the child widget correctly on app start
      child.set_damage(true);
      //create a Widget from our <Box<dyn WidgetExt>>
      let mut child_as_widget = unsafe {widget::Widget::from_widget_ptr(child.as_widget_ptr())};
      //resize the child
      child_as_widget.resize(widg.x(), widg.y(), widg.width(), child.height());
      //update the child
      widg.update_child(&mut child_as_widget);
    });

    wind.end();
    wind.show();
    app.run().unwrap();
}

See the red group peaking out from under the blue frame: 
resizing_issue.gif
Dragging the window to the right seems to make the parent larger than the child, and dragging the window to the left seems to make the child larger than the parent.

Close up:

close_up.PNG


--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/9ceee8a5-e54b-428c-b8ef-2c9349f5e03fn%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.