Re: How to fully expand a widget within a window?
- From: Samvel <ksamvel gmail com>
- To: "Jonathon Jongsma" <jonathon jongsma gmail com>
- Cc: Murray Cumming <murrayc murrayc com>, gtkmm-list gnome org
- Subject: Re: How to fully expand a widget within a window?
- Date: Fri, 15 Sep 2006 10:54:51 -0500
On Fri, 15 Sep 2006 09:19:48 -0500, Jonathon Jongsma
<jonathon jongsma gmail com> wrote:
On 9/15/06, Samvel <ksamvel gmail com> wrote:
On Fri, 15 Sep 2006 01:46:43 -0500, Murray Cumming <murrayc murrayc com>
wrote:
>
>> However you add widgets to show they are properly and nicely packed
in a
>> window. But they are not affected as soon as you start resizing
Window.
>> The
>> only remedy I've found is to connect method to signal_check_resize()
of
>> the
>> main window:
>
> Widgets should automatically expand to fill available space, when you
> have
> specified that. You should, for instance, investigate the
> Gtk::Box::pack()
> parameters.
I do not agree. Gtk::Box::pack() parameters work only for initial
packing.
Once you change window size nothing happens to widgets. They are left in
exactly the same layout. In order to solve this resize_children() should
be called while or after resizing.
I'm not quite sure what you're talking about. My widgets always
resize with the window if I pack them with the right options, and I've
never called resize_children() in my life. Maybe you could post a
stripped down example to show when this happens for you.
Ok, here is my code:
-----------------------------------------------------------
PBrowser.hpp
#ifndef PB_BROWSER_INTERFACE
#define PB_BROWSER_INTERFACE
#include <glibmm/refptr.h>
#include <gtkmm/box.h>
#include <gtkmm/image.h>
#include <gtkmm/frame.h>
#include <gtkmm/window.h>
#include <gtkmm/button.h>
namespace PB {
class PBrowser: public Gtk::Window {
public:
PBrowser();
virtual ~PBrowser() {}
private:
void on_clicked_full_screen();
const int _nXPad,
_nYPad;
bool _bFullScreen;
int _nXPos, _nYPos,
_nHeight, _nWidth;
double _dImgAspectRatio;
Gtk::VBox _oBoxMain;
Gtk::Image _oImage;
Gtk::Button _oButton;
Gtk::Frame _oFrame;
Glib::RefPtr<Gdk::Pixbuf> _oPixBuf;
};
};
#endif // PB_BROWSER_INTERFACE
---------------------------------------------------------------------
---------------------------------------------------------------------
PBrowser.cpp
#include <iostream>
#include <glibmm/refptr.h>
#include <gdkmm/pixbuf.h>
#include <gtkmm/main.h>
#include "../PBrowser.hpp"
PB::PBrowser::PBrowser():
_nXPad( 10), _nYPad( 10),
_bFullScreen( false),
_oBoxMain( false),
_oButton( "Full Screen"),
_oFrame( "./1.jpg") {
set_border_width( 10);
set_default_size( 700, 500);
//Glib::RefPtr<Gdk::Pixbuf> oPixBuf =
Gdk::Pixbuf::create_from_file( "./1.jpg");
_oPixBuf = Gdk::Pixbuf::create_from_file( "./1.jpg");
_dImgAspectRatio = static_cast<double>( _oPixBuf->get_width()) /
_oPixBuf->get_height();
_oImage.set_alignment( 0.5, 0.5);
_oImage.set( _oPixBuf->scale_simple( 640, 480, Gdk::INTERP_NEAREST));
_oImage.set_padding( _nXPad, _nYPad);
//_oFrame.add( _oImage);
_oBoxMain.pack_start( _oFrame, Gtk::PACK_EXPAND_WIDGET);
_oBoxMain.pack_start( _oButton, Gtk::PACK_SHRINK);
_oButton.signal_clicked().connect( sigc::mem_fun( *this,
&PBrowser::on_clicked_full_screen));
add( _oBoxMain);
show_all_children();
}
void PB::PBrowser::on_clicked_full_screen() {
_oImage.hide();
int nWidth, nHeight, nXPos, nYPos;
if( _bFullScreen) {
nXPos = _nXPos;
nYPos = _nYPos;
nWidth = _nWidth;
nHeight = _nHeight;
} else {
nXPos = 0;
nYPos = 0;
nWidth = gdk_screen_width();
nHeight = gdk_screen_height();
// Save old window geometry
get_position( _nXPos, _nYPos);
_nHeight = get_height();
_nWidth = get_width();
}
set_size_request( -1, -1);
while( Gtk::Main::events_pending()){
// Processing pending events
Gtk::Main::iteration( false);
}
set_size_request( 1, 1);
get_window()->resize( nWidth, nHeight);
move( nXPos, nYPos);
while(Gtk::Main::events_pending()){
// Processing pending events
Gtk::Main::iteration(false);
}
std::cout << "Resize: "
<< nWidth << 'x' << nHeight << std::endl;
std::cout << "Frame : "
<< _oFrame.get_width() << 'x'
<< _oFrame.get_height() << std::endl;
{
std::cout << "AspRet: " << _dImgAspectRatio << std::endl;
int nDstWidth = _oFrame.get_width() - _nXPad * 2;
int nDstHeight = _oFrame.get_height() - _nYPad * 2;
int nTmpWidth = static_cast<int>( nDstHeight * _dImgAspectRatio);
int nTmpHeight = static_cast<int>( 1.0 / _dImgAspectRatio * nDstWidth);
std::cout << "Destin: " << nDstWidth << 'x' << nDstHeight << std::endl;
if( nTmpWidth > nDstWidth) {
// Use nTmpHeight: scale by Width
std::cout << "Pic : " << nDstWidth
<< 'x' << nTmpHeight
<< "\t[TW>DW]" << std::endl;
_oImage.set( _oPixBuf->scale_simple( nDstWidth, nTmpHeight,
Gdk::INTERP_BILINEAR));
} else {
// Use nTmpWidth
std::cout << "Pic : " << nTmpWidth
<< 'x' << nDstHeight
<< "\t[TW<=DW]" << std::endl;
_oImage.set( _oPixBuf->scale_simple( nTmpWidth, nDstHeight,
Gdk::INTERP_BILINEAR));
}
}
std::cout << std::endl;
_bFullScreen = !_bFullScreen;
while(Gtk::Main::events_pending()){
// Processing pending events
Gtk::Main::iteration(false);
}
_oImage.show();
}
---------------------------------------------------------------------
*I have commented packing _oImage into Frame in order to see how Frame is
resized.
Simple window with one button and frame in it. Just copy code into a text
editor, save and compile. Run and push button one time and one more. Now
take a look at output in terminal. It should look something like:
Resize: 1400x1050
Frame : 680x451
AspRet: 1.25
Destin: 660x431
Pic : 538x431 [TW<=DW]
Resize: 700x500
Frame : 1374x927
AspRet: 1.25
Destin: 1354x907
Pic : 1133x907 [TW<=DW]
Pay attention on 'Frame' and 'Resize' lines.
'Resize' is the size of resized window itself.
'Frame' should be a new size of Frame after resize() call.
BUT!!! it is not updated. Why? That is the reason my Picture is not
resized correctly and that is what all this talk about. I've already put
loops to workout pending event, tried different things like explicit
resize_children() call... Nothing helps.
Any ideas?
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]