Commit graph

174 commits

Author SHA1 Message Date
Olivier Goffart
59707f068c add a enabled property on the line edit 2020-11-02 18:20:01 +01:00
Olivier Goffart
aabd13b5a9 Adjust the ugly style default stretches 2020-10-27 07:24:04 +01:00
Olivier Goffart
47be71e16d Introduce layout stretching 2020-10-26 16:40:35 +01:00
Simon Hausmann
a98da9ecc9 Draw rounded rectangles with anti-aliasing
Draw rounded rectangles using a distance function. This removes the need
to use lyon to tesselate the rounded corners and as a bonus it gives
anti-aliased borders.
2020-10-21 09:35:35 +02:00
Simon Hausmann
853a74043f Add support for moving/selecting to beginning/end of line 2020-10-13 13:20:26 +02:00
Simon Hausmann
2d387d4c3b Fix hang when pressing the right arrow to go back the end of text input
str::is_char_boundary() returns true at text.len() but beyond that it'll return false.
2020-10-13 13:20:26 +02:00
Simon Hausmann
a37d42fa0e Add an init function to the Item vtable
This will be called by the run-time and will allow items to set up
bindings that rely on internals that should not be exposed to the
compiler/runtime.
2020-10-12 16:49:44 +02:00
Simon Hausmann
633275c3cd Fix formatting 2020-09-29 14:46:05 +02:00
Simon Hausmann
c1d1dc8193 Make the flickable clip by default 2020-09-29 14:41:40 +02:00
Olivier Goffart
6662e1ff00 Proper Scrollbar on the native style 2020-09-28 18:13:13 +02:00
Simon Hausmann
ec91e4c933 Make ComponentWindow::set_focus_item ffi friendly
Take a Pin<VRef<ItemVTable>>, which is easier to map from C++ than a generic method...
2020-09-28 15:59:29 +02:00
Simon Hausmann
acb6eddeaf Expose the focused property on TextInput correctly
As per #55 introduce a has_focus property on the TextInput.
2020-09-25 11:22:32 +02:00
Simon Hausmann
e5dfb3a4c0 Implement basic focus handling
Similar to the mouse_grabber, we use a VisitChildrenResult field to
track the focus item within a component. Unlike the mouse grabber
however, it is set/cleared using dedicated focus events.

The key event now routes the key event directly to the focus item.

The focus can be requested via set_focus_item on a window, which the
TextItem does.
2020-09-25 10:43:47 +02:00
Simon Hausmann
2b76e9277a Prepare for allowing an item mouse handler to request focus
In the future the TextInput will request focus on mouse click,for
example.

Pass the outer-most component through to ItemVTable's input_event.

For the purpose of disambiguating this component from any nested
component instantiated by a repeater or so, it's called the
app_component.

The ComponentVTable takes a reference to a ComponentRefPin instead of a
ComponentRefPin by value, as the vtable macro gets confused otherwise
and thinks it's a self argument.
2020-09-25 10:06:15 +02:00
Olivier Goffart
0cb827a901 Two ways binding with optimized public property in the interpreter 2020-09-25 09:50:03 +02:00
Simon Hausmann
b5d7adef7d Fix mouse event handling with multiple text input elements
Don't grab the mouse, otherwise clicking between text inputs will require
multiple clicks.
2020-09-25 08:27:54 +02:00
Simon Hausmann
7ca66d62b9 Fix crash in TextInput when deleting a left-directed selection
When selecting to the left, the anchor remains to the right of the cursor.
When deleting such a selection, we fetch the cursor and anchor using a helper
method, which ensures that the anchor is to the left of the cursor.
Finally when setting the cursor then to the anchor, we need to also
set the anchor, since both were swapped.

This also add an automated test for this scenario.
2020-09-23 17:33:09 +02:00
Simon Hausmann
babfd17813 Add support for copy & paste in TextInput 2020-09-23 11:46:38 +02:00
Simon Hausmann
7238e0d01c Minor TextInput cleanup
Treat the cursor and anchor positions as usize within functions, only store it
as i32 in the Property<>.
2020-09-23 11:02:50 +02:00
Simon Hausmann
49edd69a3a Fix multi-byte handling hit testing
Return a byte offset within the string for the hit test in TextInput.
2020-09-22 18:43:00 +02:00
Simon Hausmann
adfadd12fa TextInput cleanup
Reduce the amount of char vs. byte offset fiddling
2020-09-22 18:29:21 +02:00
Olivier Goffart
fa55c1f015 Flickable: properly grab the mouse
otherwise the Flickable think the mouse stay pressed forever if it is released while outside of it.
2020-09-22 17:39:51 +02:00
Simon Hausmann
722fce61f2 Add support for selecting text with the mouse to TextInput 2020-09-22 15:37:54 +02:00
Simon Hausmann
141224bf28 Minor fixes for entering text in TextInput
Delete any selected text and update anchor and cursor after insertion.
2020-09-22 15:35:40 +02:00
Simon Hausmann
bf970b3ace Fix build without rtti 2020-09-22 13:59:03 +02:00
Simon Hausmann
4f25b0942f Draw text selections 2020-09-21 18:43:59 +02:00
Simon Hausmann
4a6a617ca5 Add logic for selection handling by cursor keys and shift
The mouse handling is still missing as well as the selection rendering.
2020-09-21 15:12:27 +02:00
Simon Hausmann
e3eeb5e23d Don't let backspace at the beginning of text delete it 2020-09-21 15:04:20 +02:00
Simon Hausmann
bb81c99ddb Add support for keyboard modifiers in the internal key event 2020-09-21 14:30:16 +02:00
Simon Hausmann
b857eb4671 Add an accepted signal to TextInput and LineEdit 2020-09-21 13:18:53 +02:00
Simon Hausmann
34eae40814 Allow moving the text cursor to the end of the input 2020-09-21 13:15:53 +02:00
Simon Hausmann
083cdd6653 Added a crude backspace and delete handler in TextInput 2020-09-18 18:18:44 +02:00
Simon Hausmann
ade78875ea Fix TextInput::move_cursor to respect character boundaries 2020-09-18 18:13:31 +02:00
Simon Hausmann
0d751e6627 Render a text cursor for TextInput items
It doesn't look quite perfect yet, but it's a start.
2020-09-18 17:58:14 +02:00
Simon Hausmann
d819541ea3 Fix build 2020-09-18 16:41:37 +02:00
Simon Hausmann
2da84fee46 Add a boilerplate TextInput item 2020-09-18 16:34:24 +02:00
Simon Hausmann
39fabdee9e Pass a window reference to Item::key_event
Similar to the input_event.
2020-09-18 16:22:00 +02:00
Simon Hausmann
7053aee0c8 Pass the ComponentWindow to ItemVTable::input_event 2020-09-18 16:18:48 +02:00
Simon Hausmann
ad77896312 Change the way Text's default color is implemented
Instead of via an item constructor, implement support for default
bindings in the compiler.
2020-09-16 13:41:18 +02:00
Simon Hausmann
1d6af1da09 Prospective CI build fix
Try to ensure that the C functions in items.rs are included in the binary.
2020-09-16 08:38:30 +02:00
Simon Hausmann
625cb6c6b8 Add a constructor to Text and let the color default to black
We really shouldn't require specifying a color for every Text {} element just in order
to see *some* text.

For Rectangle OTOH transparent is a good default (and thus for Color), hence
this change just to Text.

Right now the constructor bit is also a bit repetitive, this could
perhaps be folded into BuiltinItem to generate the ffi, default impl and
forward to an init function if it exists.
2020-09-16 08:20:13 +02:00
Simon Hausmann
dd8e487acc Fix discrepancy between Text layout info and rendering
The layout_info() would calculate the text metrics based on a different effective pixel
size compared to the rendering.
2020-09-15 16:15:26 +02:00
Simon Hausmann
79ba5d9de8 Provide a window reference in various ItemVTable functions
Access to the window, in particular the scale factor, will be needed in a few places.
2020-09-15 15:55:47 +02:00
Simon Hausmann
37e550e540 Fix inconsistency in Font API
Have just one height() function in the fontkit and canvas version.
2020-09-15 12:28:30 +02:00
Simon Hausmann
546818ee55 Add key event data structures and event function boiler plate 2020-09-15 11:16:55 +02:00
Olivier Goffart
8761ca80a3 Add SharedArray::push and adjust a bit the API 2020-09-09 18:47:15 +02:00
Olivier Goffart
e997dff094 Use a reference as a signal argument.
It will be easier to make that work with C++
2020-09-08 12:12:01 +02:00
Simon Hausmann
570e51eaa9 Improve API of color handling of text
Make the text color a rendering variable, so that it can be passed
through as uniform to the glyph shader and applied to the gray
map of the glyphs. This avoids re-creating the glyph runs when
merely the color changes.

This already "worked" for the glyph cache based text rendering,
but it wasn't used because of the wasm canvas code path. This
patch changes that to render the text into a text using simply black
and then render that texture using our existing glyph shader,
which merely uses the alpha channel anyway.

This reduces also #cfg's.
2020-09-02 11:48:41 +02:00
Olivier Goffart
58cdaeb8dd Update license header to mention that commertial option are available 2020-08-26 13:23:42 +02:00
Simon Hausmann
2823f32692 Apply license headers to all non-binary/non-json sources 2020-08-17 17:55:20 +02:00