Skip to main content

Theme

Struct Theme 

Source
pub struct Theme {
    pub background: Rgba,
    pub axis: Rgba,
    pub grid_major: Rgba,
    pub grid_minor: Rgba,
    pub hover_bg: Rgba,
    pub hover_border: Rgba,
    pub pin_bg: Rgba,
    pub pin_border: Rgba,
    pub selection_fill: Rgba,
    pub selection_border: Rgba,
    pub legend_bg: Rgba,
    pub legend_border: Rgba,
}
Expand description

Visual theme for plot-level elements such as axes, grid, and overlays.

Themes are applied at the plot level and affect all series and overlays.

Fields§

§background: Rgba

Plot background color.

§axis: Rgba

Axis, tick, and label color.

§grid_major: Rgba

Major grid line color.

§grid_minor: Rgba

Minor grid line color.

§hover_bg: Rgba

Hover tooltip background color.

§hover_border: Rgba

Hover tooltip border color.

§pin_bg: Rgba

Pin tooltip background color.

§pin_border: Rgba

Pin tooltip border color.

§selection_fill: Rgba

Selection rectangle fill color.

§selection_border: Rgba

Selection rectangle border color.

§legend_bg: Rgba

Legend background color.

§legend_border: Rgba

Legend border color.

Implementations§

Source§

impl Theme

Source

pub fn new() -> Self

Create the default theme (alias of Theme::dark).

Source

pub fn light() -> Self

Create a light theme palette.

Source

pub fn dark() -> Self

Create a dark theme palette.

Examples found in repository?
examples/basic.rs (line 37)
7fn main() {
8    Application::new().run(|cx| {
9        let options = WindowOptions {
10            window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
11                None,
12                size(px(720.0), px(480.0)),
13                cx,
14            ))),
15            ..Default::default()
16        };
17
18        cx.open_window(options, |_window, cx| {
19            let series = Series::from_iter_y(
20                "signal",
21                (0..400).map(|i| {
22                    let x = i as f64 * 0.03;
23                    x.sin()
24                }),
25                SeriesKind::Line(LineStyle {
26                    color: Rgba {
27                        r: 0.2,
28                        g: 0.75,
29                        b: 0.95,
30                        a: 1.0,
31                    },
32                    width: 2.0,
33                }),
34            );
35
36            let mut plot = Plot::builder()
37                .theme(Theme::dark())
38                .x_axis(AxisConfig::builder().title("Sample").build())
39                .y_axis(AxisConfig::builder().title("Amplitude").build())
40                .build();
41            plot.add_series(&series);
42
43            let config = PlotViewConfig {
44                show_legend: true,
45                show_hover: true,
46                ..Default::default()
47            };
48
49            let view = PlotView::with_config(plot, config);
50            cx.new(|_| view)
51        })
52        .unwrap();
53    });
54}
More examples
Hide additional examples
examples/advanced.rs (line 103)
34fn build_views(
35    cx: &mut gpui::App,
36) -> (
37    gpui::Entity<PlotView>,
38    gpui::Entity<PlotView>,
39    Series,
40    Series,
41) {
42    let mut stream_a = Series::line("stream-A").with_kind(SeriesKind::Line(LineStyle {
43        color: Rgba {
44            r: 0.2,
45            g: 0.82,
46            b: 0.95,
47            a: 1.0,
48        },
49        width: 2.0,
50    }));
51    let mut stream_b = Series::line("stream-B").with_kind(SeriesKind::Line(LineStyle {
52        color: Rgba {
53            r: 0.95,
54            g: 0.64,
55            b: 0.28,
56            a: 1.0,
57        },
58        width: 2.0,
59    }));
60
61    for i in 0..1_000 {
62        let phase = i as f64 * 0.02;
63        let _ = stream_a.push_y((phase * 0.9).sin() + 0.2 * (phase * 0.13).cos());
64        let _ = stream_b.push_y((phase * 0.45).cos() * 1.15 + 0.15 * (phase * 0.09).sin());
65    }
66
67    let events = Series::from_iter_points(
68        "events(scatter)",
69        (0..200).map(|i| {
70            let x = i as f64 * 80.0 + 40.0;
71            let y = (x * 0.02).sin() * 0.9;
72            gpui_liveplot::Point::new(x, y)
73        }),
74        SeriesKind::Scatter(MarkerStyle {
75            color: Rgba {
76                r: 0.95,
77                g: 0.25,
78                b: 0.55,
79                a: 1.0,
80            },
81            size: 5.0,
82            shape: MarkerShape::Circle,
83        }),
84    );
85
86    let baseline = Series::from_explicit_callback(
87        "baseline(callback)",
88        |x| (x * 0.015).sin() * 0.4,
89        Range::new(0.0, 25_000.0),
90        5_000,
91        SeriesKind::Line(LineStyle {
92            color: Rgba {
93                r: 0.45,
94                g: 0.45,
95                b: 0.5,
96                a: 0.8,
97            },
98            width: 1.0,
99        }),
100    );
101
102    let mut top_plot = Plot::builder()
103        .theme(Theme::dark())
104        .x_axis(AxisConfig::builder().title("Sample").build())
105        .y_axis(AxisConfig::builder().title("Top: stream + events").build())
106        .view(View::FollowLastN { points: 2_000 })
107        .build();
108    top_plot.add_series(&stream_a);
109    top_plot.add_series(&events);
110
111    let mut bottom_plot = Plot::builder()
112        .theme(Theme::dark())
113        .x_axis(AxisConfig::builder().title("Sample").build())
114        .y_axis(
115            AxisConfig::builder()
116                .title("Bottom: stream + baseline")
117                .build(),
118        )
119        .view(View::FollowLastNXY { points: 2_000 })
120        .build();
121    bottom_plot.add_series(&stream_b);
122    bottom_plot.add_series(&baseline);
123
124    let config = PlotViewConfig {
125        show_legend: true,
126        show_hover: true,
127        ..Default::default()
128    };
129
130    let link_group = PlotLinkGroup::new();
131    let options = PlotLinkOptions {
132        link_x: true,
133        link_y: false,
134        link_cursor: true,
135        link_brush: true,
136        link_reset: true,
137    };
138
139    let top = cx.new(|_| {
140        PlotView::with_config(top_plot, config.clone()).with_link_group(link_group.clone(), options)
141    });
142    let bottom =
143        cx.new(|_| PlotView::with_config(bottom_plot, config).with_link_group(link_group, options));
144
145    (top, bottom, stream_a, stream_b)
146}

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Theme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Theme

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Theme

Source§

fn eq(&self, other: &Theme) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Theme

Auto Trait Implementations§

§

impl Freeze for Theme

§

impl RefUnwindSafe for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

§

impl UnwindSafe for Theme

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more