Skip to main content
Inspiring
July 4, 2014
Answered

How to keeps button in center of resizable dialog/panel?

  • July 4, 2014
  • 1 reply
  • 401 views

Hi all,

Is there any ways to make a button still in center of dialog/panel when I resize dialog/panel without changes its frame size?

I'm using kBindAll but the button will be changed frame size. Can anybody please help me resolve that?

My attribute of button:

ButtonWidget

  (

  kAMPBrowseBtWidgetID,

  kSysButtonPMRsrcId, // The Plugin ID

  kBindAll, // Frame binding

  Frame(64,220,200,246) // Frame(4,4,265,320) // Frame

  kTrue, // Is this visible

  kTrue, // Is this enabled

  "Browse Pages", // The String value

  ),

This topic has been closed for replies.
Correct answer LizW

Hi,

I couldn't get it to work using the binding.

There may be a better way of doing it, but I got it working by setting to kBindNone and moving the button on panel resize events:

Firstly, make sure you have a custom class for your panel's control view.

Mark it up in the fr file for the panel's widget boss class with:

IID_ICONTROLVIEW, kMyPanelViewImpl,

Add to the ID definitions, factory list etc and set up a MyPanelView class (or whatever you want to call it...), derived from PanelView, for this implementation

Then in your MyPanelView class, setup the Resize function as below:

void MyPanelView::Resize(const PMPoint& dimensions, bool16 invalidate)

{

    PanelView::Resize(dimensions, invalidate);

    InterfacePtr<IPanelControlData> panelData(Utils<IPalettePanelUtils>()->QueryPanelByWidgetID(kMyPanelWidgetID));

    if(panelData == nil) return;

    IControlView *myWidget = panelData->FindWidget(kMyButtonWidgetID);

    if (myWidget == nil) return;

    PMRect theFrame = myWidget->GetFrame();

    PMReal left = (dimensions.X() - theFrame.Width()) / 2;

    PMReal right = left + theFrame.Width();

    theFrame.Left(left);

    theFrame.Right(right);

    myWidget->SetFrame(theFrame, kTrue);

}

You will need these includes:

#include "Utils.h"

#include "IPalettePanelUtils.h"


Hope that helps

1 reply

LizWCorrect answer
Inspiring
July 15, 2014

Hi,

I couldn't get it to work using the binding.

There may be a better way of doing it, but I got it working by setting to kBindNone and moving the button on panel resize events:

Firstly, make sure you have a custom class for your panel's control view.

Mark it up in the fr file for the panel's widget boss class with:

IID_ICONTROLVIEW, kMyPanelViewImpl,

Add to the ID definitions, factory list etc and set up a MyPanelView class (or whatever you want to call it...), derived from PanelView, for this implementation

Then in your MyPanelView class, setup the Resize function as below:

void MyPanelView::Resize(const PMPoint& dimensions, bool16 invalidate)

{

    PanelView::Resize(dimensions, invalidate);

    InterfacePtr<IPanelControlData> panelData(Utils<IPalettePanelUtils>()->QueryPanelByWidgetID(kMyPanelWidgetID));

    if(panelData == nil) return;

    IControlView *myWidget = panelData->FindWidget(kMyButtonWidgetID);

    if (myWidget == nil) return;

    PMRect theFrame = myWidget->GetFrame();

    PMReal left = (dimensions.X() - theFrame.Width()) / 2;

    PMReal right = left + theFrame.Width();

    theFrame.Left(left);

    theFrame.Right(right);

    myWidget->SetFrame(theFrame, kTrue);

}

You will need these includes:

#include "Utils.h"

#include "IPalettePanelUtils.h"


Hope that helps

toan minhAuthor
Inspiring
July 16, 2014

Hi LizW,

I did and it worked fine. Thanks you so much for your help. You save my life