Bazaar: AutoScroller now uses always single inclued.

git-svn-id: svn://ultimatepp.org/upp/trunk@15202 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
klugier 2020-10-04 20:25:02 +00:00
parent 756c25a822
commit a6bda7eb9f
6 changed files with 91 additions and 92 deletions

View file

@ -1,38 +1,50 @@
#ifndef _AutoScroller_AutoScroller_h_
#define _AutoScroller_AutoScroller_h_
#ifndef _AutoScroller_AutoScroller_hpp_
#define _AutoScroller_AutoScroller_hpp_
#include <CtrlLib/CtrlLib.h>
#include "AutoScrollerParentCtrl.h"
namespace Upp
{
template<class C = ParentCtrl>
class AutoScroller : public C
template<class C>
AutoScroller<C>::AutoScroller()
{
public:
using CLASSNAME = AutoScroller<C>;
AutoScroller();
public:
virtual void Layout();
void EnableScroll(bool b = true);
void DisableScroll() { EnableScroll(false); }
bool IsEnabledScroll() const { return scroll.x.IsEnabled() || scroll.y.IsEnabled(); }
C::AddFrame(scroll);
scroll.AutoHide();
scroll.WhenScroll = THISBACK(OnScroll);
}
void AddPane(Ctrl& c) { ClearPane(); pane = &c; C::Add(c); }
Ctrl* GetPane() const { return pane; }
inline bool HasPane() const { return (~pane != NULL); }
void ClearPane() { if(! ~pane) return; pane->Remove(); pane = NULL; }
template<class C>
void AutoScroller<C>::Scroll(const Point& p)
{
if(!HasPane()) return;
Rect _r = pane->GetRect();
Rect r(-p, _r.GetSize());
pane->SetRect(r);
WhenScrolled();
}
void Scroll(const Point& p);
void OnScroll();
template<class C>
void AutoScroller<C>::OnScroll()
{
Scroll(scroll.Get());
}
Callback WhenScrolled;
ScrollBars scroll;
template<class C>
void AutoScroller<C>::Layout()
{
Size psz = C::GetSize();
scroll.SetPage(psz);
if(!HasPane()) return;
Size tsz = pane->GetSize();
scroll.SetTotal(tsz);
}
protected:
Ptr<Ctrl> pane;
};
template<class C>
void AutoScroller<C>::EnableScroll(bool b)
{
scroll.x.Enable(b);
scroll.y.Enable(b);
}
}
#endif

View file

@ -1,50 +0,0 @@
#ifndef _AutoScroller_AutoScroller_hpp_
#define _AutoScroller_AutoScroller_hpp_
#include "AutoScroller.h"
namespace Upp
{
template<class C>
AutoScroller<C>::AutoScroller()
{
C::AddFrame(scroll);
scroll.AutoHide();
scroll.WhenScroll = THISBACK(OnScroll);
}
template<class C>
void AutoScroller<C>::Scroll(const Point& p)
{
if(!HasPane()) return;
Rect _r = pane->GetRect();
Rect r(-p, _r.GetSize());
pane->SetRect(r);
WhenScrolled();
}
template<class C>
void AutoScroller<C>::OnScroll()
{
Scroll(scroll.Get());
}
template<class C>
void AutoScroller<C>::Layout()
{
Size psz = C::GetSize();
scroll.SetPage(psz);
if(!HasPane()) return;
Size tsz = pane->GetSize();
scroll.SetTotal(tsz);
}
template<class C>
void AutoScroller<C>::EnableScroll(bool b)
{
scroll.x.Enable(b);
scroll.y.Enable(b);
}
}
#endif

View file

@ -5,6 +5,7 @@ uses
file
AutoScroller.h,
AutoScroller.hpp,
AutoScroller.cpp;
AutoScroller.cpp,
Specialisations readonly separator,
AutoScrollerParentCtrl.h;

View file

@ -0,0 +1,38 @@
#ifndef _AutoScroller_AutoScroller_h_
#define _AutoScroller_AutoScroller_h_
#include <CtrlLib/CtrlLib.h>
namespace Upp
{
template<class C = ParentCtrl>
class AutoScroller : public C
{
public:
using CLASSNAME = AutoScroller<C>;
AutoScroller();
public:
virtual void Layout() override;
void EnableScroll(bool b = true);
void DisableScroll() { EnableScroll(false); }
bool IsEnabledScroll() const { return scroll.x.IsEnabled() || scroll.y.IsEnabled(); }
void AddPane(Ctrl& c) { ClearPane(); pane = &c; C::Add(c); }
Ctrl* GetPane() const { return pane; }
inline bool HasPane() const { return (~pane != nullptr); }
void ClearPane() { if(! ~pane) return; pane->Remove(); pane = nullptr; }
void Scroll(const Point& p);
void OnScroll();
Callback WhenScrolled;
ScrollBars scroll;
protected:
Ptr<Ctrl> pane;
};
}
#endif

View file

@ -2,8 +2,9 @@
#define _AutoScrollerTest_AutoScrollerTest_h
#include <CtrlLib/CtrlLib.h>
#include <AutoScroller/AutoScroller.h>
using namespace Upp;
namespace Upp {
#define LAYOUTFILE <AutoScrollerTest/AutoScrollerTest.lay>
#include <CtrlCore/lay.h>
@ -11,21 +12,16 @@ using namespace Upp;
#define IMAGEFILE <AutoScrollerTest/AutoScrollerTest.iml>
#include <Draw/iml_header.h>
//if use only ParentCtrl as base
//#include <AutoScroller/AutoScroller.h>
//if use custom base
#include <AutoScroller/AutoScroller.hpp>
class AutoScrollerTest : public WithAutoScrollerTestLayout<TopWindow> {
public:
typedef AutoScrollerTest CLASSNAME;
AutoScrollerTest();
void Toggle();
AutoScroller<ParentCtrl> sc;
AutoScroller<ParentCtrl> sc;
WithTestLay<ParentCtrl> view;
};
#endif
}
#endif

View file

@ -1,5 +1,7 @@
#include "AutoScrollerTest.h"
using namespace Upp;
#define IMAGEFILE <AutoScrollerTest/AutoScrollerTest.iml>
#include <Draw/iml_source.h>
@ -17,13 +19,13 @@ AutoScrollerTest::AutoScrollerTest()
sc.EnableScroll();
Add(sc.SizePos());
CtrlLayout(view); //will determine desired size of pane
sc.AddPane(view); //size remains as specified, if view changes size, sc.Layout() needs to be called.
//if sc changes its size, it recalculates the scroll bars automatically
CtrlLayout(view); // will determine desired size of pane
sc.AddPane(view); // size remains as specified, if view changes size, sc.Layout() needs to be called.
// if sc changes its size, it recalculates the scroll bars automatically
//sc.WhenScrolled = THISBACK(); //after scrolling events
//sc.WhenScrolled = [=] {}; //after scrolling events
view.tg <<= THISBACK(Toggle);
view.tg << [=] { Toggle(); };
view.doc0 <<= "doc0";
view.doc1 <<= "doc1";