-
Notifications
You must be signed in to change notification settings - Fork 34
Pinnable "Page Search" with Right click #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,11 +23,15 @@ public abstract class Window : IDisposable { | |||||||
|
|
||||||||
| private Tooltip? tooltip; | ||||||||
| private SimpleTooltip? simpleTooltip; | ||||||||
| protected DropDownPanel? dropDown; | ||||||||
| protected DropDownPanel? commonDropDown; | ||||||||
| private SimpleDropDown? simpleDropDown; | ||||||||
| protected DropDownPanel? pagesDropDown; | ||||||||
| private SimpleDropDown? pagesSimpleDropDown; | ||||||||
|
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not clear to me (by names) what all of these dropdown are (doing). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't checked too much DropDownPanel x SimpleDropDown I just needed to use separate dropdown for pages search to be able to open for example the dropdown for recipe column and keep the pages search opened - until now just one dropdown could be opened at the same time while reusing the single one shared DropDownPanel and SimpleDropDown There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whatever's going on with I would like to see the two new fields renamed to better explain why we need two fields for one dropdown. |
||||||||
| private ImGui.DragOverlay? draggingOverlay; | ||||||||
| private bool disposedValue; | ||||||||
|
|
||||||||
| public bool PagesSimpleDropPinned => pagesSimpleDropDown?.pinnedMode ?? false; | ||||||||
|
|
||||||||
| public DrawingSurface? surface { get; protected set; } | ||||||||
|
|
||||||||
| public int displayIndex => SDL.SDL_GetWindowDisplayIndex(window); | ||||||||
|
|
@@ -215,7 +219,7 @@ public void ShowTooltip(ImGui targetGui, Rect target, GuiBuilder builder, float | |||||||
| } | ||||||||
|
|
||||||||
| public void ShowDropDown(DropDownPanel dropDown) { | ||||||||
| this.dropDown = dropDown; | ||||||||
| this.commonDropDown = dropDown; | ||||||||
| Rebuild(); | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -226,16 +230,57 @@ public void ShowDropDown(ImGui targetGui, Rect target, GuiBuilder builder, Paddi | |||||||
| ShowDropDown(simpleDropDown); | ||||||||
| } | ||||||||
|
|
||||||||
| public void ShowPagesListDropDown(ImGui targetGui, Rect target, GuiBuilder builder, Padding padding, float width = 20f, bool pinned = false) { | ||||||||
|
|
||||||||
| if (simpleDropDown?.active == true) { | ||||||||
| simpleDropDown.Close(); | ||||||||
| } | ||||||||
|
|
||||||||
| pagesSimpleDropDown ??= new SimpleDropDown(); | ||||||||
|
|
||||||||
| pagesSimpleDropDown.SetPadding(padding); | ||||||||
| pagesSimpleDropDown.SetFocus(targetGui, target, builder, width, pinned); | ||||||||
|
|
||||||||
| this.pagesDropDown = pagesSimpleDropDown; | ||||||||
| this. | ||||||||
| Rebuild(); | ||||||||
|
Comment on lines
+245
to
+246
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No idea if you meant to explicitly wanted/needed to include |
||||||||
| } | ||||||||
|
|
||||||||
| public bool ClosePagesListDropDown(ImGui targetGui, Rect target) { | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function documentation would be appreciated for (new) functions. In this case even more, as it is unclear what the returned (Later I figured, it seems to be true when the dropdown was not closed?) |
||||||||
| pagesSimpleDropDown ??= new SimpleDropDown(); | ||||||||
| // If a pinned dropdown is already open for this source/rect and caller asked to open pinned, close it. | ||||||||
| if (pagesSimpleDropDown.active && pagesSimpleDropDown.pinnedMode && pagesSimpleDropDown.MatchesSource(targetGui, target)) { | ||||||||
| pagesSimpleDropDown.pinnedMode = false; | ||||||||
| pagesSimpleDropDown.Close(); | ||||||||
| // Ensure top-level reference is cleared so Build won't try to render it next frame | ||||||||
| if (pagesDropDown == pagesSimpleDropDown) { | ||||||||
| pagesDropDown = null; | ||||||||
| } | ||||||||
| Rebuild(); | ||||||||
|
|
||||||||
| return true; | ||||||||
| } | ||||||||
|
|
||||||||
| return false; | ||||||||
| } | ||||||||
|
|
||||||||
| private void Build(ImGui gui) { | ||||||||
| if (closed) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| BuildContents(gui); | ||||||||
| if (dropDown != null) { | ||||||||
| dropDown.Build(gui); | ||||||||
| if (!dropDown.active) { | ||||||||
| dropDown = null; | ||||||||
| if (commonDropDown != null) { | ||||||||
| commonDropDown.Build(gui); | ||||||||
| if (!commonDropDown.active) { | ||||||||
| commonDropDown = null; | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| if (pagesDropDown != null) { | ||||||||
| pagesDropDown.Build(gui); | ||||||||
| if (!pagesDropDown.active) { | ||||||||
| pagesDropDown = null; | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,13 +198,13 @@ public static ButtonEvent BuildRedButton(this ImGui gui, Icon icon, float size = | |
| } | ||
|
|
||
| public static ButtonEvent BuildButton(this ImGui gui, Icon icon, SchemeColor normal = SchemeColor.None, | ||
| SchemeColor over = SchemeColor.Grey, SchemeColor down = SchemeColor.None, float size = 1.5f) { | ||
| SchemeColor over = SchemeColor.Grey, SchemeColor down = SchemeColor.None, float size = 1.5f, uint button = SDL.SDL_BUTTON_LEFT) { | ||
|
|
||
| using (gui.EnterGroup(new Padding(0.3f))) { | ||
| gui.BuildIcon(icon, size); | ||
| } | ||
|
|
||
| return gui.BuildButton(gui.lastRect, normal, over, down); | ||
| return gui.BuildButton(gui.lastRect, normal, over, down, button); | ||
| } | ||
|
|
||
| public static ButtonEvent BuildButton(this ImGui gui, Icon icon, string text, SchemeColor normal = SchemeColor.None, | ||
|
|
@@ -225,6 +225,13 @@ public static bool WithTooltip(this ButtonEvent evt, ImGui gui, string tooltip, | |
|
|
||
| return evt; | ||
| } | ||
| public static bool WithTooltipConditional(this ButtonEvent evt, bool condition, ImGui gui, string tooltip, Rect? rect = null) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if (evt == ButtonEvent.MouseOver && condition) { | ||
| gui.ShowTooltip(rect ?? gui.lastRect, tooltip); | ||
| } | ||
|
|
||
| return evt; | ||
| } | ||
|
|
||
| public static bool BuildCheckBox(this ImGui gui, string text, bool value, out bool newValue, SchemeColor color = SchemeColor.None, | ||
| RectAllocator allocator = RectAllocator.LeftRow, string? tooltip = null) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||||||||||||||||||||||||||||||||||
| using System.IO; | ||||||||||||||||||||||||||||||||||||
| using System.Net.Http; | ||||||||||||||||||||||||||||||||||||
| using System.Numerics; | ||||||||||||||||||||||||||||||||||||
| using System.Runtime.CompilerServices; | ||||||||||||||||||||||||||||||||||||
| using System.Text.Json; | ||||||||||||||||||||||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||||||||||||||||||||||
| using SDL2; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -137,7 +138,9 @@ private void BuildPage(ImGui gui, ProjectPage element, int index) { | |||||||||||||||||||||||||||||||||||
| if (evt) { | ||||||||||||||||||||||||||||||||||||
| if (gui.actionParameter == SDL.SDL_BUTTON_MIDDLE) { | ||||||||||||||||||||||||||||||||||||
| ProjectPageSettingsPanel.Show(element); | ||||||||||||||||||||||||||||||||||||
| dropDown?.Close(); | ||||||||||||||||||||||||||||||||||||
| commonDropDown?.Close(); | ||||||||||||||||||||||||||||||||||||
| pagesDropDown?.Close(); | ||||||||||||||||||||||||||||||||||||
| HideTooltip(); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||||
| SetActivePage(element); | ||||||||||||||||||||||||||||||||||||
|
|
@@ -152,6 +155,8 @@ private void ProjectOnMetaInfoChanged() { | |||||||||||||||||||||||||||||||||||
| if (_activePage != null && project.FindPage(_activePage.guid) != _activePage) { | ||||||||||||||||||||||||||||||||||||
| SetActivePage(null); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| // Keep the missing-pages dropdown list in sync with project changes (add/remove/rename) | ||||||||||||||||||||||||||||||||||||
| UpdatePageList(); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private void ChangePage(ref ProjectPage? activePage, ProjectPage? newPage, ref ProjectPageView? activePageView, ProjectPageView? newPageView) { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -254,29 +259,59 @@ private void BuildTabBar(ImGui gui) { | |||||||||||||||||||||||||||||||||||
| ProductionTableView.CreateProductionSheet(); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| var padding = new Padding(0f, 0f, 0f, 0.5f); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| gui.allocator = RectAllocator.RightRow; | ||||||||||||||||||||||||||||||||||||
| if (gui.BuildButton(Icon.DropDown, SchemeColor.None, SchemeColor.Grey).WithTooltip(gui, LSs.ListAndSearchAll.L(ImGuiUtils.ScanToString(SDL.SDL_Scancode.SDL_SCANCODE_F))) || showSearchAll) { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| var isPinned = PagesSimpleDropPinned || this.project.settings.isPagesListPinned; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (isPinned) { | ||||||||||||||||||||||||||||||||||||
| gui.window?.HideTooltip(); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (gui.BuildButton(isPinned ? Icon.Close : Icon.DropDown, SchemeColor.None, SchemeColor.Grey, button: 0).WithTooltipConditional(!isPinned, gui, LSs.ListAndSearchAll.L(ImGuiUtils.ScanToString(SDL.SDL_Scancode.SDL_SCANCODE_F))) || showSearchAll) { | ||||||||||||||||||||||||||||||||||||
| showSearchAll = false; | ||||||||||||||||||||||||||||||||||||
| updatePageList(); | ||||||||||||||||||||||||||||||||||||
| ShowDropDown(gui, gui.lastRect, missingPagesDropdown, new Padding(0f, 0f, 0f, 0.5f), 30f); | ||||||||||||||||||||||||||||||||||||
| UpdatePageList(); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // determine pinned by right-click (mouse button == 3) | ||||||||||||||||||||||||||||||||||||
| bool pin = InputSystem.Instance.mouseDownButton == 3; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (InputSystem.Instance.mouseDownButton == 1 || InputSystem.Instance.mouseDownButton == 3) { | ||||||||||||||||||||||||||||||||||||
| if (!ClosePagesListDropDown(gui, gui.lastRect)) { | ||||||||||||||||||||||||||||||||||||
| showPagesListDropDown(pin); | ||||||||||||||||||||||||||||||||||||
| this.project.settings.isPagesListPinned = pin; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||||
| this.project.settings.isPagesListPinned = false; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+280
to
+287
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a follow-up to veger's comment about
Suggested change
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (this.project.settings.isPagesListPinned && pagesDropDown == null && pseudoScreens.Count == 0) { | ||||||||||||||||||||||||||||||||||||
| showPagesListDropDown(true); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| tabBar.Build(gui); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| gui.DrawRectangle(gui.lastRect, SchemeColor.PureBackground); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| void updatePageList() { | ||||||||||||||||||||||||||||||||||||
| List<ProjectPage> sortedAndFilteredPageList = [.. pageListSearch.Search(project.pages)]; | ||||||||||||||||||||||||||||||||||||
| sortedAndFilteredPageList.Sort((a, b) => a.visible == b.visible ? string.Compare(a.name, b.name, StringComparison.InvariantCultureIgnoreCase) : a.visible ? -1 : 1); | ||||||||||||||||||||||||||||||||||||
| allPages.data = sortedAndFilteredPageList; | ||||||||||||||||||||||||||||||||||||
| void showPagesListDropDown(bool pinned) => ShowPagesListDropDown(gui, gui.lastRect, missingPagesDropdown, padding, 30f, pinned); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| gui.DrawRectangle(gui.lastRect, SchemeColor.PureBackground); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| void missingPagesDropdown(ImGui gui) { | ||||||||||||||||||||||||||||||||||||
| pageListSearch.Build(gui, updatePageList); | ||||||||||||||||||||||||||||||||||||
| pageListSearch.Build(gui, UpdatePageList); | ||||||||||||||||||||||||||||||||||||
| allPages.Build(gui); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Centralized update for the pages list shown in the dropdown so callers (e.g. after renaming) | ||||||||||||||||||||||||||||||||||||
| // can refresh the list. | ||||||||||||||||||||||||||||||||||||
| public void UpdatePageList() { | ||||||||||||||||||||||||||||||||||||
| List<ProjectPage> sortedAndFilteredPageList = [.. pageListSearch.Search(project.pages)]; | ||||||||||||||||||||||||||||||||||||
| sortedAndFilteredPageList.Sort((a, b) => a.visible == b.visible ? string.Compare(a.name, b.name, StringComparison.InvariantCultureIgnoreCase) : a.visible ? -1 : 1); | ||||||||||||||||||||||||||||||||||||
| allPages.data = sortedAndFilteredPageList; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private void BuildPage(ImGui gui) { | ||||||||||||||||||||||||||||||||||||
| float usedHeaderSpace = gui.statePosition.Y; | ||||||||||||||||||||||||||||||||||||
| var pageVisibleSize = size; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -305,13 +340,15 @@ private void BuildPage(ImGui gui) { | |||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public ProjectPage AddProjectPage(string name, FactorioObject? icon, Type contentType, bool setActive, bool initNew) { | ||||||||||||||||||||||||||||||||||||
| public ProjectPage AddProjectPage(String name, FactorioObject? icon, Type contentType, bool setActive, bool initNew) { | ||||||||||||||||||||||||||||||||||||
| ProjectPage page = new ProjectPage(project, contentType) { name = name, icon = icon }; | ||||||||||||||||||||||||||||||||||||
| if (initNew) { | ||||||||||||||||||||||||||||||||||||
| page.content.InitNew(); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| project.RecordUndo().pages.Add(page); | ||||||||||||||||||||||||||||||||||||
| // Ensure any visible page lists are updated immediately | ||||||||||||||||||||||||||||||||||||
| UpdatePageList(); | ||||||||||||||||||||||||||||||||||||
| if (setActive) { | ||||||||||||||||||||||||||||||||||||
| SetActivePage(page); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -543,6 +580,12 @@ public bool ShowPseudoScreen(PseudoScreen screen) { | |||||||||||||||||||||||||||||||||||
| if (topScreen == null) { | ||||||||||||||||||||||||||||||||||||
| Ui.DispatchInMainThread(x => fadeDrawer.CreateDownscaledImage(), null); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (pagesDropDown != null) { | ||||||||||||||||||||||||||||||||||||
| pagesDropDown.Close(); | ||||||||||||||||||||||||||||||||||||
| pagesDropDown = null; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| project.undo.Suspend(); | ||||||||||||||||||||||||||||||||||||
| screen.Rebuild(); | ||||||||||||||||||||||||||||||||||||
| pseudoScreens.Insert(0, screen); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ | |
| ---------------------------------------------------------------------------------------------------------------------- | ||
| Version: | ||
| Date: | ||
| Features: | ||
| - Add Right-click option to show the Page Search dropdown pinned to keep it open. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You read my mind 😉 |
||
| Fixes: | ||
| - Fix rendering of multi-icon technologies (e.g. shooting speed techs) | ||
| - Add simplified support for debug.getinfo(), only returns short_src. Fixes #455, #504. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go in
ProjectPreferencesinstead. I haven't added a comment about this yet, but Preferences is for things that don't require the solver to run again, and Settings is for things that do.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for catching that.
This info should go to the javadoc. I'll make a ticket for that just to not forget.