I have a property grid that contains properties ( name value pairs ). In the simplest case, a single property is displayed as a label ( for the name ) and a textbox ( for the value, which can be edited by the user ) displayed on a panel. The panels for all the properties are displayed in a panel with scrollbars.

This code:

form fm( 0, nana::size{ 400, 600 } );
fm.caption("PropGrid2 demo 2");

//  Construct property grid 
panel<true> pnl( fm, { 20, 20, 300, 600 });
cPropGrid pg( pnl );
pg.category( "Strings" );

// Add 20 properties
for( int k = 0; k < 20; k++ )
{
    // add property ( label and textbox )
    pg.string(
        "test" + std::to_string(k),   // label caption
        std::to_string(k) );         // textbox initial value
}

Shows

5d9e01c545248.jpg

That’s fine!

What happens if the form is not high enough to show all the properties?

form fm( 0, nana::size{ 400, 300 } );

gives

5d9e01f0dd041.jpg

Not perfect, but acceptable for the moment.

The bigger problem is when the form is resized to reveal the properties that were outside the initial form size

5d9e024235205.jpg

Although the textboxes are revealed as expected in the larger resized form, the labels are not!

Note that this is not a simple problem with labels. If I add a label to the form located outside the initial form size, it is revealed correctly when the form is resized.

    // Add label to form, outside the initial form size
    nana::label lbtest( fm );
    lbtest.move( {10, 650, 60,30});
    lbtest.caption("test");

gives after form resizing

5d9e02709ac07.jpg

So it must be something to do with adding labels on a panel on another on another panel on the form.

What is the difference between the textbox and the label that might account for the label not appearing while the textbox does?

I do not expect anyone to look at the code for this and fix it for me! I would just like a hint from someone who knows the detailed implementation of labels and textboxes about what difference between them might explain this behaviour and point me in the right direction to working around this problem.

( However, it anyone does want to look at the complete code, it can be seen here: https://github.com/JamesBremner/nana-extra/tree/master/propgrid2 )

I have a property grid that contains properties ( name value pairs ). In the simplest case, a single property is displayed as a label ( for the name ) and a textbox ( for the value, which can be edited by the user ) displayed on a panel. The panels for all the properties are displayed in a panel with scrollbars. This code: form fm( 0, nana::size{ 400, 600 } ); fm.caption("PropGrid2 demo 2"); // Construct property grid panel<true> pnl( fm, { 20, 20, 300, 600 }); cPropGrid pg( pnl ); pg.category( "Strings" ); // Add 20 properties for( int k = 0; k < 20; k++ ) { // add property ( label and textbox ) pg.string( "test" + std::to_string(k), // label caption std::to_string(k) ); // textbox initial value } Shows ![5d9e01c545248.jpg](serve/attachment&path=5d9e01c545248.jpg) That’s fine! What happens if the form is not high enough to show all the properties? ```` form fm( 0, nana::size{ 400, 300 } ); ```` gives ![5d9e01f0dd041.jpg](serve/attachment&path=5d9e01f0dd041.jpg) Not perfect, but acceptable for the moment. The bigger problem is when the form is resized to reveal the properties that were outside the initial form size ![5d9e024235205.jpg](serve/attachment&path=5d9e024235205.jpg) Although the textboxes are revealed as expected in the larger resized form, the labels are not! Note that this is not a simple problem with labels. If I add a label to the form located outside the initial form size, it is revealed correctly when the form is resized. ```` // Add label to form, outside the initial form size nana::label lbtest( fm ); lbtest.move( {10, 650, 60,30}); lbtest.caption("test"); ```` gives after form resizing ![5d9e02709ac07.jpg](serve/attachment&path=5d9e02709ac07.jpg) So it must be something to do with adding labels on a panel on another on another panel on the form. What is the difference between the textbox and the label that might account for the label not appearing while the textbox does? I do not expect anyone to look at the code for this and fix it for me! I would just like a hint from someone who knows the detailed implementation of labels and textboxes about what difference between them might explain this behaviour and point me in the right direction to working around this problem. ( However, it anyone does want to look at the complete code, it can be seen here: https://github.com/JamesBremner/nana-extra/tree/master/propgrid2 )
edited Oct 9 at 4:54 pm

This is not a problem with nana.

The same thing happens when I use the windows API directly

5dac739daf598.png

It is a basic problem with the windows api function SetWindowText ( https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowtexta )

I suppose that the only workaround would be to handle the window resizing event and force redrawing the label texts.

( FYI 'windex' is the header only gui framework I am developing to provide a thin modern C++ wrapper around the windows API with the aim of providing a similar capability to nana but without the build headaches (https://github.com/JamesBremner/windex/wiki/propertyGrid )

This is **not** a problem with nana. The same thing happens when I use the windows API directly ![5dac739daf598.png](serve/attachment&path=5dac739daf598.png) It is a basic problem with the windows api function SetWindowText ( https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowtexta ) I suppose that the only workaround would be to handle the window resizing event and force redrawing the label texts. ( FYI 'windex' is the header only gui framework I am developing to provide a thin modern C++ wrapper around the windows API with the aim of providing a similar capability to nana but without the build headaches (https://github.com/JamesBremner/windex/wiki/propertyGrid )

The problem is that when the window containing the property grid resizes, any property label that was previously outside the containing window receives a paint message for just the part of the label that has become newly visible. Any label that was partially visible does NOT receive a paint message.

So, when the containing window is slowly resized only the top row of pixels in newly visible labels is drawn. If the resizing is done more quickly, the first few rows are drawn and you can see the tops of the letters in the labels. Resize super fast and the entire labels can be seen.

The workaround is to handle the resize event for the window containing the property grid and force the property grid to loop over all the labels, forcing them all to be redrawn.

propertyGrid pg( form );
...
    form.events().resize([&](int w, int h)
{
    /// window containing propertyGrid has been resized
    /// ensure that every visible label is completely redrawn
    pg.update();
});
...
/// force every property to redraw its label
void propertyGrid::update()
{
    for( auto& p : myProperty )
        p.update();
}
...
/// force label to redraw
void property::update()
{
    myLabel.update();
}
...
/// force widget to redraw completely
void widget::update()
{
    InvalidateRect(myHandle,NULL,true);
    UpdateWindow(myHandle);
}

I have implemented this for windex::propertyGrid. Does anyone need it for nana-extra::propgrid2?

The problem is that when the window containing the property grid resizes, any property label that was previously outside the containing window receives a paint message for just the part of the label that has become newly visible. Any label that was partially visible does NOT receive a paint message. So, when the containing window is slowly resized only the top row of pixels in newly visible labels is drawn. If the resizing is done more quickly, the first few rows are drawn and you can see the tops of the letters in the labels. Resize super fast and the entire labels can be seen. The workaround is to handle the resize event for the window containing the property grid and force the property grid to loop over all the labels, forcing them all to be redrawn. propertyGrid pg( form ); ... form.events().resize([&](int w, int h) { /// window containing propertyGrid has been resized /// ensure that every visible label is completely redrawn pg.update(); }); ... /// force every property to redraw its label void propertyGrid::update() { for( auto& p : myProperty ) p.update(); } ... /// force label to redraw void property::update() { myLabel.update(); } ... /// force widget to redraw completely void widget::update() { InvalidateRect(myHandle,NULL,true); UpdateWindow(myHandle); } I have implemented this for windex::propertyGrid. Does anyone need it for nana-extra::propgrid2?
16
views
2
replies
1
followers
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft