gravity for splitter window (patch 1046105)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30947 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
4116fac052
commit
14b4c0ff12
@ -31,6 +31,7 @@ All:
|
||||
|
||||
All (GUI):
|
||||
|
||||
- wxSplitterWindow now supports gravity parameter (Zbigniew Zagórski)
|
||||
- recursive wxSizer::GetItem returns item of given window, sizer or nth index
|
||||
- wxLayoutConstraints now use best size, not current size, for AsIs() condition
|
||||
- wxSizer::Add/Insert etc. now returns pointer to wxSizerItem just added and this
|
||||
|
@ -131,6 +131,16 @@ Returns the current minimum pane size (defaults to zero).
|
||||
|
||||
\helpref{wxSplitterWindow::SetMinimumPaneSize}{wxsplitterwindowsetminimumpanesize}
|
||||
|
||||
\membersection{wxSplitterWindow::GetSashGravity}\label{wxsplitterwindowgetsashgravity}
|
||||
|
||||
\func{double}{GetSashGravity}{\void}
|
||||
|
||||
Returns the current sash gravity.
|
||||
|
||||
\wxheading{See also}
|
||||
|
||||
\helpref{wxSplitterWindow::SetSashGravity}{wxsplitterwindowsetsashgravity}
|
||||
|
||||
\membersection{wxSplitterWindow::GetSashPosition}\label{wxsplitterwindowgetsashposition}
|
||||
|
||||
\func{int}{GetSashPosition}{\void}
|
||||
@ -269,6 +279,37 @@ may wish to do it yourself.
|
||||
\helpref{wxSplitterWindow::SplitVertically}{wxsplitterwindowsplitvertically}\\
|
||||
\helpref{wxSplitterWindow::SplitHorizontally}{wxsplitterwindowsplithorizontally}
|
||||
|
||||
\membersection{wxSplitterWindow::SetSashGravity}\label{wxsplitterwindowsetsashgravity}
|
||||
|
||||
\func{void}{SetSashGravity}{\param{double }{gravity}}
|
||||
|
||||
Sets the sash gravity.
|
||||
|
||||
\wxheading{Parameters}
|
||||
|
||||
\docparam{gravity}{The sash gravity. Value between 0.0 and 1.0.}
|
||||
|
||||
|
||||
\wxheading{Remarks}
|
||||
Gravity is real factor which controls position of sash while resizing wxSplitterWindow.
|
||||
Gravity tells wxSplitterWindow how much will left/top window grow while resizing.
|
||||
|
||||
Example values:
|
||||
\begin{itemize}\itemsep=0pt
|
||||
\item{ 0.0 - only the bottom/right window is automaticaly resized}
|
||||
\item{ 0.5 - both windows grow by equal size}
|
||||
\item{ 1.0 - only left/top window grows}
|
||||
\end{itemize}
|
||||
|
||||
Gravity should be real value betwwen 0.0 and 1.0.
|
||||
|
||||
Default value of sash gravity is 0.0. That value is compatible with previous
|
||||
(before gravity was introduced) behaviour of wxSplitterWindow.
|
||||
|
||||
\wxheading{See also}
|
||||
|
||||
\helpref{wxSplitterWindow::GetSashGravity}{wxsplitterwindowgetsashgravity}
|
||||
|
||||
\membersection{wxSplitterWindow::SetSashPosition}\label{wxsplitterwindowsetsashposition}
|
||||
|
||||
\func{void}{SetSashPosition}{\param{int }{position}, \param{const bool}{ redraw = true}}
|
||||
|
@ -155,6 +155,12 @@ public:
|
||||
// Gets the sash position
|
||||
int GetSashPosition() const { return m_sashPosition; }
|
||||
|
||||
// Set the sash gravity
|
||||
void SetSashGravity(double gravity);
|
||||
|
||||
// Gets the sash gravity
|
||||
double GetSashGravity() const { return m_sashGravity; }
|
||||
|
||||
// If this is zero, we can remove panes by dragging the sash.
|
||||
void SetMinimumPaneSize(int min);
|
||||
int GetMinimumPaneSize() const { return m_minimumPaneSize; }
|
||||
@ -271,6 +277,8 @@ protected:
|
||||
int m_oldX;
|
||||
int m_oldY;
|
||||
int m_sashPosition; // Number of pixels from left or top
|
||||
double m_sashGravity;
|
||||
wxSize m_lastSize;
|
||||
int m_requestedSashPosition;
|
||||
int m_sashPositionCurrent; // while dragging
|
||||
int m_firstX;
|
||||
|
@ -52,7 +52,8 @@ enum
|
||||
SPLIT_UNSPLIT,
|
||||
SPLIT_LIVE,
|
||||
SPLIT_SETPOSITION,
|
||||
SPLIT_SETMINSIZE
|
||||
SPLIT_SETMINSIZE,
|
||||
SPLIT_SETGRAVITY
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -82,6 +83,7 @@ public:
|
||||
void ToggleLive(wxCommandEvent& event);
|
||||
void SetPosition(wxCommandEvent& event);
|
||||
void SetMinSize(wxCommandEvent& event);
|
||||
void SetGravity(wxCommandEvent& event);
|
||||
|
||||
void Quit(wxCommandEvent& event);
|
||||
|
||||
@ -162,6 +164,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(SPLIT_LIVE, MyFrame::ToggleLive)
|
||||
EVT_MENU(SPLIT_SETPOSITION, MyFrame::SetPosition)
|
||||
EVT_MENU(SPLIT_SETMINSIZE, MyFrame::SetMinSize)
|
||||
EVT_MENU(SPLIT_SETGRAVITY, MyFrame::SetGravity)
|
||||
|
||||
EVT_MENU(SPLIT_QUIT, MyFrame::Quit)
|
||||
|
||||
@ -202,6 +205,9 @@ MyFrame::MyFrame()
|
||||
splitMenu->Append(SPLIT_SETMINSIZE,
|
||||
_T("Set &min size\tCtrl-M"),
|
||||
_T("Set minimum pane size"));
|
||||
splitMenu->Append(SPLIT_SETGRAVITY,
|
||||
_T("Set &gravity\tCtrl-G"),
|
||||
_T("Set gravity of sash"));
|
||||
splitMenu->AppendSeparator();
|
||||
|
||||
splitMenu->Append(SPLIT_QUIT, _T("E&xit\tAlt-X"), _T("Exit"));
|
||||
@ -214,6 +220,8 @@ MyFrame::MyFrame()
|
||||
menuBar->Check(SPLIT_LIVE, true);
|
||||
m_splitter = new MySplitterWindow(this);
|
||||
|
||||
m_splitter->SetSashGravity(1.0);
|
||||
|
||||
#if 1
|
||||
m_left = new MyCanvas(m_splitter, true);
|
||||
m_left->SetBackgroundColour(*wxRED);
|
||||
@ -330,6 +338,21 @@ void MyFrame::SetMinSize(wxCommandEvent& WXUNUSED(event) )
|
||||
SetStatusText(str, 1);
|
||||
#endif // wxUSE_STATUSBAR
|
||||
}
|
||||
void MyFrame::SetGravity(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
wxString str;
|
||||
str.Printf( wxT("%g"), m_splitter->GetSashGravity());
|
||||
str = wxGetTextFromUser(_T("Enter sash gravity (0,1):"), _T(""), str, this);
|
||||
if ( str.empty() )
|
||||
return;
|
||||
|
||||
double gravity = wxStrtod( str, (wxChar**)NULL);
|
||||
m_splitter->SetSashGravity(gravity);
|
||||
#if wxUSE_STATUSBAR
|
||||
str.Printf( wxT("Gravity = %g"), gravity);
|
||||
SetStatusText(str, 1);
|
||||
#endif // wxUSE_STATUSBAR
|
||||
}
|
||||
|
||||
// Update UI handlers
|
||||
|
||||
|
@ -117,6 +117,8 @@ void wxSplitterWindow::Init()
|
||||
m_firstX = 0;
|
||||
m_firstY = 0;
|
||||
m_sashPosition = m_requestedSashPosition = 0;
|
||||
m_sashGravity = 0.0;
|
||||
m_lastSize = wxSize(0,0);
|
||||
m_checkRequestedSashPosition = false;
|
||||
m_minimumPaneSize = 0;
|
||||
m_sashCursorWE = wxCursor(wxCURSOR_SIZEWE);
|
||||
@ -408,6 +410,8 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
|
||||
|
||||
if ( iconized )
|
||||
{
|
||||
m_lastSize = wxSize(0,0);
|
||||
|
||||
event.Skip();
|
||||
|
||||
return;
|
||||
@ -419,13 +423,36 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event)
|
||||
GetClientSize(&w, &h);
|
||||
|
||||
int size = m_splitMode == wxSPLIT_VERTICAL ? w : h;
|
||||
|
||||
int old_size = m_splitMode == wxSPLIT_VERTICAL ? m_lastSize.x : m_lastSize.y;
|
||||
if ( old_size != 0 )
|
||||
{
|
||||
int delta = (int) ( (size - old_size)*m_sashGravity );
|
||||
if ( delta != 0 )
|
||||
{
|
||||
int newPosition = m_sashPosition + delta;
|
||||
if( newPosition < m_minimumPaneSize )
|
||||
newPosition = m_minimumPaneSize;
|
||||
SetSashPositionAndNotify(newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_sashPosition >= size - 5 )
|
||||
SetSashPositionAndNotify(wxMax(10, size - 40));
|
||||
m_lastSize = wxSize(w,h);
|
||||
}
|
||||
|
||||
SizeWindows();
|
||||
}
|
||||
|
||||
void wxSplitterWindow::SetSashGravity(double gravity)
|
||||
{
|
||||
wxCHECK_RET( gravity >= 0. && gravity <= 1.,
|
||||
_T("invalid gravity value") );
|
||||
|
||||
m_sashGravity = gravity;
|
||||
}
|
||||
|
||||
bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
|
||||
{
|
||||
if ( m_windowTwo == NULL || m_sashPosition == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user