1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 12:02:21 +02:00

Added buttons to BookmarksPanel

This commit is contained in:
Simon Lübeß 2022-06-09 18:23:57 +02:00
parent bd048e2fe6
commit 09c31d5db1
8 changed files with 196 additions and 45 deletions

View file

@ -3,19 +3,107 @@ using System.Collections;
using System.Text; using System.Text;
using Beefy.widgets; using Beefy.widgets;
using Beefy.gfx; using Beefy.gfx;
using Beefy.geom;
namespace Beefy.theme.dark namespace Beefy.theme.dark
{ {
public struct Padding
{
public float Left;
public float Right;
public float Top;
public float Bottom;
public this(float padding)
{
Left = padding;
Right = padding;
Top = padding;
Bottom = padding;
}
public this(float leftRight, float topBottom)
{
Left = leftRight;
Right = leftRight;
Top = topBottom;
Bottom = topBottom;
}
public this(float left, float right, float top, float bottom)
{
Left = left;
Right = right;
Top = top;
Bottom = bottom;
}
}
public class DarkIconButton : ButtonWidget public class DarkIconButton : ButtonWidget
{ {
public Image mIcon; private Image mIcon;
public float mIconOfsX;
public float mIconOfsY; private Padding mPadding = .(4);
public Image Icon
{
get => mIcon;
set
{
if (mIcon == value)
return;
mIcon = value;
if (mIcon != null)
UpdateSize();
}
}
public Padding Padding
{
get => mPadding;
set
{
if (mPadding == value)
return;
mPadding = value;
UpdateSize();
}
}
/// Calculates the size of the button.
private void UpdateSize()
{
float width = mPadding.Left + mIcon.mWidth + mPadding.Right;
float height = mPadding.Top + mIcon.mHeight + mPadding.Bottom;
Resize(0, 0, width, height);
}
public override void Draw(Graphics g) public override void Draw(Graphics g)
{ {
base.Draw(g); base.Draw(g);
g.Draw(mIcon, mIconOfsX, mIconOfsY);
bool drawDown = ((mMouseDown && mMouseOver) || (mMouseFlags.HasFlag(MouseFlag.Kbd)));
Image texture =
mDisabled ? DarkTheme.sDarkTheme.GetImage(.BtnUp) :
drawDown ? DarkTheme.sDarkTheme.GetImage(.BtnDown) :
mMouseOver ? DarkTheme.sDarkTheme.GetImage(.BtnOver) :
DarkTheme.sDarkTheme.GetImage(.BtnUp);
g.DrawBox(texture, 0, 0, mWidth, mHeight);
if ((mHasFocus) && (!mDisabled))
{
using (g.PushColor(DarkTheme.COLOR_SELECTED_OUTLINE))
g.DrawBox(DarkTheme.sDarkTheme.GetImage(.Outline), 0, 0, mWidth, mHeight);
}
g.Draw(mIcon, mPadding.Left, mPadding.Top);
} }
} }
} }

View file

@ -185,6 +185,11 @@ namespace Beefy.theme.dark
CollapseOpened, CollapseOpened,
IconBookmarkDisabled, IconBookmarkDisabled,
NewBookmarkFolder,
PrevBookmark,
NextBookmark,
PrevBookmarkInFolder,
NextBookmarkInFolder,
COUNT COUNT
}; };

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Before After
Before After

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 67 KiB

Before After
Before After

View file

@ -809,6 +809,7 @@ namespace IDE
dlg(mProfilePanel); dlg(mProfilePanel);
dlg(mPropertiesPanel); dlg(mPropertiesPanel);
dlg(mAutoCompletePanel); dlg(mAutoCompletePanel);
dlg(mBookmarksPanel);
} }
public override void ShutdownCompleted() public override void ShutdownCompleted()

View file

@ -6,6 +6,9 @@ using System.Collections;
using Beefy.theme; using Beefy.theme;
using Beefy.events; using Beefy.events;
using System.Diagnostics; using System.Diagnostics;
using Beefy.theme.dark;
using Beefy.gfx;
using Beefy.geom;
namespace IDE.ui namespace IDE.ui
{ {
@ -63,35 +66,63 @@ namespace IDE.ui
class BookmarksPanel : Panel class BookmarksPanel : Panel
{ {
public DarkButton mCreateBookmarkFolder; public DarkIconButton mBtnCreateBookmarkFolder;
public DarkIconButton mBtnPrevBookmark;
public DarkIconButton mBtnNextBookmark;
public DarkIconButton mBtnPrevBookmarkInFolder;
public DarkIconButton mBtnNextBookmarkInFolder;
public BookmarksListView mBookmarksLV; public BookmarksListView mBookmarksListView;
public this() public this()
{ {
mCreateBookmarkFolder = new DarkButton(); mBtnCreateBookmarkFolder = new DarkIconButton();
mCreateBookmarkFolder.Label = "New Folder"; mBtnCreateBookmarkFolder.Icon = DarkTheme.sDarkTheme.GetImage(.NewBookmarkFolder);
mCreateBookmarkFolder.mOnMouseClick.Add(new (args) => mBtnCreateBookmarkFolder.mOnMouseClick.Add(new (args) => gApp.mBookmarkManager.CreateFolder());
{ AddWidget(mBtnCreateBookmarkFolder);
gApp.mBookmarkManager.CreateFolder();
});
AddWidget(mCreateBookmarkFolder);
mBookmarksLV = new .(); float iconButtonWidth = mBtnCreateBookmarkFolder.Width;
mBookmarksLV.mOnEditDone.Add(new => HandleEditDone);
mBookmarksLV.InitScrollbars(true, true); mBtnPrevBookmark = new DarkIconButton();
mBookmarksLV.mLabelX = GS!(6); mBtnPrevBookmark.Icon = DarkTheme.sDarkTheme.GetImage(.PrevBookmark);
mBookmarksLV.mOnItemMouseClicked.Add(new => ListViewItemMouseClicked); mBtnPrevBookmark.mOnMouseClick.Add(new (args) => gApp.Cmd_PrevBookmark());
mBtnPrevBookmark.X = GS!(1) + iconButtonWidth;
AddWidget(mBtnPrevBookmark);
mBookmarksLV.AddColumn(200, "Bookmark"); mBtnNextBookmark = new DarkIconButton();
mBookmarksLV.AddColumn(400, "File"); mBtnNextBookmark.Icon = DarkTheme.sDarkTheme.GetImage(.NextBookmark);
mBookmarksLV.AddColumn(120, "Line"); mBtnNextBookmark.mOnMouseClick.Add(new (args) => gApp.Cmd_NextBookmark());
mBtnNextBookmark.X = (GS!(1) + iconButtonWidth) * 2;
AddWidget(mBtnNextBookmark);
mBookmarksLV.mOnDragEnd.Add(new => BookmarksLV_OnDragEnd); mBtnPrevBookmarkInFolder = new DarkIconButton();
mBookmarksLV.mOnDragUpdate.Add(new => BookmarksLV_OnDragUpdate); mBtnPrevBookmarkInFolder.Icon = DarkTheme.sDarkTheme.GetImage(.PrevBookmarkInFolder);
mBtnPrevBookmarkInFolder.mOnMouseClick.Add(new (args) => gApp.Cmd_PrevBookmarkInFolder());
mBtnPrevBookmarkInFolder.X = (GS!(1) + iconButtonWidth) * 3;
AddWidget(mBtnPrevBookmarkInFolder);
mBookmarksLV.mOnItemMouseDown.Add(new (item, x, y, btnNum, btnCount) => mBtnNextBookmarkInFolder = new DarkIconButton();
mBtnNextBookmarkInFolder.Icon = DarkTheme.sDarkTheme.GetImage(.NextBookmarkInFolder);
mBtnNextBookmarkInFolder.mOnMouseClick.Add(new (args) => gApp.Cmd_NextBookmarkInFolder());
mBtnNextBookmarkInFolder.X = (GS!(1) + iconButtonWidth) * 4;
AddWidget(mBtnNextBookmarkInFolder);
mBookmarksListView = new .();
mBookmarksListView.mOnEditDone.Add(new => HandleEditDone);
mBookmarksListView.InitScrollbars(true, true);
mBookmarksListView.mLabelX = GS!(6);
mBookmarksListView.mOnItemMouseClicked.Add(new => ListViewItemMouseClicked);
mBookmarksListView.AddColumn(200, "Bookmark");
mBookmarksListView.AddColumn(400, "File");
mBookmarksListView.AddColumn(120, "Line");
mBookmarksListView.mOnDragEnd.Add(new => BookmarksLV_OnDragEnd);
mBookmarksListView.mOnDragUpdate.Add(new => BookmarksLV_OnDragUpdate);
mBookmarksListView.mOnItemMouseDown.Add(new (item, x, y, btnNum, btnCount) =>
{ {
if ((btnNum == 0) && (btnCount == 2)) if ((btnNum == 0) && (btnCount == 2))
{ {
@ -101,10 +132,10 @@ namespace IDE.ui
ListViewItemMouseDown(item, x, y, btnNum, btnCount); ListViewItemMouseDown(item, x, y, btnNum, btnCount);
}); });
mBookmarksLV.mOnItemMouseClicked.Add(new => ListViewItemMouseClicked); mBookmarksListView.mOnItemMouseClicked.Add(new => ListViewItemMouseClicked);
mBookmarksLV.mOnKeyDown.Add(new => BookmarksLV_OnKeyDown); mBookmarksListView.mOnKeyDown.Add(new => BookmarksLV_OnKeyDown);
AddWidget(mBookmarksLV); AddWidget(mBookmarksListView);
} }
private void BookmarksLV_OnKeyDown(KeyDownEvent event) private void BookmarksLV_OnKeyDown(KeyDownEvent event)
@ -119,7 +150,15 @@ namespace IDE.ui
public override void RehupScale(float oldScale, float newScale) public override void RehupScale(float oldScale, float newScale)
{ {
mBookmarksLV.mOpenButtonX = GS!(4); mBookmarksListView.mOpenButtonX = GS!(4);
float iconButtonWidth = mBtnCreateBookmarkFolder.Width;
mBtnPrevBookmark.X = GS!(1) + iconButtonWidth;
mBtnNextBookmark.X = (GS!(1) + iconButtonWidth) * 2;
mBtnPrevBookmarkInFolder.X = (GS!(1) + iconButtonWidth) * 3;
mBtnNextBookmarkInFolder.X = (GS!(1) + iconButtonWidth) * 4;
base.RehupScale(oldScale, newScale); base.RehupScale(oldScale, newScale);
} }
@ -166,7 +205,7 @@ namespace IDE.ui
return; return;
List<BookmarksListViewItem> selectedItems = scope .(); List<BookmarksListViewItem> selectedItems = scope .();
mBookmarksLV.GetRoot().WithSelectedItems(scope [&] (selectedItem) => mBookmarksListView.GetRoot().WithSelectedItems(scope [&] (selectedItem) =>
{ {
selectedItems.Add((BookmarksListViewItem)selectedItem); selectedItems.Add((BookmarksListViewItem)selectedItem);
}); });
@ -231,7 +270,7 @@ namespace IDE.ui
/// Tries to rename the currently selected bookmark /// Tries to rename the currently selected bookmark
public void TryRenameItem() public void TryRenameItem()
{ {
ListViewItem selectedItem = mBookmarksLV.GetRoot().FindFirstSelectedItem(); ListViewItem selectedItem = mBookmarksListView.GetRoot().FindFirstSelectedItem();
RenameItem(selectedItem); RenameItem(selectedItem);
} }
@ -242,7 +281,7 @@ namespace IDE.ui
editWidget.GetText(newValue); editWidget.GetText(newValue);
newValue.Trim(); newValue.Trim();
ListViewItem listViewItem = mBookmarksLV.mEditingItem; ListViewItem listViewItem = mBookmarksListView.mEditingItem;
if (var item = listViewItem as BookmarksListViewItem) if (var item = listViewItem as BookmarksListViewItem)
{ {
@ -289,7 +328,7 @@ namespace IDE.ui
anItem = menu.AddItem("Rename"); anItem = menu.AddItem("Rename");
anItem.mOnMenuItemSelected.Add(new (item) => anItem.mOnMenuItemSelected.Add(new (item) =>
{ {
var selectedItem = mBookmarksLV.GetRoot().FindFirstSelectedItem(); var selectedItem = mBookmarksListView.GetRoot().FindFirstSelectedItem();
if (selectedItem != null) if (selectedItem != null)
RenameItem(selectedItem); RenameItem(selectedItem);
}); });
@ -320,7 +359,7 @@ namespace IDE.ui
void EditListViewItem(ListViewItem listViewItem) void EditListViewItem(ListViewItem listViewItem)
{ {
mBookmarksLV.EditListViewItem(listViewItem); mBookmarksListView.EditListViewItem(listViewItem);
} }
void RenameItem(ListViewItem listViewItem) void RenameItem(ListViewItem listViewItem)
@ -340,31 +379,48 @@ namespace IDE.ui
{ {
base.Resize(x, y, width, height); base.Resize(x, y, width, height);
float buttonWidth = GS!(140); float buttonHeight = mBtnCreateBookmarkFolder.mHeight;
float buttonHeight = GS!(22);
mCreateBookmarkFolder.Resize(0, 0, buttonWidth, buttonHeight);
mBookmarksLV.Resize(0, buttonHeight, width, Math.Max(mHeight - buttonHeight, 0)); mBookmarksListView.Resize(0, buttonHeight, width, Math.Max(mHeight - buttonHeight, 0));
}
public void Clear()
{
} }
public bool mBookmarksDirty; public bool mBookmarksDirty;
public override void Update() public override void Update()
{ {
if (mBookmarksDirty) if (mBookmarksDirty)
UpdateBookmarks(); UpdateBookmarks();
ShowTooltip(mBtnCreateBookmarkFolder, "Create a new folder.");
ShowTooltip(mBtnPrevBookmark, "Move the cursor to previous bookmark.");
ShowTooltip(mBtnNextBookmark, "Move the cursor to next bookmark.");
ShowTooltip(mBtnPrevBookmarkInFolder, "Move the cursor to previous bookmark in the current folder.");
ShowTooltip(mBtnNextBookmarkInFolder, "Move the cursor to next bookmark in the current folder.");
base.Update(); base.Update();
} }
public void Clear()
{
var root = mBookmarksListView.GetRoot();
root.Clear();
mBookmarksDirty = true;
}
private void ShowTooltip(Widget widget, String text)
{
Point mousePoint;
if (DarkTooltipManager.CheckMouseover(widget, 20, out mousePoint))
{
DarkTooltipManager.ShowTooltip(text, widget, mousePoint.x, mousePoint.y);
}
}
private void UpdateBookmarks() private void UpdateBookmarks()
{ {
var root = mBookmarksLV.GetRoot(); var root = mBookmarksListView.GetRoot();
root.Clear(); root.Clear();
@ -377,6 +433,7 @@ namespace IDE.ui
if (!isRoot) if (!isRoot)
{ {
FolderItem = (BookmarksListViewItem)root.CreateChildItem(); FolderItem = (BookmarksListViewItem)root.CreateChildItem();
SetupListViewItemFolder(FolderItem, folder); SetupListViewItemFolder(FolderItem, folder);
} }
else else
@ -447,14 +504,14 @@ namespace IDE.ui
public override void KeyDown(KeyCode keyCode, bool isRepeat) public override void KeyDown(KeyCode keyCode, bool isRepeat)
{ {
mBookmarksLV.KeyDown(keyCode, isRepeat); mBookmarksListView.KeyDown(keyCode, isRepeat);
base.KeyDown(keyCode, isRepeat); base.KeyDown(keyCode, isRepeat);
} }
private void DeleteSelectedItems() private void DeleteSelectedItems()
{ {
var root = mBookmarksLV.GetRoot(); var root = mBookmarksListView.GetRoot();
List<ListViewItem> selectedItems = scope List<ListViewItem>(); List<ListViewItem> selectedItems = scope List<ListViewItem>();
root.WithSelectedItems(scope (listViewItem) => root.WithSelectedItems(scope (listViewItem) =>
{ {