Commit Graph

178 Commits (jgrpp)

Author SHA1 Message Date
Peter Nelson d683ec0183
Codechange: Move dropdown and slider out of widgets directory. (#12403)
Also shuffle headers to place widget includes near end.

This leaves the widgets directory solely for defining Widget IDs.
2 months ago
Patric Stout a3cfd23cf9
Codechange: rename byte to uint8_t (#12308) 3 months ago
Rubidium 86cb184eb4 Codechange: use std::source_location over __FILE__ and __LINE__ for WindowDesc 3 months ago
Peter Nelson 0ce30d05c8 Codechange: Add method to replace the content of a dropdown menu.
If necessary the dropdown list window will be resized and scrollbar enabled/disabled.
4 months ago
Peter Nelson 4c44e1eae0 Codechange: Add parameter to persist dropdown menus.
If a dropdown menu is set to persist, it will not close when an item is selected. It will close as normal if the window loses focus.

Closing the list is the responsibility of the caller.
4 months ago
Peter Nelson 7737aa6640 Codechange: Make all NWidgetPart arrays constexpr.
This ensures that the arrays are not created at runtime and prevents using non-constexpr values.
5 months ago
Peter Nelson a0dfb76e34 Codechange: Replace mishmash of types for widget index with WidgetID.
Indices were stored as int, but often passed around as uint/uint8_t and casts.

Now they should all use WidgetID.
5 months ago
Peter Nelson a29766d6cc Codechange: Move dropdown list size and position calculation to window.
This simplifies initialization of DropdownWindow, as instead of both the caller code and the class needing to know about list sizes and available space, only the DropdownWindow needs to know.
6 months ago
Peter Nelson f1cceb43a1 Codechange: Move initialization of DropdownWindow members. 6 months ago
Peter Nelson 52b121942b Codechange: DropdownWindow's selected_index is not actually an index. 6 months ago
Peter Nelson 60565da8f9
Codechange: Add specific WidgetDimension for dropdown list window. (#11554)
This avoids contorting fullbevel dimensions.
6 months ago
Peter Nelson 89461b5561
Codechange: Don't highlight unselectable dropdown item. (#11553) 6 months ago
Peter Nelson 49532914dd Change: Use CRTP-mixins to compose dropdown list items.
This allows list items to built from component parts as required, and additional
functionality is added:

* Icons and text can be positioned at the start or end of the space (templated.)
* Font size of text can be changed (templated.)
* Palette of sprites can be set (runtime.)
6 months ago
Peter Nelson 5489b9fc0c Codechange: Undo #11447, drop down list divider lines are now explicit. 6 months ago
Peter Nelson c18a1494b7
Codechange: Remove FONT_HEIGHT_... macros. (#11481)
These make it look like we're dealing with a constant, but actually each is a call to `GetCharacterHeight(...)`.
7 months ago
Peter Nelson 08dfe35442 Codechange: Move DropDownList height and width calculation to helper. 7 months ago
Peter Nelson 136551408c
Change: Show empty string drop down entries as divider. (#11447) 7 months ago
Peter Nelson 18fb8e153f Codechange: Add __FILE__/__LINE__ of WindowDesc to WindowDesc.
This is to allow unit-tests to produce more useful output.
7 months ago
Peter Nelson d3cb6e1e67
Codechange: Call Widget::SetDirty/SetLowered directly. (#11417)
In these instances we already have the widget to hand, so don't need to look it up by index again.
7 months ago
Peter Nelson 129e98fbab
Fix d42a78f: Some raw drop down list strings may need token processing. (#11400)
Storing the raw string without processing though GetString() caused token
processing to be skipped.
7 months ago
Bernhard Reutner-Fischer ac42dea7b2 Codechange: Remove unused parameter for Height()
DropDownListItem::Height does not need to take an argument so remove it

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
8 months ago
Rubidium f16399f4c9 Codechange: replace x.size() > 0 with !x.empty() 8 months ago
Peter Nelson fd6f1e844a
Codechange: Avoid emplace_back(new()) into a unique_ptr. (#11384)
This could theoretically leave an unmanaged pointer in certain circumstances, and directly using
make_unique shows intent.
8 months ago
Peter Nelson f379b31e28 Add: data parameter in Window::Close method.
This allows passing data when closing a window, e.g. to indicate how it was closed.
8 months ago
frosch b6c8f301be Codechange: Silence warnings about intentionally unused parameters. 9 months ago
Peter Nelson e8015e497d Codechange: Use begin/end of nwidget parts of begin/length.
This simplifies processing nwidget parts as, unlike the remaining length, the pointer to the end of the list never changes. This is the same principle as we use(d) for tracking end instead of length for C-style strings.

And this removes 160~ instances of the lengthof() macro.
9 months ago
Rubidium eaae0bb5e7 Codechange: automatic adding of _t to (u)int types, and WChar to char32_t
for i in `find src -type f|grep -v 3rdparty/fmt|grep -v 3rdparty/catch2|grep -v 3rdparty/opengl|grep -v stdafx.h`; do sed 's/uint16& /uint16 \&/g;s/int8\([ >*),;[]\)/int8_t\1/g;s/int16\([ >*),;[]\)/int16_t\1/g;s/int32\([ >*),;[]\)/int32_t\1/g;s/int64\([ >*),;[]\)/int64_t\1/g;s/ uint32(/ uint32_t(/g;s/_uint8_t/_uint8/;s/Uint8_t/Uint8/;s/ft_int64_t/ft_int64/g;s/uint64$/uint64_t/;s/WChar/char32_t/g;s/char32_t char32_t/char32_t WChar/' -i $i; done
11 months ago
PeterN d42a78f3e8
Codechange: Make DropDownListStringItem preformat and remove other implementations. (#11063)
Having to choose between DropDownListStringItem, DropDownListCharStringItem, and DropDownListParamStringItem depending on whether to draw a StringID, a raw string, or a StringID with extra parameters was needlessly complex.

Instead, allow passing a StringID or raw string to DropDownListStringItem. This will preformat the StringID into a raw string, and can therefore accept parameters via the normal SetDParam mechanism.

This also means that strings no longer need to be formatted on every draw.
12 months ago
PeterN b68d56d94d
Fix #11043: Don't choose toolbar dropdown option if focus is lost. (#11044)
Since dropdown menus now get closed if they lose focus, 'instant close' dropdowns (i.e. the toolbar dropdowns) should no longer execute their action to avoid unintended actions.
12 months ago
PeterN ebc451b071
Fix #10987: Double-close of dropdown stopped land-info tool working as default. (#11000)
Clicking and releasing on the query toolbar icon is meant to select the land-info tool.

This did not work as during closing a window, OnFocusLost() is called, which then closes the window again. These two calls toggled the land-info tool one and off in the same action.

Resolve by not calling Window::Close in OnFocusLost() if the window is already closing.
1 year ago
PeterN b49bd86a46
Fix dec7ff6b0c: Dropdowns couldn't be closed by pressing the parent button. (#10954)
Since dropdowns self-close, the detection of re-clicking a dropdown
button no longer worked, as the dropdown is already closed.

Instead set (and then test) a flag on the parent widget to indicate that
the dropdown closed. This method avoids looping windows on every click.
1 year ago
Patric Stout c43a23cea8
Fix: crash when not even a single row fits for dropdowns on low resolution screens (#10934) 1 year ago
Peter Nelson 2e62682f73 Codechange: Close dropdowns by class instead of id. 1 year ago
Peter Nelson 2511649938 Codechange: Use window parent association for dropdowns.
This replaces the separate window class and number properties, and
allows the window system to close dropdowns automatically.
1 year ago
Peter Nelson dec7ff6b0c Fix: Make dropdowns self-close when losing focus. 1 year ago
Peter Nelson d2034d9c38 Codechange: Scrollbar methods now accept size_t.
This clears up a lot of casts from size_t to int.
1 year ago
PeterN a836edd5a7
Codechange: Scrollbar::UpdatePosition() will tell if the position changed. (#10777)
So we don't need to check this manually.
1 year ago
Rubidium c829930440 Codechange: replace strnatcmp with C++ string capable version 1 year ago
Patric Stout 1ba4dcc924 Codechange: migrate all Window-related timers to the new framework
This means we also say goodbye to GUITimers.
1 year ago
Peter Nelson e5af5907ec Change: Make all dropdown lists extend width if necessary.
This removes the auto_width parameter from ShowDropDown(At).
1 year ago
Peter Nelson 5bc9d00735 Cleanup: Let GetStringBoundingBox deal with buffer. 1 year ago
PeterN c962c77306
Fix: Incorrect available height for dropdowns due to unsigned promotion. (#10264)
Dropdowns which are taller than the main window should automatically have
a scrollbar added. This did not work for toolbar dropdown as the location
near the top of the window resulted in an unsigned underflow.
1 year ago
Peter Nelson 890b2666d3 Change: Use scaled WidgetDimensions. 2 years ago
Peter Nelson 6f95e04005 Change: Use Rect helpers for widget drawing.
This replaces repetitive and sometimes unwieldy use of constants.
2 years ago
Peter Nelson 632464a623 Codechange: Use Rect in DropDownListItem::Draw(). 2 years ago
glx22 5799402f7a Codechange: Rename window related DeleteXXX to match new behaviour 3 years ago
glx22 994bf19aef Fix f6d5c01: Delay deletion when closing windows 3 years ago
glx22 e66e25ff71 Fix #9269, f6d5c01: Hide windows without abusing WC_INVALID 3 years ago
frosch f96f113951 Codechange: use IterateFromBack/Front only if the order is important.
Use Iterate if the order does not matter.
3 years ago
Peter Nelson d8e06e590a Codechange: Make GetCurrentRect() conform to usual Rect bounds, and reuse it.
Similar code is already repeated in other locations.
3 years ago