Hey,

2011/5/27 Graeme Gill <[email protected]>:
>        I'm trying to come to grips with layout using Wt, but it
> is all a bit maddening.

See the attached modified test case with the following diff:

--- /home/koen/Downloads/hello.C        2011-06-16 13:29:13.000000000 +0200
+++ test168.cc  2011-06-16 13:28:06.000000000 +0200
@@ -49,8 +49,6 @@
        root()->setLayout(m_layout);

        // Make it scroll if the text overflows
-       root()->setOverflow(Wt::WContainerWidget::OverflowAuto);
-
        // The left hand vertical graphic strip
        m_vstrip = new WContainerWidget();
        m_vstrip->decorationStyle().setBackgroundImage("vstrip.jpg",
@@ -59,7 +57,6 @@
        // If we don't set a minimum size, the strip vanishes
        m_vstrip->setMinimumSize(Wt::WLength("40px"), Wt::WLength("1px"));

-       root()->addWidget(m_vstrip);
        m_layout->addWidget(m_vstrip, 0);       // Minimize strip width

        // Some text to the right of the graphical strip
@@ -150,8 +147,10 @@
                            "The quick brown fox jumps over the lazy dog"
                            "The quick brown fox jumps over the lazy dog"
                            "The last line ends here. xxxxxxxxxxxxxxxxxx");
-       root()->addWidget(m_body);
        m_layout->addWidget(m_body, 1); // Maximize text width
+
+       m_body->setStyleClass("text");
+       styleSheet().addRule(".text", "overflow: auto;");
 }

 WApplication *createApplication(const WEnvironment& env)

The following changes are related to the problem:
 - when setting a layout manager to a widget, you usually want that
layout manager to fit exactly in that widget and thus there is no need
to specify overflow for the container. In your case the contents of
the text was actually overflowing.
 - in this case, you want the text widget to overflow using a
scrollbar. This is accomplished with the style class and rule (which
could be in an external css file).

Some changes are not relevant to the problem:
 - there is no need to add the widgets to the container and the layout
manager -- just the layout manager will suffice

Regards,
koen
/*
 * Copyright (C) 2008 Emweb bvba, Heverlee, Belgium.
 *
 * See the LICENSE file for terms of use.
 */

#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WHBoxLayout>
#include <Wt/WVBoxLayout>
#include <Wt/WText>
#include <Wt/WImage>

// c++0x only, for std::bind
// #include <functional>

using namespace Wt;

/*
 * A simple hello world application class which demonstrates how to react
 * to events, read input, and give feed-back.
 */
class HelloApplication : public WApplication
{
public:
  HelloApplication(const WEnvironment& env);

private:
	
	WHBoxLayout *m_layout;		// Horizontal layout

	WContainerWidget *m_vstrip;	// Left vertical graphical strip

	WText  *m_body;				// Right body text
};

/*
 * The env argument contains information about the new session, and
 * the initial request. It must be passed to the WApplication
 * constructor so it is typically also an argument for your custom
 * application constructor.
*/
HelloApplication::HelloApplication(const WEnvironment& env)
  : WApplication(env)
{
	// Create the horizontal Layout
	m_layout = new WHBoxLayout();

	root()->setLayout(m_layout);

	// Make it scroll if the text overflows 
	// The left hand vertical graphic strip
	m_vstrip = new WContainerWidget();
	m_vstrip->decorationStyle().setBackgroundImage("vstrip.jpg",
                   Wt::WCssDecorationStyle::RepeatY);

	// If we don't set a minimum size, the strip vanishes
	m_vstrip->setMinimumSize(Wt::WLength("40px"), Wt::WLength("1px"));

	m_layout->addWidget(m_vstrip, 0);	// Minimize strip width

	// Some text to the right of the graphical strip
	m_body = new WText("The first line starts here. xxxxxxxxxxxxxxx"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The quick brown fox jumps over the lazy dog"
	                    "The last line ends here. xxxxxxxxxxxxxxxxxx");
	m_layout->addWidget(m_body, 1);	// Maximize text width

	m_body->setStyleClass("text");
	styleSheet().addRule(".text", "overflow: auto;");
}

WApplication *createApplication(const WEnvironment& env)
{
  /*
   * You could read information from the environment to decide whether
   * the user has permission to start a new application
   */
  return new HelloApplication(env);
}

int main(int argc, char **argv)
{
  /*
   * Your main method may set up some shared resources, but should then
   * start the server application (FastCGI or httpd) that starts listening
   * for requests, and handles all of the application life cycles.
   *
   * The last argument to WRun specifies the function that will instantiate
   * new application objects. That function is executed when a new user surfs
   * to the Wt application, and after the library has negotiated browser
   * support. The function should return a newly instantiated application
   * object.
   */
  return WRun(argc, argv, &createApplication);
}

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to