Skip to content

Commit

Permalink
Merge branch 'develop' into infinitesky
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 authored Nov 28, 2024
2 parents 69ba0b6 + 3937555 commit 45ecda5
Show file tree
Hide file tree
Showing 22 changed files with 5,367 additions and 73 deletions.
1 change: 1 addition & 0 deletions docs/about/Authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Myk Taylor myk002
Najeeb Al-Shabibi master-spike
napagokc napagokc
Neil Little nmlittle
Nicholas McDaniel NicksWorld
Nick Rart nickrart comestible
Nicolas Ayala nicolasayala
Nik Nyby nikolas
Expand Down
5 changes: 4 additions & 1 deletion docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Template for new versions:
# Future

## New Tools
- `infinite-sky`: (reinstated, renamed from ``infiniteSky``) tool for automatically creating new z-levels of sky
- `infinite-sky`: (reinstated, renamed from ``infiniteSky``) tool for automatically creating new z-levels of sky to build in
- `forceequip`: (reinstated) Forcibly move items into a unit's inventory

## New Features
- `tweak`: ``realistic-melting``: change melting return for inorganic armor parts, shields, weapons, trap components and tools to stop smelters from creating metal, bring melt return for adamantine in line with other metals to ~95% of forging cost. wear reduces melt return by 10% per level
Expand All @@ -62,6 +63,7 @@ Template for new versions:
- `autobutcher`: don't run a scanning and marking cycle on the first tick of a fortress to allow for all custom configuration to be set first
- `nestboxes`: don't consider eggs to be infertile just because the mother has left the nest; eggs can still hatch in this situation
- `timestream`: adjust the incubation counter on fertile eggs so they hatch at the expected time
- `timestream`: fix potential crash in birthday tracking
- `logistics`: don't ignore rotten items when applying stockpile logistics operations (e.g. autodump, autoclaim, etc.)

## Misc Improvements
Expand All @@ -86,6 +88,7 @@ Template for new versions:
## Lua

- ``dfhack.units``: new function ``setPathGoal``
- ``widgets.TabBar``: updated to allow for horizontal scrolling of tabs when there are too many to fit in the available space

## Removed
- UI focus strings for squad panel flows combined into a single tree: ``dwarfmode/SquadEquipment`` -> ``dwarfmode/Squads/Equipment``, ``dwarfmode/SquadSchedule`` -> ``dwarfmode/Squads/Schedule``
Expand Down
184 changes: 181 additions & 3 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5513,6 +5513,155 @@ The ``EditField`` class also provides the following functions:

Inserts the given text at the current cursor position.

TextArea class
--------------

Subclass of Panel; implements a multi-line text field with features such as
text wrapping, mouse control, text selection, clipboard support, history,
and typical text editor shortcuts.

Cursor Behavior
~~~~~~~~~~~~~~~

The cursor in the ``TextArea`` class is index-based, starting from 1,
consistent with Lua's text indexing conventions.

Each character, including newlines (``string.char(10)``),
occupies a single index in the text content.

Cursor movement and position are fully aware of line breaks,
meaning they count as one unit in the offset.

The cursor always points to the position between characters,
with 1 being the position before the first character and
``#text + 1`` representing the position after the last character.

Cursor positions are preserved during text operations like insertion,
deletion, or replacement. If changes affect the cursor's position,
it will be adjusted to the nearest valid index.

TextArea Attributes:

* ``init_text``: The initial text content for the text area.

* ``init_cursor``: The initial cursor position within the text content.
If not specified, defaults to end of the text (length of ``init_text`` + 1).

* ``text_pen``: Optional pen used to draw the text. Default is ``COLOR_LIGHTCYAN``.

* ``select_pen``: Optional pen used for text selection. Default is ``COLOR_CYAN``.

* ``ignore_keys``: List of input keys to ignore.
Functions similarly to the ``ignore_keys`` attribute in the ``EditField`` class.

* ``on_text_change``: Callback function called whenever the text changes.
The function signature should be ``on_text_change(new_text, old_text)``.

* ``on_cursor_change``: Callback function called whenever the cursor position changes.
Expected function signature is ``on_cursor_change(new_cursor, old_cursor)``.

* ``one_line_mode``: If set to ``true``, disables multi-line text features.
In this mode the :kbd:`Enter` key is not handled by the widget
as if it were included in ``ignore_keys``.
If multiline text (including ``\n`` chars) is pasted into the widget, newlines are removed.

TextArea Functions:

* ``textarea:getText()``

Returns the current text content of the ``TextArea`` widget as a string.
"\n" characters (``string.char(10)``) should be interpreted as new lines

* ``textarea:setText(text)``

Sets the content of the ``TextArea`` to the specified string ``text``.
The cursor position will not be adjusted, so should be set separately.

* ``textarea:getCursor()``

Returns the current cursor position within the text content.
The position is represented as a single integer, starting from 1.

* ``textarea:setCursor(cursor)``

Sets the cursor position within the text content.

* ``textarea:scrollToCursor()``

Scrolls the text area view to ensure that the current cursor position is visible.
This happens automatically when the user interactively moves the cursor or
pastes text into the widget, but may need to be called when ``setCursor`` is
called programmatically.

* ``textarea:clearHistory()``

Clears undo/redo history of the widget.

Functionality
~~~~~~~~~~~~~

The TextArea widget provides a familiar and intuitive text editing experience with baseline features such as:

- Text Wrapping: Automatically fits text within the display area.
- Mouse and Keyboard Support: Standard keys like :kbd:`Home`, :kbd:`End`, :kbd:`Backspace`, and :kbd:`Delete` are supported,
along with gestures like double-click to select a word or triple-click to select a line.
- Clipboard Operations: copy, cut, and paste,
with intuitive defaults when no text is selected.
- Undo/Redo: :kbd:`Ctrl` + :kbd:`Z` and :kbd:`Ctrl` + :kbd:`Y` for quick changes.
- Additional features include advanced navigation, line management,
and smooth scrolling for handling long text efficiently.

Detailed list:

- Cursor Control: Navigate through text using arrow keys (Left, Right, Up,
and Down) for precise cursor placement.
- Mouse Control: Use the mouse to position the cursor within the text,
providing an alternative to keyboard navigation.
- Text Selection: Select text with the mouse, with support for replacing or
removing selected text.
- Select Word/Line: Use double click to select current word, or triple click to
select current line.
- Move By Word: Use :kbd:`Ctrl` + :kbd:`Left` and :kbd:`Ctrl` + :kbd:`Right` to
move the cursor one word back or forward.
- Line Navigation: :kbd:`Home` moves the cursor to the beginning of the current
line, and :kbd:`End` moves it to the end.
- Jump to Beginning/End: Quickly move the cursor to the beginning or end of the
text using :kbd:`Ctrl` + :kbd:`Home` and :kbd:`Ctrl` + :kbd:`End`.
- Longest X Position Memory: The cursor remembers the longest x position when
moving up or down, making vertical navigation more intuitive.
- New Lines: Easily insert new lines using the :kbd:`Enter` key, supporting
multiline text input.
- Text Wrapping: Text automatically wraps within the editor, ensuring lines fit
within the display without manual adjustments.
- Scrolling for long text entries.
- Backspace Support: Use the backspace key to delete characters to the left of
the cursor.
- Delete Character: :kbd:`Delete` deletes the character under the cursor.
- Delete Current Line: :kbd:`Ctrl` + :kbd:`U` deletes the entire current line
where the cursor is located.
- Delete Rest of Line: :kbd:`Ctrl` + :kbd:`K` deletes text from the cursor to
the end of the line.
- Delete Last Word: :kbd:`Ctrl` + :kbd:`W` removes the word immediately before
the cursor.
- Select All: Select entire text by :kbd:`Ctrl` + :kbd:`A`.
- Undo/Redo: Undo/Redo changes by :kbd:`Ctrl` + :kbd:`Z` / :kbd:`Ctrl` +
:kbd:`Y`.
- Clipboard Operations: Perform OS clipboard cut, copy, and paste operations on
selected text, allowing you to paste the copied content into other
applications.
- Copy Text: Use :kbd:`Ctrl` + :kbd:`C` to copy selected text.
- copy selected text, if available
- if no text is selected it copy the entire current line, including the
terminating newline if present
- Cut Text: Use :kbd:`Ctrl` + :kbd:`X` to cut selected text.
- cut selected text, if available
- if no text is selected it will cut the entire current line, including the
terminating newline if present
- Paste Text: Use :kbd:`Ctrl` + :kbd:`V` to paste text from the clipboard into
the editor.
- replace selected text, if available
- If no text is selected, paste text in the cursor position

Scrollbar class
---------------

Expand Down Expand Up @@ -6194,9 +6343,16 @@ TabBar class
------------

This widget implements a set of one or more tabs to allow navigation between groups
of content. Tabs automatically wrap on the width of the window and will continue
rendering on the next line(s) if all tabs cannot fit on a single line.

of content.

:wrap: If true, tabs automatically wrap on the width of the window and will
continue rendering on the next line(s) if all tabs cannot fit on a single line.
If false, tabs will be truncated and can be scrolled using ``scroll_key``
and ``scroll_key_back``, mouse wheel or by clicking on the scroll labels
that will automatically appear on the left and right sides of the tab bar
as needed. When clicking on a tab or using ``key`` or ``key_back`` to switch tabs,
the selected tab will be scrolled into view if it is not already visible.
Defaults to true.
:key: Specifies a keybinding that can be used to switch to the next tab.
Defaults to ``CUSTOM_CTRL_T``.
:key_back: Specifies a keybinding that can be used to switch to the previous
Expand All @@ -6222,6 +6378,28 @@ rendering on the next line(s) if all tabs cannot fit on a single line.
itself as the second. The default implementation, which will handle most
situations, returns ``self.active_tab_pens``, if ``self.get_cur_page() == idx``,
otherwise returns ``self.inactive_tab_pens``.
:scroll_key: Specifies a keybinding that can be used to scroll the tabs to the right.
Defaults to ``CUSTOM_ALT_T``.
:scroll_key_back: Specifies a keybinding that can be used to scroll the tabs to the left.
Defaults to ``CUSTOM_ALT_Y``.
:scroll_left_text: The text to display on the left scroll label.
Defaults to "<<<".
:scroll_right_text: The text to display on the right scroll label.
Defaults to ">>>".
:scroll_label_text_pen: The pen to use for the scroll label text.
Defaults to ``Label`` default.
:scroll_label_text_hpen: The pen to use for the scroll label text when hovered.
Defaults to ``scroll_label_text_pen`` with the background
and foreground colors swapped.
:scroll_step: The number of units to scroll tabs by.
Defaults to 10.
:fast_scroll_multiplier: The multiplier for fast scrolling (holding shift).
Defaults to 3.
:scroll_into_view_offset: After a selected tab is scrolled into view, this offset
is added to the scroll position to ensure the tab is
not flush against the edge of the tab bar, allowing
some space for the user to see the next tab.
Defaults to 5.

Tab class
---------
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/forceequip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ forceequip

.. dfhack-tool::
:summary: Move items into a unit's inventory.
:tags: unavailable
:tags: adventure fort animals items military units

This tool is typically used to equip specific clothing/armor items onto a dwarf,
but can also be used to put armor onto a war animal or to add unusual items
Expand Down
2 changes: 1 addition & 1 deletion library/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void get_commands(color_ostream &con, std::vector<std::string> &commands) {
static bool try_autocomplete(color_ostream &con, const std::string &first, std::string &completed)
{
std::vector<std::string> commands, possible;

get_commands(con, commands);
for (auto &command : commands)
if (command.substr(0, first.size()) == first)
possible.push_back(command);
Expand Down
5 changes: 0 additions & 5 deletions library/include/DataDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ distribution.

#include "BitArray.h"

// Stop some MS stupidity
#ifdef interface
#undef interface
#endif

typedef struct lua_State lua_State;

/*
Expand Down
1 change: 1 addition & 0 deletions library/include/DataFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ distribution.
#include <map>
#include <type_traits>

#include "ColorText.h"
#include "DataIdentity.h"
#include "LuaWrapper.h"

Expand Down
1 change: 1 addition & 0 deletions library/include/modules/DFSDL.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "Error.h"
#include "Export.h"
#include "ColorText.h"

Expand Down
2 changes: 1 addition & 1 deletion library/lua/dfhack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ end
---@nodiscard
---@param self string
---@param width number
---@param opts {return_as_table:boolean, keep_trailing_spaces:boolean}
---@param opts {return_as_table:boolean, keep_trailing_spaces:boolean, keep_original_newlines:boolean}
---@return string|string[]
function string:wrap(width, opts)
width, opts = width or 72, opts or {}
Expand Down
1 change: 1 addition & 0 deletions library/lua/gui/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ FilteredList = require('gui.widgets.filtered_list')
TabBar = require('gui.widgets.tab_bar')
RangeSlider = require('gui.widgets.range_slider')
DimensionsTooltip = require('gui.widgets.dimensions_tooltip')
TextArea = require('gui.widgets.text_area')

Tab = TabBar.Tab
makeButtonLabelText = Label.makeButtonLabelText
Expand Down
Loading

0 comments on commit 45ecda5

Please sign in to comment.