Home » Community » Newbie corner » Attempting to get a canvas to display...
Attempting to get a canvas to display... [message #47753] |
Sun, 19 March 2017 03:44  |
ptkacz
Messages: 89 Registered: March 2017
|
Member |
|
|
Hi All,
I'm attempting to create a simple application in order to begin learn how to make use of U++. The application consists of two panels, on the left, a button panel with three buttons labeled 'A', 'B', 'C', on the right, a canvas. Selection of any of the buttons is to result in some text displaying on the canvas. Unfortunately, the canvas does not display. Could some one please point out what needs to be done? Code an layout are listed below.
Peter
UppApp.lay:
==========================================
LAYOUT(UppAppLayout, 364, 192)
END_LAYOUT
LAYOUT(ButtonLayout, 80, 84)
ITEM(Button, aBtn, SetLabel(t_("A")).LeftPosZ(12, 56).TopPosZ(8, 15))
ITEM(Button, bBtn, SetLabel(t_("B")).LeftPosZ(12, 56).TopPosZ(32, 15))
ITEM(Button, cBtn, SetLabel(t_("C")).LeftPosZ(12, 56).TopPosZ(56, 15))
END_LAYOUT
DrawCanvas.h:
==========================================
#ifndef _UppApp_DrawCanvas_h_
#define _UppApp_DrawCanvas_h_
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class DrawCanvas : public ParentCtrl {
typedef DrawCanvas CLASSNAME;
public:
DrawCanvas();
virtual void Paint(Draw& d);
void displayMessage(String s);
private:
String stringToDisplay = "Not Yet!";
};
#endif
DrawCanvas.cpp:
==========================================
#include "UppApp.h"
#include "DrawCanvas.h"
DrawCanvas::DrawCanvas() {
}
void DrawCanvas::Paint(Draw& d) {
Size(500, 500);
d.DrawRect(GetSize(), SWhite);
d.DrawText(5, 5, stringToDisplay, Arial(48), Black);
}
void DrawCanvas::displayMessage(String s) {
stringToDisplay = s;
Refresh();
}
UppApp.h:
==========================================
#ifndef _UppApp_UppApp_h
#define _UppApp_UppApp_h
#include <CtrlLib/CtrlLib.h>
#include <Painter/Painter.h>
#include "DrawCanvas.h"
using namespace Upp;
#define LAYOUTFILE <UppApp/UppApp.lay>
#include <CtrlCore/lay.h>
class UppApp : public WithUppAppLayout<TopWindow> {
public:
typedef UppApp CLASSNAME;
UppApp();
void displayMessage(String s);
private:
DrawCanvas canvas;
WithButtonLayout<ParentCtrl> buttonPanel;
};
#endif
main.cpp:
==========================================
#include "UppApp.h"
UppApp::UppApp()
{
CtrlLayout(*this, "UppApp");
CtrlLayout(buttonPanel);
buttonPanel.aBtn << THISBACK1(displayMessage, "A");
buttonPanel.bBtn << THISBACK1(displayMessage, "B");
buttonPanel.cBtn << THISBACK1(displayMessage, "C");
Add(buttonPanel);
Add(canvas);
BackPaint();
}
void UppApp::displayMessage(String s) {
canvas.displayMessage(s);
}
GUI_APP_MAIN
{
UppApp uppApp;
uppApp.Run();
}
|
|
|
Re: Attempting to get a canvas to display... [message #47757 is a reply to message #47753] |
Sun, 19 March 2017 19:24   |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
Hi,
You do not specify the size of canvas.
UppApp::UppApp()
{
CtrlLayout ( *this, "UppApp" );
canvas.SetRect(100,0, 500, 500 ); // <---- setting the canvas size here
CtrlLayout ( buttonPanel );
buttonPanel.aBtn << THISBACK1 ( displayMessage, "A" );
buttonPanel.bBtn << THISBACK1 ( displayMessage, "B" );
buttonPanel.cBtn << THISBACK1 ( displayMessage, "C" );
Add ( buttonPanel );
Add ( canvas );
BackPaint();
}
regards
omari.
|
|
|
|
Re: Attempting to get a canvas to display... [message #47762 is a reply to message #47761] |
Mon, 20 March 2017 22:59   |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
the canvas overwrites the displayed layout because both are in the same frame.
if you want separate them, you can use Splitter:
class UppApp : public WithUppAppLayout<TopWindow>
{
public:
typedef UppApp CLASSNAME;
UppApp();
void displayMessage ( String s );
private:
DrawCanvas canvas;
WithButtonLayout<ParentCtrl> buttonPanel;
Splitter splitter; // <-------------------------
};
UppApp::UppApp()
{
CtrlLayout ( *this, "UppApp" );
CtrlLayout ( buttonPanel );
buttonPanel.aBtn << THISBACK1 ( displayMessage, "A" );
buttonPanel.bBtn << THISBACK1 ( displayMessage, "B" );
buttonPanel.cBtn << THISBACK1 ( displayMessage, "C" );
Add(splitter); // <-------------------------
splitter.Horz(buttonPanel,canvas); // <-------------------------
BackPaint();
}
for more information, you can try this examples :
SplitterFrame
Splitter
Frame
regards
omari.
|
|
|
|
Goto Forum:
Current Time: Mon Apr 28 01:02:03 CEST 2025
Total time taken to generate the page: 0.07339 seconds
|