TextDiffCtrl: Gutter area replaced with showing changes directly is ScrollBar

This commit is contained in:
Mirek Fidler 2023-01-14 19:35:41 +01:00
parent 0a26258c38
commit bb3f9b35cb
5 changed files with 77 additions and 106 deletions

View file

@ -4,7 +4,7 @@ set -e
# u:/ is set to be the home folder of account responsible for building
# wine and SDK is installed there...
wine c:/upp/umk u:/upp.src/uppbox,u:/upp.src/uppsrc MakeInstall6 c:/upp/CLANG.bm -ar u:/mku.exe
wine c:/upp/umk.exe u:/upp.src/uppbox,u:/upp.src/uppsrc MakeInstall6 c:/upp/CLANG.bm -ar u:/mku.exe
wine u:/mku.exe
#~/bin/upload

View file

@ -1,4 +1,6 @@
PREMULTIPLIED
IMAGE_ID(dot__UHD)
IMAGE_ID(dot)
IMAGE_ID(Next)
IMAGE_ID(Prev)
IMAGE_ID(Patched)
@ -10,44 +12,34 @@ IMAGE_ID(CopyLeft)
IMAGE_ID(CopyRight)
IMAGE_BEGIN_DATA
IMAGE_DATA(120,156,237,153,127,76,91,85,20,199,31,165,212,190,23,68,140,50,51,195,76,192,140,0,115,137,100,217,132,40,148,108)
IMAGE_DATA(97,146,50,22,38,118,100,154,110,106,173,78,252,9,99,102,195,65,43,6,209,185,110,115,181,102,18,2,110,198,95,232)
IMAGE_DATA(248,195,212,132,133,140,87,247,163,147,106,196,233,162,46,251,67,178,196,196,127,93,98,248,243,216,83,188,221,237,123,239)
IMAGE_DATA(190,247,238,43,76,18,251,77,78,250,184,247,124,206,61,247,222,211,147,182,196,138,133,98,97,169,213,115,113,55,236,137)
IMAGE_DATA(63,11,175,156,245,195,139,211,79,1,47,223,125,225,25,248,226,183,147,240,249,175,31,194,238,73,47,55,255,114,204,7)
IMAGE_DATA(159,254,50,10,31,95,30,1,223,87,59,184,249,206,169,93,240,209,229,97,56,241,243,113,240,142,183,115,243,254,232,227)
IMAGE_DATA(48,246,211,251,48,242,227,123,208,113,114,43,55,191,235,212,118,24,158,13,195,241,31,142,66,219,112,51,55,191,227,147)
IMAGE_DATA(54,136,124,127,24,194,223,189,3,238,99,27,185,249,246,81,55,188,155,56,8,135,103,134,96,211,193,135,184,249,45,145)
IMAGE_DATA(38,56,116,113,16,222,142,15,64,253,192,6,46,62,255,150,252,90,207,240,86,24,186,240,58,12,158,235,135,13,189,53)
IMAGE_DATA(166,249,138,150,178,73,215,64,221,252,11,167,252,48,112,182,15,130,223,244,66,219,177,22,168,244,223,59,95,242,192,29)
IMAGE_DATA(83,38,66,56,238,219,89,121,165,227,131,109,208,31,219,15,7,228,87,161,37,180,25,74,221,43,175,226,156,217,60,202)
IMAGE_DATA(90,87,205,182,30,105,6,247,161,38,88,185,105,197,37,179,28,173,187,234,75,206,175,168,191,115,198,10,107,90,55,163)
IMAGE_DATA(25,160,30,27,217,54,179,61,210,122,222,10,235,61,209,126,233,173,68,63,12,126,251,26,60,26,105,153,53,203,217,236)
IMAGE_DATA(54,199,147,159,117,92,29,74,28,72,55,131,190,216,158,100,65,52,95,177,229,231,25,94,230,35,71,220,83,157,167,119)
IMAGE_DATA(206,191,17,223,159,110,6,111,158,235,3,207,232,150,249,7,187,215,79,154,205,131,110,6,254,47,189,112,123,249,109,181)
IMAGE_DATA(102,89,212,255,185,25,160,54,135,92,150,154,1,145,107,176,46,221,12,238,239,94,195,205,215,245,173,75,55,131,53,207)
IMAGE_DATA(87,112,243,235,246,174,133,222,51,61,176,239,76,55,84,248,203,185,249,181,47,85,66,213,115,171,97,245,211,101,80,254)
IMAGE_DATA(196,61,220,188,89,197,110,86,51,48,84,145,80,106,153,173,22,60,73,154,235,13,150,193,62,44,132,44,179,93,194,53)
IMAGE_DATA(75,185,35,27,20,32,245,106,149,245,8,227,25,227,69,169,83,232,210,205,135,176,104,90,126,100,94,235,76,104,22,215)
IMAGE_DATA(97,9,89,244,193,179,33,126,52,235,19,226,134,123,68,150,248,211,207,104,102,238,26,125,104,134,24,207,93,99,238,52)
IMAGE_DATA(139,121,240,10,247,202,147,183,82,120,71,184,174,242,174,121,132,103,111,162,70,53,155,65,177,36,253,89,88,88,8,102)
IMAGE_DATA(12,125,149,188,211,233,28,247,58,157,144,108,97,186,134,62,232,171,228,11,10,10,186,48,182,17,143,62,232,171,228,243)
IMAGE_DATA(242,242,74,113,110,194,110,103,178,56,135,62,232,171,117,48,162,40,198,245,246,128,115,232,195,58,88,135,195,17,90,37)
IMAGE_DATA(73,127,179,120,156,67,31,22,111,179,217,106,49,191,25,155,77,197,226,24,206,161,15,139,71,221,42,73,127,236,115,56)
IMAGE_DATA(84,60,142,225,156,30,139,194,187,89,47,138,215,149,60,142,105,221,155,82,118,187,221,67,238,129,54,28,195,57,35,158)
IMAGE_DATA(236,65,89,115,102,114,95,44,97,125,148,139,226,239,100,109,124,102,213,140,150,238,150,164,235,27,69,49,189,119,124,198)
IMAGE_DATA(49,179,60,174,73,223,33,62,227,152,89,158,220,1,109,204,179,95,54,159,12,22,4,250,22,52,48,1,230,230,230,52)
IMAGE_DATA(141,240,161,163,178,166,45,5,79,255,77,243,248,108,196,107,197,162,215,87,198,160,121,227,115,188,97,75,177,254,98,236)
IMAGE_DATA(95,189,54,251,252,111,212,134,154,199,177,88,44,198,228,113,252,235,211,127,49,243,71,150,197,19,150,230,179,172,223,255)
IMAGE_DATA(86,139,217,12,170,171,171,61,209,104,20,100,89,134,112,56,124,77,146,164,18,30,222,229,114,5,100,57,0,211,211,211)
IMAGE_DATA(169,24,196,162,209,189,128,177,141,248,198,198,198,0,64,15,36,91,104,134,37,18,2,224,92,210,5,99,192,191,175,12)
IMAGE_DATA(62,160,226,101,57,205,211,151,171,138,177,192,119,234,241,244,250,170,24,184,199,177,49,55,4,131,141,25,22,8,52,105)
IMAGE_DATA(237,95,119,47,38,69,98,40,197,42,76,163,130,167,253,180,242,50,104,182,170,188,148,49,82,190,53,53,53,224,243,249)
IMAGE_DATA(96,98,98,130,197,43,99,164,95,209,215,237,118,67,36,18,73,153,14,79,199,72,27,89,159,102,131,193,32,139,87,229)
IMAGE_DATA(65,214,167,89,157,245,117,207,143,176,60,188,174,229,154,129,146,207,53,3,198,24,75,44,94,149,87,85,85,85,70,125)
IMAGE_DATA(36,191,102,177,234,67,115,111,13,13,13,204,250,192,216,58,49,82,175,88,95,172,250,192,57,157,60,82,182,192,107,215)
IMAGE_DATA(7,131,207,200,99,129,215,174,15,29,62,227,252,88,245,161,177,127,126,45,179,175,9,203,72,69,201,239,133,93,252,63)
IMAGE_DATA(24,101,176,86,62,250,209,172,21,222,23,55,254,56,170,247,241,52,219,245,149,49,172,42,155,243,207,201,146,114,205,192)
IMAGE_DATA(170,176,80,139,172,255,7,36,245,70,201,38,6,121,179,106,197,224,109,6,62,227,95,247,185,214,55,203,103,179,255,108)
IMAGE_DATA(207,63,39,165,254,1,150,204,17,73,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
IMAGE_END_DATA(1280, 9)
IMAGE_DATA(120,156,237,153,191,107,219,64,20,199,21,99,27,235,72,77,150,82,40,46,134,110,246,150,161,224,41,54,133,210,226,93)
IMAGE_DATA(99,201,224,173,155,161,133,110,214,63,96,40,132,204,222,51,120,114,135,46,145,167,64,51,102,205,208,16,40,116,109,160)
IMAGE_DATA(243,85,95,73,103,159,78,247,67,210,57,212,80,189,240,176,124,239,125,222,123,119,247,116,72,206,59,226,16,71,34,195)
IMAGE_DATA(80,131,80,105,162,139,80,187,130,207,41,108,131,129,67,231,243,88,113,157,248,159,38,62,96,168,231,57,148,210,180,98)
IMAGE_DATA(44,241,69,174,133,204,71,240,141,234,65,30,149,31,108,172,230,156,126,65,142,188,139,164,70,211,60,186,5,214,133,73)
IMAGE_DATA(55,137,191,169,39,201,21,75,35,252,227,228,89,168,183,73,194,155,228,251,205,253,125,92,8,62,153,93,82,224,173,224)
IMAGE_DATA(183,225,153,29,223,215,71,206,145,172,27,42,41,47,158,179,221,221,60,234,73,99,116,66,27,54,78,246,135,241,142,146)
IMAGE_DATA(213,199,200,199,202,99,20,99,211,49,174,74,177,219,24,234,181,202,43,29,11,246,191,144,234,48,200,47,54,205,100,211)
IMAGE_DATA(204,54,55,147,205,205,108,115,152,216,28,102,187,56,76,43,41,33,251,115,24,180,45,110,182,126,212,124,131,210,236,91)
IMAGE_DATA(103,94,154,157,134,173,93,166,118,176,126,216,204,253,18,205,204,88,207,185,72,141,183,163,85,152,106,235,97,44,84,230)
IMAGE_DATA(199,236,178,53,225,89,228,81,9,88,248,96,109,152,31,207,78,194,163,205,36,96,153,63,127,237,71,7,137,121,175,225)
IMAGE_DATA(195,51,76,139,236,53,106,231,89,212,81,84,48,215,34,117,139,130,61,66,94,113,175,139,8,214,62,71,143,74,15,131)
IMAGE_DATA(35,66,126,29,30,30,210,60,10,95,145,111,181,90,23,239,91,173,240,21,197,209,42,124,224,43,242,141,70,99,138,216)
IMAGE_DATA(38,30,62,240,21,249,131,131,131,14,108,203,122,93,201,194,6,31,248,202,22,198,117,221,43,221,28,96,131,143,106,97)
IMAGE_DATA(155,205,230,252,5,33,127,84,60,108,240,81,241,181,90,109,128,250,190,215,106,25,22,99,176,193,71,197,67,158,16,242)
IMAGE_DATA(243,115,179,153,225,49,6,155,142,133,96,111,94,185,238,131,200,99,76,182,111,162,212,235,117,143,237,3,175,24,131,205)
IMAGE_DATA(196,179,57,136,61,151,167,246,93,9,250,227,165,235,254,96,185,113,173,234,25,153,60,39,228,225,181,235,110,230,142,107)
IMAGE_DATA(140,229,229,145,147,223,67,92,99,44,47,207,246,128,87,229,218,239,205,147,65,44,134,71,66,223,160,14,189,187,187,147)
IMAGE_DATA(42,227,231,95,2,169,62,6,207,127,231,121,92,155,120,89,44,62,191,24,131,231,205,235,184,213,199,200,191,139,249,103)
IMAGE_DATA(115,171,215,127,219,27,89,30,99,235,245,90,201,99,252,235,183,223,202,250,193,170,120,198,242,188,101,255,254,91,217,229)
IMAGE_DATA(97,208,239,247,189,213,106,69,131,32,160,103,103,103,247,132,144,167,69,248,225,112,56,11,130,25,189,188,188,140,98,48)
IMAGE_DATA(93,173,62,81,196,54,241,163,209,104,70,233,199,204,79,190,215,215,14,133,205,49,188,187,199,252,44,195,7,193,134,231)
IMAGE_DATA(55,55,19,35,230,63,232,120,62,127,38,6,230,184,88,140,169,239,143,82,58,155,189,145,205,127,23,63,170,177,24,162)
IMAGE_DATA(168,26,211,212,240,188,159,172,46,195,97,155,169,75,140,17,249,30,31,31,211,201,100,66,151,203,165,138,23,99,108,62)
IMAGE_DATA(225,59,30,143,233,249,249,121,164,26,158,143,177,81,150,159,103,125,223,87,241,153,58,88,126,158,213,228,215,174,31,99)
IMAGE_DATA(139,240,90,173,14,3,145,175,14,3,197,152,74,84,124,166,174,94,175,151,234,143,240,53,75,213,31,210,185,157,156,156)
IMAGE_DATA(40,251,3,177,53,49,162,79,244,151,170,63,96,211,212,17,105,204,203,251,67,193,167,234,136,121,121,127,104,248,212,250)
IMAGE_DATA(169,250,67,50,255,226,178,103,175,9,123,36,237,240,189,112,90,252,7,163,20,91,230,209,143,103,203,240,147,43,243,227)
IMAGE_DATA(168,238,241,212,54,191,24,163,172,216,172,127,37,165,164,58,12,202,10,26,181,109,241,239,70,220,40,54,49,216,205,42)
IMAGE_DATA(139,81,244,48,152,152,127,221,47,148,63,47,111,51,127,219,245,175,68,148,191,193,149,37,168,0,0,0,0,0,0,0)
IMAGE_END_DATA(960, 11)

View file

@ -9,14 +9,12 @@ namespace Upp {
TextDiffCtrl::TextDiffCtrl()
{
left.SetLeft();
left.Gutter(30);
next.SetImage(DiffImg::Next());
prev.SetImage(DiffImg::Prev());
left.scroll.y.AddFrame(prev);
left.scroll.y.AddFrame(next);
next << [=] { FindDiff(true); };
prev << [=] { FindDiff(false); };
right.NoGutter();
Horz(left, right);
left.WhenScroll = right.ScrollWhen(left);
right.WhenScroll = left.ScrollWhen(right);

View file

@ -5,7 +5,7 @@ namespace Upp {
inline Color HistoryBg() { return Color(255, 255, 0); }
TextCompareCtrl::TextCompareCtrl()
{
: sbi(*this) {
letter = Size(1, 1);
number_width = 0;
number_yshift = 0;
@ -17,11 +17,7 @@ TextCompareCtrl::TextCompareCtrl()
scroll.WhenScroll = THISBACK(SelfScroll);
maxwidth = 0;
tabsize = 4;
gutter_width = 0;
gutter_bg = AdjustIfDark(Color(151, 190, 239));
gutter_fg = SGreen;
cursor = anchor = Null;
gutter_capture = false;
show_line_number = true;
show_white_space = false;
show_diff_highlight = true;
@ -52,19 +48,8 @@ void TextCompareCtrl::DoSelection(int y, bool shift)
void TextCompareCtrl::LeftDown(Point pt, dword keyflags)
{
Size sz = GetSize();
if(pt.x > sz.cx - gutter_width || HasCapture() && gutter_capture) {
if(!HasCapture())
SetCapture();
int line = (pt.y * lines.GetCount()) / sz.cy;
int page_lines = sz.cy / letter.cy;
scroll.SetY(line - page_lines / 2);
gutter_capture = true;
}
else {
DoSelection(pt.y, keyflags & K_SHIFT);
SetCapture();
gutter_capture = false;
}
DoSelection(pt.y, keyflags & K_SHIFT);
SetCapture();
SetWantFocus();
}
@ -78,17 +63,13 @@ void TextCompareCtrl::LeftDouble(Point pt, dword keyflags)
void TextCompareCtrl::MouseMove(Point pt, dword flags)
{
if(HasCapture()) {
if(gutter_capture)
LeftDown(pt, flags);
else
DoSelection(pt.y, true);
}
if(HasCapture())
DoSelection(pt.y, true);
}
void TextCompareCtrl::LeftRepeat(Point pt, dword keyflags)
{
if(HasCapture() && !gutter_capture)
if(HasCapture())
DoSelection(pt.y, true);
}
@ -244,6 +225,29 @@ bool TextCompareCtrl::LineDiff(bool left, Vector<LineEdit::Highlight>& hln, Colo
return false;
}
TextCompareCtrl::ScrollBarItems::ScrollBarItems(TextCompareCtrl& e)
: diff(e) {
e.scroll.y.Add(SizePos());
Transparent();
IgnoreMouse();
}
void TextCompareCtrl::ScrollBarItems::Paint(Draw& w)
{
diff.PaintScrollBarItems(w);
}
void TextCompareCtrl::PaintScrollBarItems(Draw& w)
{
Size isz = DiffImg::dot().GetSize();
Rect sr = scroll.y.GetSliderRect();
for(int i = 0; i < lines.GetCount(); i++)
if(lines[i].level > 1)
w.DrawImage(sr.CenterPoint().x - isz.cx / 2,
sr.top + scroll.y.GetSliderPos(i) - isz.cy / 2,
DiffImg::dot());
}
void TextCompareCtrl::Paint(Draw& draw)
{
Point sc = scroll.Get();
@ -253,34 +257,6 @@ void TextCompareCtrl::Paint(Draw& draw)
int lcnt = lines.GetCount();
int first_line = offset.cy / letter.cy;
int last_line = min(idivceil(sz.cy + offset.cy, letter.cy), lines.GetCount() - 1);
if(gutter_width > 0)
{
int t = 0, b = 0;
int gx = sz.cx - gutter_width;
for(int i = 0; i < lcnt; i++)
if(lines[i].level > 1) {
b = idivceil(sz.cy * i, lcnt);
if(b >= t) {
draw.DrawRect(gx, t, gutter_width, b - t, gutter_bg);
draw.DrawRect(gx, b, gutter_width, 1, gutter_fg);
t = b + 1;
}
}
draw.DrawRect(gx, t, gutter_width, sz.cy - t, gutter_bg);
int total = letter.cy * lcnt;
if(total <= 0)
total = 1;
int page_height = (sz.cy * sz.cy) / total;
int ty = max(0, (sz.cy * offset.cy) / total);
int by = min(sz.cy, ty + page_height);
draw.DrawRect(gx, ty, gutter_width, 2, Black);
draw.DrawRect(gx, by - 2, gutter_width, 2, Black);
draw.DrawRect(gx, ty, 2, by - ty, Black);
draw.DrawRect(gx + gutter_width - 2, ty, 2, by - ty, Black);
}
WString test = "č"; // read text/paper colors from highlighting scheme using likely non-highlighted text
Vector<LineEdit::Highlight> th;
@ -307,7 +283,7 @@ void TextCompareCtrl::Paint(Draw& draw)
draw.DrawText(0, y + number_yshift, FormatInt(l.number_diff), number_font, ink);
}
}
draw.Clip(n_width, 0, sz.cx - gutter_width - n_width, sz.cy);
draw.Clip(n_width, 0, sz.cx - n_width, sz.cy);
for(int i = first_line; i <= last_line; i++) {
const Line& l = lines[i];
@ -444,7 +420,7 @@ void TextCompareCtrl::Layout()
{
int n_width = show_line_number ? number_width : 0;
scroll.Set(scroll, (scroll.GetReducedViewSize() - Size(n_width + gutter_width, 0)) / letter, Size(maxwidth, lines.GetCount()));
scroll.Set(scroll, (scroll.GetReducedViewSize() - Size(n_width, 0)) / letter, Size(maxwidth, lines.GetCount()));
Refresh();
}

View file

@ -73,21 +73,29 @@ private:
Font font;
Font number_font;
Color number_bg;
Color gutter_fg;
Color gutter_bg;
Size letter;
int tabsize;
int number_width;
int number_yshift;
int gutter_width;
int cursor;
int anchor;
bool gutter_capture;
bool show_line_number;
bool show_white_space;
bool show_diff_highlight;
bool change_paper_color;
bool left = false;
struct ScrollBarItems : Ctrl {
TextCompareCtrl& diff;
void Paint(Draw& w);
ScrollBarItems(TextCompareCtrl& e);
};
ScrollBarItems sbi;
void PaintScrollBarItems(Draw& w);
typedef TextCompareCtrl CLASSNAME;
@ -115,9 +123,6 @@ public:
void ShowSb(bool ssb) { scroll.ShowY(ssb); }
void HideSb() { ShowSb(false); }
void Gutter(int size) { gutter_width = size; Refresh(); }
void NoGutter() { gutter_width = 0; Refresh(); }
void TabSize(int t);
int GetTabSize() const { return tabsize; }