Commit Graph
39175 Commits
Author SHA1 Message Date
Nate Butler ec722d48fc Add checkboxes and their stories (#3235)
[[PR Description]]

Adds checkboxes and their stories.

A checkbox can be created simply by passing an id:

~~~rust
#[derive(Component)]
pub struct Checkbox {
    id: SharedString,
    checked: Selected,
    disabled: bool,
}

impl Checkbox {
    pub fn new(id: impl Into<SharedString>) -> Self {
        Self {
            id: id.into(),
            checked: Selected::Unselected,
            disabled: false,
        }
    }
    //...
}
~~~

I've documented this component rather thoroughly as an example of how
we've been thinking about building out UI elements:

~~~rs
pub fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>)
-> impl Component<V> {
        let group_id = format!("checkbox_group_{}", self.id);

        // The icon is different depending on the state of the checkbox.
        //
        // We need the match to return all the same type,
        // so we wrap the eatch result in a div.
        //
        // We are still exploring the best way to handle this.
        let icon = match self.checked {
            // When selected, we show a checkmark.
            Selected::Selected => {
                div().child(
                    IconElement::new(Icon::Check)
                        .size(crate::IconSize::Small)
                        .color(
// If the checkbox is disabled we change the color of the icon.
                            if self.disabled {
                                IconColor::Disabled
                            } else {
                                IconColor::Selected
                            },
                        ),
                )
            }
            // In an indeterminate state, we show a dash.
            Selected::Indeterminate => {
                div().child(
                    IconElement::new(Icon::Dash)
                        .size(crate::IconSize::Small)
                        .color(
// If the checkbox is disabled we change the color of the icon.
                            if self.disabled {
                                IconColor::Disabled
                            } else {
                                IconColor::Selected
                            },
                        ),
                )
            }
            // When unselected, we show nothing.
            Selected::Unselected => div(),
        };

        // A checkbox could be in an indeterminate state,
        // for example the indeterminate state could represent:
        //  - a group of options of which only some are selected
        //  - an enabled option that is no longer available
        //  - a previously agreed to license that has been updated
        //
// For the sake of styles we treat the indeterminate state as selected,
        // but it's icon will be different.
        let selected =
self.checked == Selected::Selected || self.checked ==
Selected::Indeterminate;

// We could use something like this to make the checkbox background when
selected:
        //
        // ~~~rust
        // ...
        // .when(selected, |this| {
        //     this.bg(cx.theme().colors().element_selected)
        // })
        // ~~~
        //
// But we use a match instead here because the checkbox might be
disabled,
// and it could be disabled _while_ it is selected, as well as while it
is not selected.
        let (bg_color, border_color) = match (self.disabled, selected) {
            (true, _) => (
                cx.theme().colors().ghost_element_disabled,
                cx.theme().colors().border_disabled,
            ),
            (false, true) => (
                cx.theme().colors().element_selected,
                cx.theme().colors().border,
            ),
(false, false) => (cx.theme().colors().element,
cx.theme().colors().border),
        };

        div()
// Rather than adding `px_1()` to add some space around the checkbox,
// we use a larger parent element to create a slightly larger
            // click area for the checkbox.
            .size_5()
// Because we've enlarged the click area, we need to create a
            // `group` to pass down interaction events to the checkbox.
            .group(group_id.clone())
            .child(
                div()
                    .flex()
                    // This prevent the flex element from growing
                    // or shrinking in response to any size changes
                    .flex_none()
// The combo of `justify_center()` and `items_center()`
// is used frequently to center elements in a flex container.
                    //
                    // We use this to center the icon in the checkbox.
                    .justify_center()
                    .items_center()
                    .m_1()
                    .size_4()
                    .rounded_sm()
                    .bg(bg_color)
                    .border()
                    .border_color(border_color)
// We only want the interaction states to fire when we
                    // are in a checkbox that isn't disabled.
                    .when(!self.disabled, |this| {
// Here instead of `hover()` we use `group_hover()`
                        // to pass it the group id.
                        this.group_hover(group_id.clone(), |el| {
                            el.bg(cx.theme().colors().element_hover)
                        })
                    })
                    .child(icon),
            )
    }
~~~

Release Notes:

- N/A
2023-11-05 08:37:45 -05:00
Kirill Bulatov b03d2e6ea8 Correctly update old diagnostics 2023-11-05 15:37:27 +02:00
Kirill Bulatov 321872095c Parallelize diagnostics filling, add more logs 2023-11-05 15:06:39 +02:00
Kirill Bulatov b76f28cf58 Restructure inner path data 2023-11-05 14:53:13 +02:00
Kirill Bulatov ac34ca4d30 Eagerly refresh diagnostics that do not intercept with user input 2023-11-05 14:44:22 +02:00
Kirill Bulatov 4b2bf246a9 Refresh all possibly stale diagnostics pat 2023-11-05 14:43:54 +02:00
Nate Butler 09fd938c2c Add checkboxes and their stories 2023-11-05 01:06:41 -05:00
Nate Butler 35a6f1520c Simplify toggle, some ui2 reorganization (#3234)
[[PR Description]]

A few mix organizational things in UI, as well as some toggle changes.

Simplify toggle:

```rust
/// Whether the entry is toggleable, and if so, whether it is currently toggled.
///
/// To make an element toggleable, simply add a `Toggle::Toggled(_)` and handle it's cases.
///
/// You can check if an element is toggleable with `.is_toggleable()`
///
/// Possible values:
/// - `Toggle::NotToggleable` - The entry is not toggleable
/// - `Toggle::Toggled(true)` - The entry is toggleable and toggled
/// - `Toggle::Toggled(false)` - The entry is toggleable and not toggled
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Toggle {
    NotToggleable,
    Toggled(bool),
}
```

Adds helper functions to easily get the toggle and toggleable states:

```rust
impl Toggle {
    /// Returns true if the entry is toggled (or is not toggleable.)
    ///
    /// As element that isn't toggleable is always "expanded" or "enabled"
    /// returning true in that case makes sense.
    pub fn is_toggled(&self) -> bool {
        match self {
            Self::Toggled(false) => false,
            _ => true,
        }
    }

    pub fn is_toggleable(&self) -> bool {
        match self {
            Self::Toggled(_) => true,
            _ => false,
        }
    }
}
```

Pulls `disclosure_control` out of components and creates a common def:

```rust
pub fn disclosure_control<V: 'static>(toggle: Toggle) -> impl Component<V> {
    match (toggle.is_toggleable(), toggle.is_toggled()) {
        (false, _) => div(),
        (_, true) => div().child(
            IconElement::new(Icon::ChevronDown)
                .color(IconColor::Muted)
                .size(IconSize::Small),
        ),
        (_, false) => div().child(
            IconElement::new(Icon::ChevronRight)
                .color(IconColor::Muted)
                .size(IconSize::Small),
        ),
    }
}
```

disclosure_control will likely get pulled into it's own component in the
future instead of being in toggle.

Release Notes:

- N/A
2023-11-04 12:09:41 -04:00
Nate Butler e59bf2ad35 Simplify toggle, do some reorganization 2023-11-04 11:24:31 -04:00
Antonio Scandurra 67d66e7a14 Fix compile errors, now lines are being laid out 2023-11-04 14:37:57 +01:00
Kirill Bulatov 39c3901f61 Suppress unused vars warning generated by gpui macro (#3233) 2023-11-04 14:06:42 +02:00
Kirill Bulatov f86bd3de7f Suppress unused vars warning generated by gpui macro 2023-11-04 13:54:37 +02:00
Conrad Irwin 8792716378 Update tooltip code a bit
This fixes a tiny UX bug where the tooltip would appear to move if you
hovered over an element, then moved your mouse out and back within
500ms.

The fix is to retain the task, so we can drop it to cancel it when the
mouse leaves.

Also changes the time we construct the tooltip to the time it first
shows.
2023-11-03 21:40:28 -06:00
Mikayla Maki 5ace4b8f06 Merge branch 'main' into add-collab-tests 2023-11-03 18:06:08 -07:00
Mikayla c163c12bca Get collab2 green 2023-11-03 18:01:06 -07:00
Max Brunsfeld 7b7ba5236d WIP2000 2023-11-03 16:40:37 -07:00
Max Brunsfeld 7a605cf7ae Allow language injection in markdown code blocks in channel notes (#3231)
Release Notes:

- Fixed an issue where markdown code blocks were not syntax-highlighted
in channel notes editors.
2023-11-03 16:12:02 -07:00
Max Brunsfeld 3500ef8b50 Allow language injection in markdown code blocks in channel notes 2023-11-03 15:53:54 -07:00
JuliaandConrad Irwin e56b9f7f45 Move more tooltip logic into gpui2 & fix tooltip moving on paint
Co-Authored-By: Conrad Irwin <conrad@zed.dev>
2023-11-03 18:37:15 -04:00
Nate Butler f970c6ddda Add UI docs (#3230)
Not as exciting as it sounds - Just starting to scaffold out some UI
docs and want to get feedback.

Release Notes:

- N/A
2023-11-03 18:25:08 -04:00
Nate Butler c6b1ef2c38 Merge branch 'main' into add-ui-docs 2023-11-03 18:20:17 -04:00
Nate Butler 7080241479 Add some initial docs 2023-11-03 18:19:54 -04:00
Marshall Bowers 80ad36479b storybook2: Remove unreferenced components module (#3229)
This PR removes the `components` module from `storybook2` as it was
dead, unreferenced code.

Release Notes:

- N/A
2023-11-03 18:12:21 -04:00
JuliaandConrad Irwin 438dcffdad Tooltips in mouse event handler & fix executor timer
Co-Authored-By: Conrad Irwin <conrad@zed.dev>
2023-11-03 18:02:58 -04:00
Marshall Bowers 9e4142a6e9 Remove theme.txt 2023-11-03 17:52:19 -04:00
Marshall Bowers 49922ece21 ui2: Reorganize components (#3228)
This PR reorganizes the components in the `ui2` crate.

The distinction between "elements" and "components" is now gone, with
all of the reusable components living under `components/`.

The components that we built while prototyping but will eventually live
in other crates currently reside in the `to_extract/` module.

Release Notes:

- N/A
2023-11-03 17:34:11 -04:00
Marshall Bowers f81e3f4dab Allow deriving Serialize and Deserialize on generated refinement (#3227)
This PR adds support for deriving `Serialize` and `Deserialize` on the
refinement type generated by `#[derive(Refineable)]`.

Release Notes:

- N/A
2023-11-03 17:21:00 -04:00
Marshall Bowers 95216af9d5 Remove unneeded type qualification 2023-11-03 16:40:46 -04:00
Nate ButlerandMarshall Bowers 5426d44499 Add docs burndown list
Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
2023-11-03 16:37:22 -04:00
Marshall Bowers 137c08c810 Use an IconButton for the tab close button 2023-11-03 16:36:02 -04:00
Nate ButlerandMarshall Bowers 7782368831 Start on ui root doc
Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
2023-11-03 16:28:54 -04:00
Conrad Irwin db65488f14 MOAR TOOLTIPS 2023-11-03 14:15:32 -06:00
Kirill Bulatov 1e24f68814 Refresh diagnostics inside the tab (#3225)
r-a now has 2 different types of diagnostics: 
* "disk-based" ones that come from `cargo check` and related, that emit
`project::Event::DiskBasedDiagnosticsStarted` and
`DiskBasedDiagnosticsFinished`
* "flycheck" diagnostics from r-a itself, that it tries to dynamically
apply to every buffer open, that come with `DiagnosticsUpdated` event.

Latter diagnostics update frequently, on every file close and open, but
`diagnostics.rs` logic had never polled for new diagnostics after
registering the `DiagnosticsUpdated` event, so the only way we could
have newer diagnostics was to re-open the whole panel.
The PR fixes that, and also adds more debug logging to the module.
The logic of the fix looks very familiar to previous related fix:
https://github.com/zed-industries/zed/pull/3128

One notable thing after the fix: "flycheck" diagnostics stay forever if
the diagnostics panel is opened: excerpts in that panel do not allow the
buffer to get dropped (hence, closed in terms of r-a) and get the
updated, zero diagnostics.
If the diagnostics panel is opened and closed multiple times, those
errors gradually disappear.

Release Notes:

- Fixed diagnostics panel not refreshing its contents properly
2023-11-03 22:03:05 +02:00
Conrad IrwinandJulia 5687664b81 Tooltip on tabs
Co-Authored-By: Julia <julia@zed.dev>
2023-11-03 14:02:46 -06:00
Kirill Bulatov 1ed9260477 Fix the test 2023-11-03 21:51:12 +02:00
Kirill Bulatov 2996ff6c1b Fix a compilation error 2023-11-03 21:51:12 +02:00
Kirill Bulatov 3592b98e8f Refresh diagnostics inside the tab 2023-11-03 21:51:12 +02:00
Marshall Bowers f9701564ce Merge branch 'main' into import-theme 2023-11-03 15:41:12 -04:00
Marshall Bowers 9e7f83068a Remove Default impl for ThemeColors` (#3226)
This PR removes the `Default` impl for `ThemeColors`.

Since we need default light and dark variants for `ThemeColors`, we
can't use a single `Default` impl.

Release Notes:

- N/A
2023-11-03 15:40:50 -04:00
Mikayla Maki 197e076487 WIP: Port channel crate to gpui2 (#3192) 2023-11-03 12:32:47 -07:00
a1e9f0f311 Fix double borrow in synchronous tests that take AppContext
Co-authored-by: Mikayla <mikayla@zed.dev>
Co-authored-by: Antonio <antonio@zed.dev>
2023-11-03 12:10:11 -07:00
Mikayla 3a4d70b212 WIP 2023-11-03 12:04:24 -07:00
Conrad Irwin b2c983034b gpui2: Add on_hover events 2023-11-03 12:51:38 -06:00
Antonio Scandurra 18f34e4eed WIP 2023-11-03 18:55:20 +01:00
Mikayla b4c926ad13 Update to latest patterns for porting work 2023-11-03 10:46:47 -07:00
Max BrunsfeldandMarshall eeaa7c7685 Add channel2 crate
Co-authored-by: Marshall <marshall@zed.dev>
2023-11-03 10:41:41 -07:00
Conrad Irwin 48800ad097 Add PointingHand on tabs 2023-11-03 11:30:15 -06:00
aebf31819c Add hover behaviour to tabs
Co-Authored-By: Marshall <marshall@zed.dev>
Co-Authored-By: Nathan <nathan@zed.dev>
2023-11-03 10:55:07 -06:00
KCaverly 29315fe06f port rope2 to zed2 2023-11-03 12:15:23 -04:00
Antonio Scandurra 8ffded7fa5 WIP: start on editor element 2023-11-03 17:14:17 +01:00