Duilib Study Notes (ii) Extended CScrollBar properties

Source: Internet
Author: User

Duilib Study Notes (ii) Extended CScrollBar properties

The default minimum value for the ScrollBar slider of the duilib is the height (HScrollbar) or width (vscrollbar) of the scroll bar. And this value defaults to 16. When using the system-style scroll bar, or Troy source code (Https://github.com/qdtroy/DuiLib_Ultimate) comes with the style, it is not a problem, because the two styles default height (width) is 16, when the slider is the smallest, there are 16* 16, background image (nine format) does not stretch the bug. However, when customizing the background picture, if the picture itself is larger than 16*16, a ghosting will occur, the scroll bar width is set to 12 in this figure, and the slider background image is 40*12. Corner= "0,6,0,24". Or the slider becomes very small, the scroll bar width is set to 12 in this figure, and the slider background image is 40*12. Corner= "0,6,0,6".

View source code can be found

M_rcthumb.top =Rc.top; M_rcthumb.bottom= Rc.top +m_cxyfixed.cy; if(M_nrange >0 ) {                    intCxthumb = cx * (rc.right-rc.left)/(M_nrange + rc.right-rc.left); if(Cxthumb < m_cxyfixed.cy) Cxthumb =m_cxyfixed.cy; M_rcthumb.left= M_nscrollpos * (cx-cxthumb)/M_nrange +M_rcbutton1.right; M_rcthumb.right= M_rcthumb.left +Cxthumb; if(M_rcthumb.right >m_rcbutton2.left) {M_rcthumb.left= M_rcbutton2.left-Cxthumb; M_rcthumb.right=M_rcbutton2.left; }                }                Else{m_rcthumb.left=M_rcbutton1.right; M_rcthumb.right=M_rcbutton2.left; }

, when the slider becomes very small, the source code simply sets the width of the slider to M_cxyfixed.cy, which is the scrollbar height (HScrollbar). Therefore, we can add an attribute thumbminsize to it, which is to set a slider minimum value to replace the m_cxyfixed.cy.

The specific code is as follows:

Header file UIScrollbar.h

protected : int m_nthumbminsize;  Public : int getthumbminsize (); void Setthumbminsize ();

Implementing File UIScrollbar.cpp

The constructor initializes a m_nthumbminsize value of Default_scrollbar_size, which is 16
Cscrollbarui::cscrollbarui (): ...
{
Default_scrollbar_size;
}
voidCscrollbarui::setattribute (LPCTSTR pstrname, LPCTSTR pstrvalue) {...//Source Code    Else if(_TCSICMP (Pstrname, _t ("thumbminsize")) ==0) setthumbminsize (_ttoi (Pstrvalue));}intcscrollbarui::getthumbminsize () {returnm_nthumbminsize;}voidCscrollbarui::setthumbminsize (intnSize) {M_nthumbminsize=nSize; Invalidate ();}voidCscrollbarui::setpos (RECT RC,BOOLbneedinvalidate) {...//Source CodeM_rcthumb.top =Rc.top; M_rcthumb.bottom= Rc.top +m_cxyfixed.cy; if(M_nrange >0 ) {        intCxthumb = cx * (rc.right-rc.left)/(M_nrange + rc.right-rc.left); /*There's a change here. The minimum slider value for the source setting is the height of the scrollbar (HScrollbar)*/        if(Cxthumb <m_nthumbminsize) {            if(M_nthumbminsize <m_cxyfixed.cy) {Cxthumb=m_cxyfixed.cy; }            ElseCxthumb=m_nthumbminsize; } m_rcthumb.left= M_nscrollpos * (cx-cxthumb)/M_nrange +M_rcbutton1.right; M_rcthumb.right= M_rcthumb.left +Cxthumb; if(M_rcthumb.right >m_rcbutton2.left) {M_rcthumb.left= M_rcbutton2.left-Cxthumb; M_rcthumb.right=M_rcbutton2.left; }} ...//Source Code//In addition, the following vertical scroll bar is the same}

Perfect realization!!!

Duilib Study Notes (ii) Extended CScrollBar properties

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.