1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-04 15:26:00 +02:00

Show comptime emits as embedded sourceviews

This commit is contained in:
Brian Fiete 2022-04-16 06:27:54 -07:00
parent ee27f6fd02
commit 4d1e14a1c3
65 changed files with 3360 additions and 633 deletions

View file

@ -59,7 +59,7 @@ namespace Beefy.theme.dark
public uint32 mBkgColor;
public DarkEditWidget mEditWidget;
bool mAllowReverseDropdown; // Allow popdown to "popup" if there isn't enough space
public Widget mPrevFocusWidget;
public SafeWidgetRef mPrevFocusWidget ~ delete _;
public bool mFocusDropdown = true;
virtual public StringView Label
@ -170,12 +170,16 @@ namespace Beefy.theme.dark
public virtual void MenuClosed()
{
if (mPrevFocusWidget != null)
{
mPrevFocusWidget.SetFocus();
}
mPrevFocusWidget?.Value?.SetFocus();
}
protected override void RemovedFromWindow()
{
base.RemovedFromWindow();
mCurMenuWidget?.mMenu.mOnMenuClosed.Dispose();
}
void HandleClose(Menu menu, Menu selectedItem)
{
mCurMenuWidget = null;
@ -186,7 +190,8 @@ namespace Beefy.theme.dark
public virtual MenuWidget ShowDropdown()
{
mPrevFocusWidget = mWidgetWindow.mFocusWidget;
if ((mPrevFocusWidget == null) && (mWidgetWindow.mFocusWidget != null))
mPrevFocusWidget = new .(mWidgetWindow.mFocusWidget);
float popupXOfs = GS!(5);
float popupYOfs = GS!(-2);
@ -302,6 +307,16 @@ namespace Beefy.theme.dark
return true;
}
public void SelectFromLabel()
{
var label = Label;
for (let itemWidget in mCurMenuWidget.mItemWidgets)
{
if (itemWidget.mMenuItem.mLabel == label)
mCurMenuWidget.SetSelection(@itemWidget.Index);
}
}
void EditKeyDownHandler(KeyDownEvent evt)
{
if (!WantsKeyHandling())
@ -318,13 +333,7 @@ namespace Beefy.theme.dark
if ((evt.mKeyCode == .Down) && (mCurMenuWidget == null))
{
ShowDropdown();
var label = Label;
for (let itemWidget in mCurMenuWidget.mItemWidgets)
{
if (itemWidget.mMenuItem.mLabel == label)
mCurMenuWidget.SetSelection(@itemWidget.Index);
}
SelectFromLabel();
}
if ((evt.mKeyCode == .Escape) && (mCurMenuWidget != null) && (mEditWidget != null))

View file

@ -21,6 +21,7 @@ namespace Beefy.theme.dark
}
public Kind mKind;
public int32 mLine = -1;
public ~this()
{
@ -61,7 +62,8 @@ namespace Beefy.theme.dark
public uint32 mViewWhiteSpaceColor;
public bool mScrollToStartOnLostFocus;
public bool mHiliteCurrentLine;
public Dictionary<int, Embed> mEmbeds = new .() ~ DeleteDictionaryAndValues!(_);
public Dictionary<int32, Embed> mEmbeds = new .() ~ DeleteDictionaryAndValues!(_);
public Range? mLineRange;
protected static uint32[] sDefaultColors = new uint32[] ( Color.White ) ~ delete _;
@ -498,7 +500,7 @@ namespace Beefy.theme.dark
((embed.mKind == .HideLine) && (!hideLine)))
selStartX += GS!(4);
Rect rect = .(selStartX, mLineCoords[lineIdx] - GS!(2), embed.GetWidth(hideLine), mFont.GetLineSpacing() + GS!(4));
Rect rect = .(selStartX, mLineCoords[lineIdx] - GS!(1), embed.GetWidth(hideLine), mFont.GetLineSpacing() + GS!(3));
if (rect.mY < 0)
rect.mY = 0;
return rect;
@ -508,7 +510,6 @@ namespace Beefy.theme.dark
{
base.Draw(g);
#unwarn
int lineCount = GetLineCount();
float lineSpacing = mFont.GetLineSpacing();
@ -588,6 +589,12 @@ namespace Beefy.theme.dark
drewCursor = true;
}
if (mLineRange != null)
{
firstLine = Math.Max(firstLine, mLineRange.Value.Start);
lastLine = Math.Min(lastLine, mLineRange.Value.End - 1);
}
String sectionText = scope String(256);
for (int lineIdx = firstLine; lineIdx <= lastLine; lineIdx++)
{
@ -604,7 +611,7 @@ namespace Beefy.theme.dark
continue;
DarkEditWidgetContent.Embed embed = null;
if (mEmbeds.GetValue(lineIdx) case .Ok(out embed))
if (mEmbeds.GetValue((.)lineIdx) case .Ok(out embed))
{
if ((embed.mKind == .HideLine) &&
((!IsInCollapseGroup(lineIdx, CursorLine)) || (!mEditWidget.mHasFocus)))
@ -813,6 +820,20 @@ namespace Beefy.theme.dark
return line;
}
public override void PhysCursorMoved(CursorMoveKind moveKind)
{
base.PhysCursorMoved(moveKind);
if (mLineRange != null)
{
var lineAndColumn = CursorLineAndColumn;
if (lineAndColumn.mLine < mLineRange.Value.Start)
CursorLineAndColumn = .(mLineRange.Value.Start, lineAndColumn.mColumn);
else if (lineAndColumn.mLine >= mLineRange.Value.End)
CursorLineAndColumn = .(mLineRange.Value.End - 1, lineAndColumn.mColumn);
}
}
public override bool GetLineCharAtCoord(float x, float y, out int line, out int lineChar, out float overflowX)
{
line = GetLineAt(y);
@ -1145,7 +1166,7 @@ namespace Beefy.theme.dark
bool isOverEmbed = false;
if (mEmbeds.GetValue(line) case .Ok(let embed))
if (mEmbeds.GetValue((.)line) case .Ok(let embed))
{
Rect embedRect = GetEmbedRect(line, embed);
if (embedRect.Contains(x, y))
@ -1223,6 +1244,21 @@ namespace Beefy.theme.dark
mVertScrollbar.mScrollIncrement = scrollIncrement;
}
public override void UpdateScrollbarData()
{
base.UpdateScrollbarData();
var ewc = mEditWidgetContent as DarkEditWidgetContent;
if (ewc.mLineRange != null)
{
ewc.GetTextData();
mVertScrollbar.mContentStart = ewc.mLineCoords[Math.Min(ewc.mLineRange.Value.Start, ewc.mLineCoords.Count - 1)];
mVertScrollbar.mContentSize = ewc.mLineCoords[Math.Min(ewc.mLineRange.Value.End, ewc.mLineCoords.Count - 1)] - mVertScrollbar.mContentStart;
ScrollPositionChanged();
mVertScrollbar.UpdateData();
}
}
public override void Draw(Graphics g)
{
base.Draw(g);

View file

@ -125,14 +125,14 @@ namespace Beefy.theme.dark
float trackSize = sizeLeft - mThumb.mWidth;
float trackPct = (x - btnMargin) / trackSize;
double contentPos = (mContentSize - mPageSize) * trackPct;
return contentPos;
return contentPos + mContentStart;
}
else
{
float trackSize = sizeLeft - mThumb.mHeight;
float trackPct = (y - btnMargin) / trackSize;
double contentPos = (mContentSize - mPageSize) * trackPct;
return contentPos;
return contentPos + mContentStart;
}
}

View file

@ -2868,11 +2868,11 @@ namespace Beefy.widgets
ExtractString(lineStart, lineEnd - lineStart, outStr); // Full line
}
public int GetTextIdx(int line, int charIdx)
public int GetTextIdx(int line, int lineChar)
{
GetTextData();
int useLine = Math.Min(line, mData.mLineStarts.Count - 1);
return mData.mLineStarts[useLine] + charIdx;
return mData.mLineStarts[useLine] + lineChar;
}
public int GetCharIdIdx(int32 findCharId)
@ -3139,13 +3139,15 @@ namespace Beefy.widgets
float lineHeight = GetLineHeight(line);
double yOfs = (mEditWidget.mVertScrollbar?.mContentStart).GetValueOrDefault();
if (mIsMultiline)
{
if (aY < mEditWidget.mVertPos.mDest + mTextInsets.mTop)
if (aY < mEditWidget.mVertPos.mDest + mTextInsets.mTop + yOfs)
{
if (scrollView)
{
float scrollPos = aY - mTextInsets.mTop;
double scrollPos = aY - mTextInsets.mTop - yOfs;
if (centerView)
{
scrollPos -= mEditWidget.mScrollContentContainer.mHeight * 0.50f;
@ -3158,7 +3160,7 @@ namespace Beefy.widgets
int aLine;
int aCharIdx;
float overflowX;
GetLineCharAtCoord(aX, (float)mEditWidget.mVertPos.mDest + mTextInsets.mTop, out aLine, out aCharIdx, out overflowX);
GetLineCharAtCoord(aX, (float)(mEditWidget.mVertPos.mDest + mTextInsets.mTop + yOfs), out aLine, out aCharIdx, out overflowX);
float newX;
float newY;
@ -3169,11 +3171,11 @@ namespace Beefy.widgets
MoveCursorTo(aLine, aCharIdx);
}
}
else if (aY + lineHeight + mShowLineBottomPadding > mEditWidget.mVertPos.mDest + mEditWidget.mScrollContentContainer.mHeight)
else if (aY + lineHeight + mShowLineBottomPadding > mEditWidget.mVertPos.mDest + mEditWidget.mScrollContentContainer.mHeight + yOfs)
{
if (scrollView)
{
float scrollPos = aY + lineHeight + mShowLineBottomPadding - mEditWidget.mScrollContentContainer.mHeight;
double scrollPos = aY + lineHeight + mShowLineBottomPadding - mEditWidget.mScrollContentContainer.mHeight - yOfs;
if (centerView)
{
// Show slightly more content on bottom
@ -3183,7 +3185,7 @@ namespace Beefy.widgets
mEditWidget.VertScrollTo(scrollPos);
}
else
MoveCursorToCoord(aX, (float)mEditWidget.mVertPos.mDest + mEditWidget.mScrollContentContainer.mHeight - lineHeight);
MoveCursorToCoord(aX, (float)(mEditWidget.mVertPos.mDest + mEditWidget.mScrollContentContainer.mHeight - lineHeight + yOfs));
}
}

View file

@ -121,7 +121,11 @@ namespace Beefy.widgets
public bool VertScrollTo(double vertPos, bool immediate = false)
{
double aVertPos = Math.Max(0, Math.Min(vertPos, mScrollContent.mHeight - mScrollContentContainer.mHeight));
float contentHeight = mScrollContent.mHeight;
if (mVertScrollbar != null)
contentHeight = (float)mVertScrollbar.mContentSize;
double aVertPos = Math.Max(0, Math.Min(vertPos, contentHeight - mScrollContentContainer.mHeight));
if (aVertPos == mVertPos.mDest)
return false;
@ -200,6 +204,7 @@ namespace Beefy.widgets
mHorzScrollbar.UpdateData();
MarkDirty();
}
if ((mVertScrollbar != null) && (mVertScrollbar.mContentPos != mVertPos.v))
{
mVertScrollbar.mContentPos = mVertPos.v;
@ -208,7 +213,9 @@ namespace Beefy.widgets
}
if (mScrollContent != null)
{
mScrollContent.Resize((int32)(-mHorzPos.v), (int32)(-mVertPos.v),
mScrollContent.Resize(
(int32)(-mHorzPos.v - (mHorzScrollbar?.mContentStart).GetValueOrDefault()),
(int32)(-mVertPos.v - (mVertScrollbar?.mContentStart).GetValueOrDefault()),
mScrollContent.mWidth, mScrollContent.mHeight);
}
@ -253,6 +260,7 @@ namespace Beefy.widgets
public override void MouseWheel(float x, float y, float deltaX, float deltaY)
{
base.MouseWheel(x, y, deltaX, deltaY);
if (deltaY != 0)
{
if (mVertScrollbar != null)

View file

@ -100,6 +100,7 @@ namespace Beefy.widgets
Vert
}
public double mContentStart;
public double mContentSize;
public double mPageSize;
public double mContentPos;
@ -120,6 +121,7 @@ namespace Beefy.widgets
public float mScrollIncrement;
public bool mAlignItems;
public bool mDoAutoClamp = true;
public bool mAllowMouseWheel = true;
public Event<ScrollEventHandler> mOnScrollEvent ~ _.Dispose();
@ -147,6 +149,9 @@ namespace Beefy.widgets
public virtual void ScrollTo(double pos)
{
var pos;
pos -= mContentStart;
MarkDirty();
double oldPos = mContentPos;
@ -161,8 +166,8 @@ namespace Beefy.widgets
if ((mOnScrollEvent.HasListeners) && (oldPos != mContentPos))
{
ScrollEvent scrollEvent = scope ScrollEvent();
scrollEvent.mOldPos = oldPos;
scrollEvent.mNewPos = mContentPos;
scrollEvent.mOldPos = oldPos + mContentStart;
scrollEvent.mNewPos = mContentPos + mContentStart;
mOnScrollEvent(scrollEvent);
}
}
@ -176,7 +181,7 @@ namespace Beefy.widgets
public virtual void Scroll(double amt)
{
ScrollTo(mContentPos + amt);
ScrollTo(mContentPos + amt + mContentStart);
}
public virtual double GetContentPosAt(float x, float y)
@ -226,6 +231,12 @@ namespace Beefy.widgets
public override void MouseWheel(float x, float y, float deltaX, float deltaY)
{
if (!mAllowMouseWheel)
{
base.MouseWheel(x, y, deltaX, deltaY);
return;
}
float delta = (mOrientation == .Horz) ? deltaX : deltaY;
Scroll(GetScrollIncrement() * -delta);
}

View file

@ -834,4 +834,27 @@ namespace Beefy.widgets
return true;
}
}
class SafeWidgetRef
{
Widget mWidget;
public this(Widget widget)
{
mWidget = widget;
mWidget.mOnDeleted.Add(new => OnDelete);
}
public ~this()
{
mWidget?.mOnDeleted.Remove(scope => OnDelete, true);
}
public Widget Value => mWidget;
void OnDelete(Widget widget)
{
mWidget = null;
}
}
}