Commit graph

36 commits

Author SHA1 Message Date
Andreas Kling
3bccd99fe9 LibGUI: Add TreeView::expand_all_parents_of(ModelIndex)
This does exactly what it sounds like. :^)
2020-09-18 21:29:01 +02:00
Andreas Kling
f69281573e LibGUI: Double-clicking on a TreeView item should set cursor
Don't just set the selection, set the cursor.
2020-09-16 16:37:28 +02:00
Andreas Kling
95b6c98435 LibGUI: Fix TreeView scrolling to top when clicking sub-items
This code was confusing two different versions of scroll_into_view that
were getting mixed up due to member function shadowing.

Adding an "override" to the subclass declaration exposed the problem.

With this fixed, we no longer lose our scroll position wildly when
using the mouse to select TreeView items.
2020-09-16 16:37:28 +02:00
Andreas Kling
9cf37901cd LibGUI: Add a cursor to AbstractView, separate from the selection
Views now have a cursor index (retrievable via cursor_index()) which
is separate from the selection.

Until now, we've been using the first entry in the selection as
"the cursor", which gets messy whenever you want to select more than
one index in the model.

When setting the cursor, the selection is implicitly updated as well
to maintain the old behavior (for the most part.)

Going forward, this will make it much easier to implement things like
shift-select (extend selection from cursor) and such. :^)
2020-08-27 18:36:31 +02:00
Andreas Kling
0b9d765f6b LibGUI: Add AbstractView::move_cursor() and share some movement logic
A view can now be told to move its cursor in one of multiple directions
as specified by the CursorMovement enum.

View subclasses can override move_cursor(CursorMovement) to implement
their own cursor behavior. By default, AbstractView::move_cursor() is
a no-op.

This patch improves code sharing between TableView and TreeView. :^)
2020-08-27 17:47:19 +02:00
thankyouverycool
0bb2025b69 Base: Create /res/icons/serenity for misc. sized system icons 2020-08-27 15:38:02 +02:00
Andreas Kling
c4347a16cf LibGUI: Make AbstractTableView row height configurable
The row height is per-table, not per-row, but this is still nice.
2020-08-26 20:34:07 +02:00
Andreas Kling
44e371635e LibGUI: Move table view headers into their own widget
This patch introduces the HeaderView class, which is a widget that
implements the column headers of TableView and TreeView.

This greatly simplifies event management in the view implementations
and also makes it much easier to eventually implement row headers.
2020-08-26 00:51:35 +02:00
Andreas Kling
9102b624ac LibGUI+DevTools+Applications: Use ModelIndex::data() in many places
This way you don't have to keep track of which model it came from.
2020-08-16 16:44:09 +02:00
Andreas Kling
96f98b1fc9 LibGUI: Simplify TableCellPaintingDelegate API slightly
No need to pass the Model *and* a ModelIndex, the index knows which
model it belongs to anyway.
2020-08-16 16:44:09 +02:00
Andreas Kling
a1e381a0f8 LibGUI: Move GUI::Model::Role to GUI::ModelRole
This is preparation for using ModelRole in the ModelIndex API.
2020-08-16 16:44:09 +02:00
Andreas Kling
4088beb8eb LibGUI: Remove Model::sibling() since it's the same as index()
... I'm not sure what the idea was here, but since these functions do
the same thing, let's only have index().
2020-08-13 20:18:11 +02:00
thankyouverycool
332f349e07 LibGUI: Fix keybind conflicts in TreeView
Changes the shortcut to expand and collapse subtrees from alt to
ctrl+right/left arrows in TreeView. The current shortcuts conflict
with applications that already have navigation controls bound to alt
like file manager.
2020-07-13 14:27:23 +02:00
thankyouverycool
366d7e6d05 LibGUI: Only report toggled directories once on subtree collapse/expansion
This prevents redundant calls to on_toggle for the same indices when
subtrees are collapsed or expanded.
2020-07-13 14:27:23 +02:00
thankyouverycool
e6ddc7e022 LibGUI: Add missing on_toggle hook to TreeView
Alt+arrow toggles are now captured.
2020-07-10 19:44:18 +02:00
thankyouverycool
cbf3c2caeb LibGUI: Add on_toggle function to TreeView
This adds a function to expose the index and open/close state
of expandible nodes in TreeView.
2020-07-07 13:38:35 +02:00
Andreas Kling
c6c71b0fcc LibGUI: Respect per-index font when computing TreeView item rects
This makes the selected (currently shown in bold) item in HackStudio's
project file view show up at the correct position.
2020-07-04 11:01:43 +02:00
AnotherTest
476ccb2206 LibGUI: Do not recurse into rows with invalid indices
That would cause the traversal to go into an infinite loop.
2020-07-01 11:18:19 +02:00
Andreas Kling
116cf92156 LibGfx: Rename Rect,Point,Size => IntRect,IntPoint,IntSize
This fits nicer with FloatRect,FloatPoint,FloatSize and gives a much
better visual clue about what type of metric is being used.
2020-06-10 10:59:04 +02:00
FalseHonesty
12fe546be9 LibGUI+HackStudio: Fix cursor appearance and crash while debugging
HackStudio uses a TreeView to display the list of current variables
while debugging, and when the program completes, it sets that view's
model to a null model. This would trip an assertion if the TreeView
had something selected at the time, so this patch lessens the
assertion into a simple null check.

Additionally, the cursor would look laggy when moving about the
editor because the code was waiting for a window repaint to update
the cursor's look when it makes more sense to update the cursor
when it actually moves. This change also requires the base
GUI::TextEditor to expose a getter to tell if its currently in a drag
selection.

Finally, requesting a context menu in the line ruler on the side of
the editor would also place/remove breakpoints, which was counter
intuitive, so this requires a left click to modify breakpoint placement.
2020-05-30 10:18:14 +02:00
Andreas Kling
278b307713 LibGUI: Make all views use CenterLeft as the default text alignment
If a model doesn't specify a text alignment for a given field, we now
fall back to CenterLeft. This will look better than Center in the vast
majority of cases.
2020-05-21 19:55:44 +02:00
Andreas Kling
2adb0a07e5 LibGUI: Get rid of Model::ColumnMetadata and always use auto-sizing
Auto-sizing of view columns is now enabled by default. This removes the
last remaining need for ColumnMetadata, so this patch gets rid of it.
2020-05-21 19:55:44 +02:00
Andreas Kling
2e03bded43 LibGUI: Add Model::Role::TextAlignment and remove from ColumnMetadata 2020-05-21 19:55:44 +02:00
Andreas Kling
04187576ff LibGUI: Models should always specify font via Model::Role::Font
This gets rid of one field in ColumnData. The goal is to get rid of all
fields and lose ColumnData entirely.
2020-05-21 19:55:44 +02:00
Andreas Kling
9d9a31384e LibGUI: Allow expand/collapse subtrees in TreeView with Alt+Left/Right
This makes TreeView a lot more keyboard friendly.
2020-05-21 13:36:08 +02:00
DexesTTP
b478c5f86c LibGUI: Properly draw the background of the selected TreeView line
In the TreeView, the background of the selected line (or any background,
really) was only drawn until the frame's width. When the text was larger
than the frame's width, this caused the end of the text to be displayed
without background, making it unreadable if it was white (which is the
default text color for selected lines).

To compute the background width, we have a choice between :
- The inner frame width (the current behaviour which causes the issue)
- The total width of all columns (which causes the background to end
  early if the columns don't cover the full width)

The new algorithm uses the biggest of the above values, which gives us
exactly what we want in all cases :^)

Fixes #2134
2020-05-07 22:13:25 +02:00
Andreas Kling
d17b42b28d LibGUI: Make view widgets fill background by default
Most clients will want background autofill, so let's make it the
default mode.
2020-04-18 21:55:37 +02:00
Andreas Kling
8e4751a963 LibGUI: Add a way for models to update without invalidating indexes
This is really just a workaround to keep SystemMonitor's process table
working right wrt selection retention during resorts (while also doing
full index invalidation on things like ProfileViewer inversion.)

It's starting to feel like the model abstraction is not super great
and we'll need a better approach if we want to actually build some more
dynamic functionality into our views.
2020-04-12 12:03:33 +02:00
Andreas Kling
b4fde72013 LibGUI: Brighten icons when hovering items in item views
View classes now track their hovered item and paint them in a slightly
brighter shade to liven up the user interface. :^)
2020-03-30 19:57:44 +02:00
Andreas Kling
8e8e8c801c LibGUI: Fix broken TreeView rendering with more than two columns
The computation of the tree column x offset was not taking padding into
account. This patch fixes that and collects the logic in a helper.
2020-03-02 23:05:04 +01:00
Tibor Nagy
0086daf9b0 LibGUI: Scroll selected treeview entries into view 2020-02-24 15:12:47 +01:00
Andreas Kling
c5d913970a LibGUI: Remove parent parameter to GUI::Widget constructor 2020-02-23 12:27:53 +01:00
Tibor Nagy
2eb9620415 LibGUI: Improve TreeView keyboard navigation
This commit adds two new behaviour to the key event handler of
the TreeView widget:

Pressing left now jumps to the parent node if the current treenode
is closed or has no children.

Pressing right now jumps to the first children node if the current
treenode is open.
2020-02-21 20:18:44 +01:00
Andreas Kling
2143da6434 LibGUI: Add forwarding header
This patch adds <LibGUI/Forward.h> and uses it a bunch.
It also dragged various header dependency reduction changes into it.
2020-02-16 09:41:56 +01:00
Tibor Nagy
4d95163400 LibGUI: Use inactive selection colors from palette instead of hardcoding them 2020-02-15 18:42:13 +01:00
Andreas Kling
6a9cc66b97 LibGUI: Remove leading G from filenames 2020-02-06 20:33:02 +01:00
Renamed from Libraries/LibGUI/GTreeView.cpp (Browse further)