Commit graph

199 commits

Author SHA1 Message Date
Jelle Raaijmakers
f391ccfe53 LibGfx+Everywhere: Change Gfx::Rect to be endpoint exclusive
Previously, calling `.right()` on a `Gfx::Rect` would return the last
column's coordinate still inside the rectangle, or `left + width - 1`.
This is called 'endpoint inclusive' and does not make a lot of sense for
`Gfx::Rect<float>` where a rectangle of width 5 at position (0, 0) would
return 4 as its right side. This same problem exists for `.bottom()`.

This changes `Gfx::Rect` to be endpoint exclusive, which gives us the
nice property that `width = right - left` and `height = bottom - top`.
It enables us to treat `Gfx::Rect<int>` and `Gfx::Rect<float>` exactly
the same.

All users of `Gfx::Rect` have been updated accordingly.
2023-05-23 12:35:42 +02:00
thankyouverycool
02d94a303c Base+Userland: Apply Human Interface Guidelines to Object text
Corrects a slew of titles, buttons, labels, menu items and status bars
for capitalization, ellipses and punctuation.

Rewords a few actions and dialogs to use uniform language and
punctuation.
2023-05-23 05:59:49 +02:00
thankyouverycool
02a9e5d3f6 LibGUI+Userland: Improve error and font handling for InputBox
Adds fallible factories, ports DeprecatedString, and rebuilds the
layout to accomodate system font changes.
2023-04-18 10:05:21 +02:00
thankyouverycool
9c2bcffe83 LibGUI: Improve calculated_min_size() for single-line TextEditor
TextBox now shrinks to fit the current font based on preferred line
height, maintaining its historical minimum size of 40x22
2023-04-18 10:05:21 +02:00
Sam Atkins
4b29702fee LibGUI: Add gutter indicators to TextEditor :^)
HackStudio's Editor has displayed indicators in its gutter for a long
time, but each required manual code to paint them in the right place
and respond to click events. All indicators on a line would be painted
in the same location. If any other applications wanted to have gutter
indicators, they would also need to manually implement the same code.

This commit adds an API to GUI::TextEditor so it deals with these
indicators. It makes sure that multiple indicators on the same line
each have their own area to paint in, and provides a callback for when
one is clicked.

- `register_gutter_indicator()` should be called early on. It returns a
  `GutterIndicatorID` that is then used by the other methods.
  Indicators on a line are painted from right to left, in the order
  they were registered.
- `add_gutter_indicator()` and `remove_gutter_indicator()` add the
  indicator to the given line.
- `clear_gutter_indicators()` removes a given indicator from every line.
- The `on_gutter_click` callback is called whenever the user clicks on
  the gutter, but *not* on an indicator.
2023-03-31 12:09:40 +02:00
Sam Atkins
ce9b9a4f20 LibGUI: Rename TextEditor::LineVisualData -> LineData
This is going to hold other per-line data too.
2023-03-31 12:09:40 +02:00
Sam Atkins
03571b1fa9 LibGUI: Extract repeated code for populating TextEditor per-line data 2023-03-31 12:09:40 +02:00
Cameron Youell
c048cf2004 Libraries: Convert DeprecatedFile usages to LibFileSystem 2023-03-24 10:58:43 +00:00
Karol Kosek
ee5838084d LibCore+Userland: Add DEPRECATED infix to REGISTER_STRING_PROPERTY macro 2023-03-16 09:58:42 +01:00
Sam Atkins
6d8f046fd0 LibGfx+Userland: Make TextAttributes::underline_style optional
Rather than having a style AND a field saying whether to use the style,
just make the style Optional.
2023-03-15 14:55:49 +01:00
Tim Schumacher
ae51c1821c Everywhere: Remove unintentional partial stream reads and writes 2023-03-13 15:16:20 +00:00
Tim Schumacher
d5871f5717 AK: Rename Stream::{read,write} to Stream::{read_some,write_some}
Similar to POSIX read, the basic read and write functions of AK::Stream
do not have a lower limit of how much data they read or write (apart
from "none at all").

Rename the functions to "read some [data]" and "write some [data]" (with
"data" being omitted, since everything here is reading and writing data)
to make them sufficiently distinct from the functions that ensure to
use the entire buffer (which should be the go-to function for most
usages).

No functional changes, just a lot of new FIXMEs.
2023-03-13 15:16:20 +00:00
Andreas Kling
359d6e7b0b Everywhere: Stop using NonnullOwnPtrVector
Same as NonnullRefPtrVector: weird semantics, questionable benefits.
2023-03-06 23:46:35 +01:00
Andreas Kling
b71c7a6e44 Userland: Use Font::pixel_size_rounded_up() instead of glyph_height()
The only remaining clients of this API are specific to bitmap fonts and
editing thereof.
2023-03-04 00:29:38 +01:00
Timothy Flynn
4463de3d10 LibGUI: Compute syntax-highlighted visual text spans using float rects
For vector fonts in particular, we need to take care to compute offsets
using floating point math. For example, with Berkeley Mono at font size
16, with syntax highlighting enabled, we are currently truncating these
offsets to integers. This results in a leftward-drift when we paint the
text.

This changes the rect in which we paint syntax-highlighted text spans to
a float rect. As we traverse the spans, we now no longer truncate any of
the text offsets, and we draw the text in the correct positions.

This is likely not a complete solution. TextEditor blindly casts ints to
floats all over, and we will want to make all of these (hundred+) float-
aware. But this should be a step in the right direction and makes vector
fonts immediately more comfortable to use.
2023-03-03 22:49:12 +01:00
Sam Atkins
d169af117d LibSyntax+LibGUI: Let syntax highlighters assign folding regions 2023-02-28 13:23:55 +01:00
Sam Atkins
92b128e20a LibGUI: Support folding regions in TextEditor 2023-02-28 13:23:55 +01:00
Sam Atkins
640f6f476c LibGUI: Store Utf32Views in TextEditor::LineVisualData
Previously this stored the position of each visual line break, meaning
that all the text would always be painted. By storing each visual
line's Utf32View, we can skip over parts of the text, such as for code
folding.
2023-02-28 13:23:55 +01:00
Sam Atkins
b5e1babc26 LibGUI: Create TextAttributes for unspanned text once, not repeatedly
Also, stop unnecessarily creating a RefPtr for the unspanned font - just
use `font()`, which returns a reference.
2023-02-28 13:23:55 +01:00
Sam Atkins
e8b7bdbd57 LibGUI: Skip painting TextEditor spans that end on previous lines
This only becomes a problem with folding, since arbitrary lines may be
invisible, meaning we try to apply a span for an invisible line N, on
line N+X instead, causing occasional crashes.

This check means we can remove the loop that skips spans occurring at
the end of the line.
2023-02-28 13:23:55 +01:00
Timothy Flynn
4edd8e8c5e LibGUI: Ensure the "End" key sets the cursor to the visual line end
We are currently setting the physical mouse position to the visual
cursor content location. In a line containing only a multi-code point
emoji, this would set the cursor to column 1 rather than however many
code points there are.
2023-02-27 09:36:37 -05:00
Timothy Flynn
16ec116133 LibGUI: Make Gfx- to text-positioning handle multi-code point glyphs 2023-02-24 20:28:23 +01:00
Timothy Flynn
fdf090a299 LibGUI: Wrap words at word break boundaries and don't break up emoji
We will currently only wrap "words" at ASCII spaces and, when wrapping,
will break up multi-code point emoji. This changes word wrapping to
behave as follows:

When the wrapping mode is "anywhere", use the iterator-based font width
computation overload. This will compute the width of multi-code point
emoji, whereas we currently only handle single-code point.

When the wrapping mode is "word", use the Unicode word segmentation
boundaries to break lines.
2023-02-22 15:24:16 +00:00
Timothy Flynn
2eb2207f50 LibGUI: Convert mouse events from a visual to a physical position
When clicking a position within a TextEditor, we should interpret that
position as a visual location. That location should be converted to a
"physical" location before using it to set the physical cursor position.

For example, consider a document with 2 emoji, each consisting of 3 code
points. Visually, these will occupy 2 columns. When a mouse click occurs
between these columns, we need to convert the visual column number 1 to
the physical column number 3 when storing the new cursor location.
2023-02-22 10:14:36 +01:00
Andreas Kling
faa1a09042 LibGUI: Fix const-correctness issues 2023-02-21 00:54:04 +01:00
Sam Atkins
e54a03d497 LibGUI: Use Gfx::Font::bold_variant() instead of a manual lookup
This has the nice side-effect of being cached in the Font, instead of
being repeatedly looked up in the FontDatabase.
2023-02-20 18:41:47 +01:00
Sam Atkins
efd56cda6a LibGUI: Use a while loop for iterating text spans 2023-02-20 18:41:47 +01:00
Sam Atkins
04deb81f71 LibGUI: Validate TextDocument spans when merging them, not when painting
TextDocument::merge_span_collections() automatically makes sure that the
spans are valid, move forwards, are in order, and do not overlap. This
means we don't have to check these things every time TextEditor paints
the document.

merge_span_collections() now does these checks instead. I am not certain
they are still useful, but someone in the past certainly did. I have
modified them to take advantage of the operator overloads and Formatter
that we now have.
2023-02-20 18:41:47 +01:00
Sam Atkins
54d45d4ac6 LibGUI: Add and use TextEditor::fixed_elements_width()
We were manually adding together the gutter and ruler widths in several
places. Soon we'll have a third section that needs to be included in
this width, so let's abstract it now.
2023-02-20 18:41:47 +01:00
Sam Atkins
1a5159df73 LibGUI+HackStudio: Simplify TextEditor gutter & ruler calculations
- Make gutter/ruler_content_rect() return rectangles relative to the
  TextEditor widget.
- Re-order painting code to translate the Painter after the gutter/ruler
  has been painted, to use those coordinates.
- Consistently put gutter before ruler in code, because that's the order
  they physically appear.
2023-02-20 18:41:47 +01:00
Fausto Tommasi
f7458b3e17 LibGUI: Update TextEditor to delete emoji based on gbp cluster
Updated TextDocument and TextEditor to use calls to
`find_grapheme_segmentation_boundary` in order to make "correct-feeling"
deletions on backspace and delete keys being pressed
2023-02-17 07:50:09 -05:00
Cameron Youell
dad70d8d6e LibGUI: Account for glyph_spacing() in spans 2023-02-16 10:47:22 +00:00
Sam Atkins
2dc1682274 LibGUI: Take gutter into account when measuring TextEditor content area 2023-02-13 16:54:56 +00:00
Sam Atkins
6905622b41 LibGUI: Don't show caret cursor when hovering TextEditor's gutter 2023-02-13 16:54:56 +00:00
Sam Atkins
69333e5dbd LibGUI: Combine wrapping/non-wrapping TextEditor code paths
The `is_wrapping_enabled()` paths function just fine when wrapping is
disabled. We already calculate `m_line_visual_data`. The only reason to
use a special path is for speed, since you can skip some steps if you
know each line is only 1 line high visually.

However, with code-folding being added, we can't make assumptions about
line height because a line could be hidden and have an effective height
of 0px. So `text_position_at_content_position()` always needs to loop
through the lines to see what our position is, and that function always
needs to be called to calculate the real position.
2023-02-13 16:54:56 +00:00
Sam Atkins
7aef096f85 LibGUI: Fix typo in span_consumed variable 2023-02-13 16:54:56 +00:00
Tim Schumacher
606a3982f3 LibCore: Move Stream-based file into the Core namespace 2023-02-13 00:50:07 +00:00
Tim Schumacher
d43a7eae54 LibCore: Rename File to DeprecatedFile
As usual, this removes many unused includes and moves used includes
further down the chain.
2023-02-13 00:50:07 +00:00
Lucas CHOLLET
db80425a65 LibGUI: Remove the Core::File overload of write_to_file()
One less usage of `Core::File`, yay!
2023-02-11 14:20:26 +00:00
Lucas CHOLLET
107e15c5bc LibGUI: Base write_to_file(StringView path) on the stream overload
`write_to_file(StringView path)` was based on the `Core::File` overload.
The return type also changed from `bool` to `ErrorOr<void>` to ease
error propagation.
2023-02-11 14:20:26 +00:00
Aliaksandr Kalenik
1f4106842d LibGfx: Pass font width to FontDatabase::get()
Width need to be passed to `FontDatabase::get()` to resolve font name
unambiguously.
2023-02-05 08:06:06 +00:00
Tim Schumacher
82a152b696 LibGfx: Remove try_ prefix from bitmap creation functions
Those don't have any non-try counterpart, so we might as well just omit
it.
2023-01-26 20:24:37 +00:00
Sam Atkins
a8cf0c9371 LibCore+Userland: Make Core::Timer::create_single_shot() return ErrorOr
clang-format sure has some interesting opinions about where to put a
method call that comes after a lambda. :thonk:
2023-01-12 11:25:51 +01:00
Lucas CHOLLET
cf1eea27d3 LibGUI: Add TextEditor::write_to_file(Core::Stream::File&)
This overload use the `Core::Stream` API instead of the now deprecated
one `Core::File`.
2023-01-07 19:53:35 +00:00
Andrew Kaster
ddf348daeb Everywhere: Use ElapsedTimer::elapsed_time() for comparisons
Simplify a lot of uses of ElapsedTimer by converting the callers to
elapsed_time from elapsed, as the AK::Time returned is better for unit
conversions and comparisons against constants.
2023-01-07 14:51:04 +01:00
Andreas Kling
2a61d66b0a LibGfx: Make Font::preferred_line_height() more correct
Return a float, and fix a bogus calculation of ascender + descender.
2023-01-06 12:02:20 +01:00
thankyouverycool
804baa42f9 LibGUI: Standardize automatic scrolling in TextEditor+GlyphMapWidget
Both widgets now make use of their base class's scrolling timer and
now always accept drag selection updates on mousemove_event().

This guarantees much snappier feeling selections when actively moving
the mouse.
2022-12-26 09:27:19 +01:00
thankyouverycool
5b02e6a46b LibGUI: Handle Enter+Leave events for automatic cursor trackers
Previously, automatic cursor tracking widgets consumed all mouse
events but did not update their own hover state while active, meaning
Enter and Leave events were not being dispatched.

Fixes TextEditor's automatic selection scroll timer failing to stop
and start while autotracking. Its manual workaround in mousedown
is no longer needed.
2022-12-26 09:27:19 +01:00
Snow
0049dfd717 LibGUI+TextEditor: Add a relative line number option for TextEditor
This adds an option for displaying relative line numbers in the ruler,
the line numbers are still absolute by default.
2022-12-12 16:02:06 +00:00
Snow
2f8c7b1b30 LibGUI: Add shortcut for inserting new line
This adds shortcut for inserting a new empty indented line
above/below current cursor position.

- <Ctrl-Return> for inserting line below.
- <Ctrl-Shift-Return> for inserting line above.
2022-12-11 19:47:42 +00:00