Add hover behaviour to tabs

Co-Authored-By: Marshall <marshall@zed.dev>
Co-Authored-By: Nathan <nathan@zed.dev>
This commit is contained in:
Conrad Irwin 2023-11-03 10:54:26 -06:00
parent d3b02c4de4
commit c604a2e34e
6 changed files with 71 additions and 5 deletions

View file

@ -212,6 +212,19 @@ pub trait Component<V> {
{
self.map(|this| if condition { then(this) } else { this })
}
fn when_some<T>(self, option: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self
where
Self: Sized,
{
self.map(|this| {
if let Some(value) = option {
then(this, value)
} else {
this
}
})
}
}
impl<V> Component<V> for AnyElement<V> {

View file

@ -3,7 +3,7 @@ use crate::{
ElementInteraction, FocusDisabled, FocusEnabled, FocusHandle, FocusListeners, Focusable,
GlobalElementId, GroupBounds, InteractiveElementState, LayoutId, Overflow, ParentElement,
Pixels, Point, SharedString, StatefulInteraction, StatefulInteractive, StatelessInteraction,
StatelessInteractive, Style, StyleRefinement, Styled, ViewContext,
StatelessInteractive, Style, StyleRefinement, Styled, ViewContext, Visibility,
};
use refineable::Refineable;
use smallvec::SmallVec;
@ -249,11 +249,15 @@ where
cx: &mut ViewContext<V>,
) {
self.with_element_id(cx, |this, _global_id, cx| {
let style = this.compute_style(bounds, element_state, cx);
if style.visibility == Visibility::Hidden {
return;
}
if let Some(group) = this.group.clone() {
GroupBounds::push(group, bounds, cx);
}
let style = this.compute_style(bounds, element_state, cx);
let z_index = style.z_index.unwrap_or(0);
let mut child_min = point(Pixels::MAX, Pixels::MAX);

View file

@ -19,6 +19,9 @@ pub struct Style {
/// What layout strategy should be used?
pub display: Display,
/// Should the element be painted on screen?
pub visibility: Visibility,
// Overflow properties
/// How children overflowing their container should affect layout
#[refineable]
@ -107,6 +110,13 @@ impl Styled for StyleRefinement {
}
}
#[derive(Default, Clone, Copy, Debug, Eq, PartialEq)]
pub enum Visibility {
#[default]
Visible,
Hidden,
}
#[derive(Clone, Debug)]
pub struct BoxShadow {
pub color: Hsla,
@ -297,6 +307,7 @@ impl Default for Style {
fn default() -> Self {
Style {
display: Display::Block,
visibility: Visibility::Visible,
overflow: Point {
x: Overflow::Visible,
y: Overflow::Visible,

View file

@ -1,6 +1,7 @@
use crate::{
self as gpui2, hsla, point, px, relative, rems, AlignItems, DefiniteLength, Display, Fill,
FlexDirection, Hsla, JustifyContent, Length, Position, Rems, SharedString, StyleRefinement,
Visibility,
};
use crate::{BoxShadow, TextStyleRefinement};
use smallvec::smallvec;
@ -60,6 +61,26 @@ pub trait Styled {
self
}
/// Sets the visibility of the element to `visible`.
/// [Docs](https://tailwindcss.com/docs/visibility)
fn visible(mut self) -> Self
where
Self: Sized,
{
self.style().visibility = Some(Visibility::Visible);
self
}
/// Sets the visibility of the element to `hidden`.
/// [Docs](https://tailwindcss.com/docs/visibility)
fn invisible(mut self) -> Self
where
Self: Sized,
{
self.style().visibility = Some(Visibility::Hidden);
self
}
/// Sets the flex direction of the element to `column`.
/// [Docs](https://tailwindcss.com/docs/flex-direction#column)
fn flex_col(mut self) -> Self