title_bar: Impl Styled to TitleBar. (#375)
This commit is contained in:
parent
c87b4c7f01
commit
53311b06f8
1 changed files with 19 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{h_flex, theme::ActiveTheme, Icon, IconName, InteractiveElementExt as _, Sizable as _};
|
use crate::{h_flex, theme::ActiveTheme, Icon, IconName, InteractiveElementExt as _, Sizable as _};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder as _, px, relative, AnyElement, Element, Hsla,
|
div, prelude::FluentBuilder as _, px, relative, AnyElement, Div, Element, Hsla,
|
||||||
InteractiveElement as _, IntoElement, ParentElement, Pixels, RenderOnce,
|
InteractiveElement as _, IntoElement, ParentElement, Pixels, RenderOnce, Stateful,
|
||||||
StatefulInteractiveElement as _, Style, Styled, WindowContext,
|
StatefulInteractiveElement as _, Style, Styled, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -10,6 +10,7 @@ use gpui::{
|
||||||
/// We can put some elements inside the title bar.
|
/// We can put some elements inside the title bar.
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct TitleBar {
|
pub struct TitleBar {
|
||||||
|
base: Stateful<Div>,
|
||||||
children: Vec<AnyElement>,
|
children: Vec<AnyElement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -18,17 +19,12 @@ pub const TITLE_BAR_HEIGHT: Pixels = px(35.);
|
||||||
impl TitleBar {
|
impl TitleBar {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
base: div().id("title-bar"),
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParentElement for TitleBar {
|
|
||||||
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
|
|
||||||
self.children.extend(elements);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The Windows control buttons have a fixed width of 35px.
|
// The Windows control buttons have a fixed width of 35px.
|
||||||
//
|
//
|
||||||
// We don't need implementation the click event for the control buttons.
|
// We don't need implementation the click event for the control buttons.
|
||||||
|
|
@ -173,6 +169,18 @@ impl RenderOnce for WindowControls {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Styled for TitleBar {
|
||||||
|
fn style(&mut self) -> &mut gpui::StyleRefinement {
|
||||||
|
self.base.style()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ParentElement for TitleBar {
|
||||||
|
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
|
||||||
|
self.children.extend(elements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl RenderOnce for TitleBar {
|
impl RenderOnce for TitleBar {
|
||||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||||
let is_linux = cfg!(target_os = "linux");
|
let is_linux = cfg!(target_os = "linux");
|
||||||
|
|
@ -187,8 +195,9 @@ impl RenderOnce for TitleBar {
|
||||||
div()
|
div()
|
||||||
.flex_shrink_0()
|
.flex_shrink_0()
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
self.base
|
||||||
.id("title-bar")
|
.flex()
|
||||||
|
.flex_row()
|
||||||
.items_center()
|
.items_center()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.h(HEIGHT)
|
.h(HEIGHT)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue