Commit graph

1531 commits

Author SHA1 Message Date
Andreas Kling
f1e0eb8a25 LibGUI: Round up font sizes in various widget size calculations 2023-03-03 15:23:47 +01:00
Andreas Kling
d0977ac566 LibCore+LibGUI+About: Use String in Core::Version and GUI::AboutDialog
The Core::Version API now returns ErrorOr<String>, and the
GUI::AboutDialog API was adjusted to accommodate this.
2023-03-03 15:23:47 +01:00
Sam Atkins
64eb326f26 LibGUI: Give SeparatorWidget a minimum size
Without this, it can be squished down into nothing, which looks really
odd.
2023-03-01 10:55:20 +01:00
Andreas Kling
544366ff2a LibGUI: Add a simple "recently open files" feature
This feature allows any application to easily install an automatically
updating list of recently open files in a GUI::Menu.

There are three main pieces to this mechanism:

- GUI::Application::set_config_domain(domain): This must be called
  before using the recent files feature. It informs the Application
  object about which config domain to find the relevant RecentFiles
  list under.

- GUI::Menu::add_recently_open_files(callback): This inserts the list
  in a menu. A callback must be provided to handle actually opening
  the recent file in some application-specific way.

- GUI::Application::set_most_recently_open_file(path): This updates
  the list of recently open files, both in the configuration files,
  and in the GUI menu.
2023-02-28 14:39:32 +01:00
Sam Atkins
cac14a3f0a LibGUI: Assign folding regions for GML files
Each {} block is now treated as a folding region, so that they can be
collapsed and expanded in TextEditor, GML Playground, HackStudio, and
anywhere else that uses the syntax highlighter. :^)
2023-02-28 13:23:55 +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
3d25b4eb34 LibGUI: Add folding regions to TextDocument
A `TextDocumentFoldingRegion` represents a region of the document which
the user can collapse/expand to make code easier to navigate.
2023-02-28 13:23:55 +01:00
Sam Atkins
96cf9355b2 LibGUI: Add TextRange::line_count() 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
Tim Ledbetter
cc4184cb47 LibGUI: Don't show non-visible actions in CommandPalette 2023-02-27 13:37:24 +01:00
MacDue
6cf8eeb7a4 LibGfx: Return bool not ErrorOr<bool> from ImageDecoderPlugin::sniff()
Nobody made use of the ErrorOr return value and it just added more
chance of confusion, since it was not clear if failing to sniff an
image should return an error or false. The answer was false, if you
returned Error you'd crash the ImageDecoder.
2023-02-26 19:43:17 +01:00
kleines Filmröllchen
376e7243a9 LibGUI: Use full text width for Label's preferred width
A label would prefer to be exactly as wide as its contained text
requires. This makes min_width: "fit" work better.
2023-02-25 20:49:41 -07:00
Linus Groh
09d40bfbb2 Everywhere: Use _{short_,}string to create Strings from literals 2023-02-25 20:51:49 +01:00
Timothy Flynn
16ec116133 LibGUI: Make Gfx- to text-positioning handle multi-code point glyphs 2023-02-24 20:28:23 +01:00
Humberto Alves
d50b4f3581 LibGUI: Fix Action destructor to unregister itself correctly
Changed the Action destructor to fix an issue where global scoped
actions without shortcuts were not being properly unregistered from the
application. Previously, this could cause crashes when attempting to
open the command palette.
2023-02-23 12:41:47 +00:00
Humberto Alves
2df25f8edf LibGUI: Fix missing parent in LinkLabel open action
Fixed a bug where an action was being registered in the global shortcut
scope by mistake.
2023-02-23 12:41:47 +00: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
Andreas Kling
4b3e229157 LibGfx: Replace Bitmap::invert() with Bitmap::inverted()
The new function return a new bitmap instead of mutating the current
one in place.
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
Tim Ledbetter
c63f70d0fd LibGUI: Allow clipboard items to have no associated data 2023-02-19 01:35:29 +01:00
Sam Atkins
5b77346f53 LibGUI: Allow double-clicking PathBreadcrumbbar buttons to edit path
When viewing a deeply nested path, there may be very little of the
PathBreadcrumbbar itself visible to double-click on. This solves that
by allowing double-clicks on its segment buttons to behave the same.
(With the caveat that it first selects the double-clicked segment.)

In order to make this work, `on_double_click` now takes the modifiers
instead of the MouseEvent. In this case we don't use it so that's fine,
but maybe we should make all mouse callbacks consistently take the
MouseEvent& as a parameter.
2023-02-19 01:09:09 +01:00
Sam Atkins
8f717927f2 LibGUI: Add Button double-click callback 2023-02-19 01:09:09 +01:00
Sam Atkins
f0c2dcdbac LibGUI: Add PathBreadcrumbbar
This Widget wraps both a Breadcrumbbar and a TextBox for editing the
path manually, based heavily on the existing code in FileManager.

Breadcrumbbar itself requires outside code to micro-manage what it does.
This class provides a simpler interface for it: Users don't have to
worry about segments, they just give/receive a string for the current
path.
2023-02-19 01:09:09 +01:00
Sam Atkins
f5cf41eb5d LibGUI+FileManager: Move has_{parent,child}_segment logic into BCB 2023-02-19 01:09:09 +01:00
Sam Atkins
6b66e39df4 LibGUI+Userland: Stop returning Layout from Widget::(try_)set_layout()
Nobody uses this return value any more. It also lets us remove a whole
bunch of `(void)` casts. :^)
2023-02-18 16:56:56 +00:00
Sam Atkins
77ad0fdb07 Userland: Specify margins and spacing in the GUI::Layout constructor 2023-02-18 16:56:56 +00:00
Sam Atkins
9561ec15f4 Userland: Use Widget::add_spacer() everywhere 2023-02-18 16:56:56 +00:00
Sam Atkins
43dddafd16 LibGUI: Allow specifying Layout margins and spacing in the constructor
This is comfier than `my_widget->layout()->set_margins(...)`.
2023-02-18 16:56:56 +00:00
Sam Atkins
ab6ef53247 LibGUI: Add Widget::add_spacer() wrapper
This just calls Layout::try_add_spacer(), but saves you having to access
the Widget's Layout directly.

We verify that the Widget has a Layout, since it would be a programming
error if we tried to do so without one.
2023-02-18 16:56:56 +00:00
Timothy Flynn
8a94c7a7f7 LibGUI: Skip over grapheme clusters on left/right arrow key presses
Currently, if you use the left/right arrow keys to move over a multi-
code point glyph, we will move through that glyph one code point at a
time. This means you can "pause" your movement in the middle of a glyph
and delete a subsection of a grapheme cluster. This now moves the cursor
across the entire cluster.

Visually, we will need to separately track physical and virtual cursor
positions. That is, when you move across a multi-code point glyph, the
visual cursor should only move one position at a time, while a physical
cursor stores the "real" position in terms of number of code points.

This also converts a couple of ints to auto - these are actually size_t,
and are being passed to functions that expect size_t, so let's not cast
them to ints.
2023-02-18 16:54:46 +01:00
FrHun
30309bac1b LibGUI: Force re-layout on Frame thickness changes 2023-02-17 16:25:57 +00:00
FrHun
cb872f5c9a LibGUI: Adjust OpacitySlider min size for consistency
22 is the size usually used for default widget height, like Buttons and
Labels.
2023-02-17 16:25:57 +00:00
FrHun
f1271c7860 LibGUI: Use calculated_preferred_size for Progressbar default size 2023-02-17 16:25:57 +00:00
FrHun
6d79d932f9 LibGUI: Implement calculated sizes for Slider 2023-02-17 16:25:57 +00:00
FrHun
caf6dd5680 LibGUI: Implement calculated sizes for ValueSlider 2023-02-17 16:25:57 +00:00
FrHun
b6d45f9c1f LibGUI: Use calculated_preferred_size in SeparatorWidget 2023-02-17 16:25:57 +00: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
cb96c892cc LibGUI: Add highlighting to UrlBox 2023-02-16 10:47:22 +00:00
Cameron Youell
dad70d8d6e LibGUI: Account for glyph_spacing() in spans 2023-02-16 10:47:22 +00:00
Timothy Flynn
4ab7216827 LibGUI: Use Unicode's text segmentation for traversing word breaks
Note that for traversing words with ctrl+(left or right arrow) on the
keyboard, we want to "skip" some boundaries. Consider the text:

    The ("quick") fox can't jump 32.3 feet, right?

Using "|" to denote word break boundaries, we will have:

    |The| |(|"|quick|"|)| |fox| |can't| |jump| |32.3| |feet|,| |right|?|

When starting at "The" and using ctrl+right to move rightward in this
text, it is unlikely that users will want to break at every single one
of those boundaries. Most text editors, for example, will skip from the
end of "The" to the end of "quick", not breaking at the parentheses or
opening quotation marks.

We try to mimic such desired behavior here. It likely isn't perfect, but
we can improve upon it as we find edge cases.
2023-02-15 12:36:47 +01:00