Menu

#93 CSplitterImpl::GetSplitterPosPct() requested.

closed-fixed
None
5
2015-10-10
2015-09-28
Anonymous
No

Hi

I have a suggestion for a new function:

The CSplitterImpl in atlsplit.h contains some functions for setting and retrieving the splitter position;
bool SetSplitterPos(int xyPos = -1, bool bUpdate = true);
int GetSplitterPos() const;
void SetSplitterPosPct(int nPct, bool bUpdate = true);
But GetSplitterPosPct() is missing.

SetSplitterPosPct() and GetSplitterPosPct() is useful when making the layout persistent. We don’t have to save absolute values, only percentages (not affected by change in screen resolution).

Perhaps it can be implemented like this:
int GetSplitterPosPct() const
{
int cxyTotal = m_bVertical ? (m_rcSplitter.right - m_rcSplitter.left - m_cxySplitBar - m_cxyBarEdge) : (m_rcSplitter.bottom - m_rcSplitter.top - m_cxySplitBar - m_cxyBarEdge);
return (cxyTotal > 0 && m_xySplitterPos >= 0) ? ::MulDiv(m_xySplitterPos, m_nPropMax, cxyTotal) / 100 : -1;
}

Thanks for WTL
Ottar Arne

Discussion

  • Nenad Stefanovic

    • assigned_to: Nenad Stefanovic
     
  • Nenad Stefanovic

    • status: open --> closed-fixed
     
  • Nenad Stefanovic

    Added as proposed, thanks.

    atlsplit.h, rev. 626

     
  • Jim Barry

    Jim Barry - 2015-10-06

    Hi Nenad - please could we have the percentage represented as a double? Otherwise, the splitter position can not be accurately saved, and is liable to gradually shift over time due to rounding.

     
  • Nenad Stefanovic

     
  • Nenad Stefanovic

    Hi Jim,

    Percentage is not saved, just used to set position and calculated to get current value. That is why get method was not there before.

    On the other hand, proportional position is based to max value of 10000. That still holds as being bigger than any screen resolution. Since there is no guarantee, it will be increased in the next version.

    Cheers,
    Nenad

     
  • Jim Barry

    Jim Barry - 2015-10-09

    I meant that GetSplitterPosPct should return a double for the user code to pass back to SetSplitterPosPct at a later time, otherwise the position may not be accurately restored. And for the internal representation (m_nProportionalPos), what reason is there not to use floating point?

     
  • Nenad Stefanovic

    Percentage is a percentage, it is not meant to be used for precise settings. Just an easy way to specify something like "half", "third", "three quarters", etc.

    Floating point can be used, but sufficiently large int is enough. They both can have rounding problems, but if the values are much larger than pixel count, they won't propagate. Either way - next version.

    Cheers,
    Nenad

     

Anonymous
Anonymous

Add attachments
Cancel