FLTK logo

[fltk.general] Background Fill for Group

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 ]

Background Fill for Group Webb Hinton Jun 16, 2021  
  What's a good approach to creating a Group that has a "filled" background?  I.e when a widget moves inside of it's parent group, the background is "cleared", thus avoiding the "tracing" effect you get otherwise:

tracing_issue.gif

Code: (sorry it is in rust)
use fltk::{app, draw::*, enums::*, frame::Frame, group::Group, prelude::*, window::Window, button::*};

fn main() {
    let app = app::App::default();
    let mut wind = Window::default()
        .with_size(400, 300)
        .with_label("Group Background Color");
    wind.make_resizable(true);
    let mut group = Group::new(0, 0, 400, 300, None);
    let mut button= Button::new(100,200,50,20,"animate");
    //frame we want to see  
    let mut frame = Frame::new(0, 0, 100, 100, "redraw parent");
    frame.set_color(Color::Magenta);
    frame.set_frame(FrameType::BorderFrame);

    group.end();
    // group.draw(move |widg| {
    //     //background fill
    //     draw_rect_fill(widg.x(), widg.y(), widg.width(), widg.height(), Color::Red);
    //     //draw the children after drawing the background fill color
    //     widg.draw_children();
    // });
    wind.end();
    wind.show();
    
    button.set_callback(move |_| {
        let mut frame = frame.clone();
        std::thread::spawn(move || {
            for i in 0..1000 {
                app::sleep(0.05);
                    frame.resize(frame.x()+10, frame.y(), frame.width(), frame.height());
                    dbg!(frame.x(), frame.y(), frame.width(), frame.height());
                    //Only Redraws the Widget, frame does not show
                    // frame.redraw();
                    //Redraws as expected, but redraws all children
                    frame.parent().unwrap().redraw();
                    dbg!("thread working!");
            }
        });
    });

    app.run().unwrap();
}

--
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/c163cb02-61ae-4ce1-b155-61588cc4c697n%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'.