ui: Refine TitleBar component (#9415)
This PR continues the refinements to the `TitleBar` component. Here are the notable changes: - `KeyBindingDisplay` and `PlatformStyle` have been unified into a single `PlatformStyle`. - This provides us a consistent way for adapting UI to different platform styles. - `PlatformTitlebar` has been renamed to `TitleBar`. - The `Platform` prefix was irrelevant. - The Windows window controls have been factored out into a separate module and have been componentized. <img width="1283" alt="Screenshot 2024-03-15 at 3 34 38 PM" src="https://github.com/zed-industries/zed/assets/1486634/07da391f-828b-48bf-8849-58863f4ccce7"> > I'm missing the Segoe Fluent Icons font, so that's why the aren't rendering properly. Release Notes: - N/A
This commit is contained in:
@@ -3,7 +3,7 @@ use gpui::Render;
|
||||
use itertools::Itertools;
|
||||
use story::{Story, StoryContainer};
|
||||
|
||||
use crate::{prelude::*, KeyBinding, KeyBindingDisplay};
|
||||
use crate::{prelude::*, KeyBinding};
|
||||
|
||||
pub struct KeybindingStory;
|
||||
|
||||
@@ -59,18 +59,22 @@ impl Render for KeybindingStory {
|
||||
.child(KeyBinding::new(binding("ctrl-a shift-z")))
|
||||
.child(KeyBinding::new(binding("fn-s")))
|
||||
.child(Story::label("Single Key with All Modifiers (Linux)"))
|
||||
.child(KeyBinding::new(binding("ctrl-alt-cmd-shift-z")).display(KeyBindingDisplay::Linux))
|
||||
.child(
|
||||
KeyBinding::new(binding("ctrl-alt-cmd-shift-z")).platform_style(PlatformStyle::Linux),
|
||||
)
|
||||
.child(Story::label("Chord (Linux)"))
|
||||
.child(KeyBinding::new(binding("a z")).display(KeyBindingDisplay::Linux))
|
||||
.child(KeyBinding::new(binding("a z")).platform_style(PlatformStyle::Linux))
|
||||
.child(Story::label("Chord with Modifier (Linux)"))
|
||||
.child(KeyBinding::new(binding("ctrl-a shift-z")).display(KeyBindingDisplay::Linux))
|
||||
.child(KeyBinding::new(binding("fn-s")).display(KeyBindingDisplay::Linux))
|
||||
.child(KeyBinding::new(binding("ctrl-a shift-z")).platform_style(PlatformStyle::Linux))
|
||||
.child(KeyBinding::new(binding("fn-s")).platform_style(PlatformStyle::Linux))
|
||||
.child(Story::label("Single Key with All Modifiers (Windows)"))
|
||||
.child(KeyBinding::new(binding("ctrl-alt-cmd-shift-z")).display(KeyBindingDisplay::Windows))
|
||||
.child(
|
||||
KeyBinding::new(binding("ctrl-alt-cmd-shift-z")).platform_style(PlatformStyle::Windows),
|
||||
)
|
||||
.child(Story::label("Chord (Windows)"))
|
||||
.child(KeyBinding::new(binding("a z")).display(KeyBindingDisplay::Windows))
|
||||
.child(KeyBinding::new(binding("a z")).platform_style(PlatformStyle::Windows))
|
||||
.child(Story::label("Chord with Modifier (Windows)"))
|
||||
.child(KeyBinding::new(binding("ctrl-a shift-z")).display(KeyBindingDisplay::Windows))
|
||||
.child(KeyBinding::new(binding("fn-s")).display(KeyBindingDisplay::Windows))
|
||||
.child(KeyBinding::new(binding("ctrl-a shift-z")).platform_style(PlatformStyle::Windows))
|
||||
.child(KeyBinding::new(binding("fn-s")).platform_style(PlatformStyle::Windows))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
use gpui::Render;
|
||||
use story::{StoryContainer, StoryItem, StorySection};
|
||||
|
||||
use crate::{prelude::*, PlatformStyle, PlatformTitlebar};
|
||||
|
||||
pub struct PlatformTitlebarStory;
|
||||
|
||||
impl Render for PlatformTitlebarStory {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
StoryContainer::new(
|
||||
"Platform Titlebar",
|
||||
"crates/ui/src/components/stories/platform_titlebar.rs",
|
||||
)
|
||||
.child(
|
||||
StorySection::new().child(
|
||||
StoryItem::new(
|
||||
"Default (macOS)",
|
||||
PlatformTitlebar::new("macos").platform_style(PlatformStyle::MacOs),
|
||||
)
|
||||
.description("")
|
||||
.usage(""),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
StorySection::new().child(
|
||||
StoryItem::new(
|
||||
"Default (Linux)",
|
||||
PlatformTitlebar::new("linux").platform_style(PlatformStyle::Linux),
|
||||
)
|
||||
.description("")
|
||||
.usage(""),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
StorySection::new().child(
|
||||
StoryItem::new(
|
||||
"Default (Windows)",
|
||||
PlatformTitlebar::new("windows").platform_style(PlatformStyle::Windows),
|
||||
)
|
||||
.description("")
|
||||
.usage(""),
|
||||
),
|
||||
)
|
||||
.into_element()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
use gpui::Render;
|
||||
use story::{StoryContainer, StoryItem, StorySection};
|
||||
|
||||
use crate::{prelude::*, PlatformStyle, TitleBar};
|
||||
|
||||
pub struct TitleBarStory;
|
||||
|
||||
impl Render for TitleBarStory {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn add_sample_children(titlebar: TitleBar) -> TitleBar {
|
||||
titlebar
|
||||
.child(div().size_2().bg(gpui::red()))
|
||||
.child(div().size_2().bg(gpui::blue()))
|
||||
.child(div().size_2().bg(gpui::green()))
|
||||
}
|
||||
|
||||
StoryContainer::new("TitleBar", "crates/ui/src/components/stories/title_bar.rs")
|
||||
.child(
|
||||
StorySection::new().child(
|
||||
StoryItem::new(
|
||||
"Default (macOS)",
|
||||
TitleBar::new("macos")
|
||||
.platform_style(PlatformStyle::Mac)
|
||||
.map(add_sample_children),
|
||||
)
|
||||
.description("")
|
||||
.usage(""),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
StorySection::new().child(
|
||||
StoryItem::new(
|
||||
"Default (Linux)",
|
||||
TitleBar::new("linux")
|
||||
.platform_style(PlatformStyle::Linux)
|
||||
.map(add_sample_children),
|
||||
)
|
||||
.description("")
|
||||
.usage(""),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
StorySection::new().child(
|
||||
StoryItem::new(
|
||||
"Default (Windows)",
|
||||
TitleBar::new("windows")
|
||||
.platform_style(PlatformStyle::Windows)
|
||||
.map(add_sample_children),
|
||||
)
|
||||
.description("")
|
||||
.usage(""),
|
||||
),
|
||||
)
|
||||
.into_element()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user