CtrlLib: ArrayCtrl absolute mode visual issue fixed

This commit is contained in:
Mirek Fidler 2022-05-17 17:38:51 +02:00
parent 30801cf271
commit a5563f9322
7 changed files with 126 additions and 6 deletions

View file

@ -191,6 +191,26 @@ struct NullFrameClass : public CtrlFrame {
CtrlFrame& NullFrame();
class MarginFrame : public CtrlFrame {
public:
virtual void FrameLayout(Rect& r);
virtual void FramePaint(Draw& w, const Rect& r);
virtual void FrameAddSize(Size& sz);
virtual void FrameAdd(Ctrl& parent);
virtual void FrameRemove();
private:
Ctrl *owner;
Color color;
Rect margins;
public:
void SetMargins(const Rect& r);
void SetColor(Color c);
MarginFrame();
};
class BorderFrame : public CtrlFrame {
public:
virtual void FrameLayout(Rect& r);

View file

@ -146,6 +146,7 @@ void Ctrl::SyncLayout(int force)
Rect oview = GetView();
Rect view = GetRect().Size();
overpaint = OverPaint();
bool dolog = parent && !parent->GetParent() && parent->IsOpen();
for(int i = 0; i < frame.GetCount(); i++) {
Frame& f = frame[i];
f.frame->FrameLayout(view);

View file

@ -13,6 +13,62 @@ void NullFrameClass::FrameAddSize(Size& sz) {}
CtrlFrame& NullFrame() { return Single<NullFrameClass>(); }
void MarginFrame::FrameAdd(Ctrl& parent)
{
owner = &parent;
}
void MarginFrame::FrameRemove()
{
owner = NULL;
}
void MarginFrame::FrameLayout(Rect& r)
{
r.left += margins.left;
r.right -= margins.right;
r.top += margins.top;
r.bottom -= margins.bottom;
}
void MarginFrame::FramePaint(Draw& w, const Rect& r)
{
if(IsNull(color))
return;
w.DrawRect(r.left, r.top, r.Width(), margins.top, color);
w.DrawRect(r.left, r.bottom - margins.bottom, r.Width(), margins.bottom, color);
int h = r.GetHeight() - margins.top - margins.bottom;
w.DrawRect(r.left, r.top + margins.top, margins.left, h, color);
w.DrawRect(r.right - margins.right, r.top + margins.top, margins.right, h, color);
}
void MarginFrame::SetMargins(const Rect& r)
{
margins = r;
if(owner)
owner->RefreshLayout();
}
void MarginFrame::SetColor(Color c)
{
color = c;
if(owner)
owner->RefreshLayout();
}
void MarginFrame::FrameAddSize(Size& sz)
{
sz.cx += margins.left + margins.right;
sz.cy += margins.bottom + margins.top;
}
MarginFrame::MarginFrame()
{
margins = Rect(0, 0, 0, 0);
color = SColorFace();
owner = nullptr;
}
void BorderFrame::FrameLayout(Rect& r)
{
Size sz = r.GetSize();

View file

@ -1068,11 +1068,8 @@ void ArrayCtrl::HeaderScroll()
void ArrayCtrl::HeaderScrollVisibility()
{
scrollbox.Height(ScrollBarSize());
if(header.IsScroll())
sb.SetFrame(scrollbox);
else
sb.SetFrame(NullFrame());
scrollbox.SetMargins(Rect(0, 0, 0, header.IsScroll() ? ScrollBarSize() : 0));
scrollbox.SetColor(IsTransparent() ? Null : SColorFace());
}
void ArrayCtrl::RefreshRow(int i)
@ -3114,6 +3111,7 @@ ArrayCtrl::ArrayCtrl() {
Reset();
AddFrame(sb);
AddFrame(header);
sb.AddFrame(scrollbox);
header.WhenLayout = THISBACK(HeaderLayout);
header.WhenScroll = THISBACK(HeaderScroll);
sb.WhenScroll = THISBACK(Scroll);

View file

@ -200,7 +200,6 @@ private:
Vector<Ln> ln;
Vector< Vector<CellInfo> > cellinfo;
Vector<bool> modify;
FrameBottom<ParentCtrl> scrollbox;
Vector<int> column_width, column_pos;
DisplayPopup info;
const Order *columnsortsecondary;
@ -208,6 +207,7 @@ private:
int ctrl_low, ctrl_high;
int sorting_from;
Index<String> id_ndx;
MarginFrame scrollbox;
int keypos;
int cursor;

View file

@ -0,0 +1,9 @@
uses
CtrlLib;
file
main.cpp;
mainconfig
"" = "GUI";

View file

@ -0,0 +1,36 @@
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
struct MyApp : TopWindow {
ArrayCtrl a;
MarginFrame f;
virtual void Paint(Draw& w) {
w.DrawRect(GetSize(), LtBlue());
}
MyApp() {
for(int i = 0; i < 50; i++)
a.AddColumn("A", 100);
a.HeaderObject().Absolute();
for(int i = 0; i < 40; i++) {
a.Add("This is very very long line...");
a.Add("This is long line, but the next column is not empty", 12);
a.Add("Short line");
}
Sizeable();
Add(a.SizePos());
// a.Transparent();
a.SetFrame(f);
f.SetColor(LtGreen());
f.SetMargins(Rect(20, 50, 20, 10));
}
};
GUI_APP_MAIN
{
MyApp().Run();
}