Skip to content

Commit

Permalink
Release 0.10 (#215)
Browse files Browse the repository at this point in the history
* Bump crate version

* Keyboard focus fixes (#211)

* Fix crash after calling `DockState::remove_tab`. (#208)

* Remove surface after removing the last remaining tab, if the surface isn't `Main`.

* Add explicit panic in `Tree::remove_leaf` if the `Tree` is empty.

* Bump patch version, update changelog.

* Include instructions on how to run examples in Readme. (#209)

* Fix keyboard focus not working inside `DockArea`s

* Add visual indicators when tab buttons are focused

* Allow current tab to be switched using the keyboard

* Remove extra focusable areas

I removed focus from two widgets that are not supposed to be focusable.
Also, I added highlighting to the separators when they are focused
because apparently I can't remove the ability to focus them without
breaking the ability to drag the separators.

* Separators can now be moved with the arrow keys

* Add highlighting to active tabs that are keyboard focused

* Update changelog

* Add tab styles for keyboard-focused tabs

* Don't move separators unless Ctrl or Shift is down

This is so that using the arrow keys to change the keyboard focus will
still work normally.

* Clippy

---------

Co-authored-by: Adam Gąsior <adanos020@gmail.com>

* Upgrade to egui 0.25 (#214)

* Update readme and changelog

* Add window tooltip translation (#216)

* Add translation for window close button tooltip

* Rename `default` to `english` in `{TabContextMenu,Window,}Translations`

* Update changelog

---------

Co-authored-by: 刘皓 <whiteaxe@tuta.io>
  • Loading branch information
Adanos020 and white-axe authored Jan 9, 2024
1 parent fae7fbc commit e07d9c4
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 78 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# egui_dock changelog

## 0.10.0 - 2024-01-08

### Added
- From ([#211](https://github.com/Adanos020/egui_dock/pull/211)):
- Tabs, the close tab buttons and the add tab buttons are now focusable with the keyboard and interactable with the enter key and space bar.
- Separators are now focusable with the keyboard and movable using the arrow keys while control or shift is held.
- `TabStyle::active_with_kb_focus`, `TabStyle::inactive_with_kb_focus` and `TabStyle::focused_with_kb_focus` for style of tabs that are focused with the keyboard.
- Missing translation for the tooltip showing when you hover on a grayed out window close button. ([#216](https://github.com/Adanos020/egui_dock/pull/216))

### Fixed
- Widgets inside tabs are now focusable with the tab key on the keyboard. ([#211](https://github.com/Adanos020/egui_dock/pull/211))

### Breaking changes
- Upgraded to egui 0.25
- Replaced `Default` implementations for `{TabContextMenu,Window,}Translations` with associated functions called `english`. ([#216](https://github.com/Adanos020/egui_dock/pull/216))

## 0.9.1 - 2023-12-10

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "egui_dock"
description = "Docking system for egui - an immediate-mode GUI library for Rust"
authors = ["lain-dono", "Adam Gąsior (Adanos020)"]
version = "0.9.1"
version = "0.10.0"
edition = "2021"
rust-version = "1.72"
license = "MIT"
Expand All @@ -18,14 +18,14 @@ default = []
serde = ["dep:serde", "egui/serde"]

[dependencies]
egui = { version = "0.24", default-features = false }
egui = { version = "0.25", default-features = false }
serde = { version = "1", optional = true, features = ["derive"] }

duplicate = "1.0"
paste = "1.0"

[dev-dependencies]
eframe = { version = "0.24", default-features = false, features = [
eframe = { version = "0.25", default-features = false, features = [
"default_fonts",
"glow",
] }
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![github](https://img.shields.io/badge/github-Adanos020/egui_dock-8da0cb?logo=github)](https://github.com/Adanos020/egui_dock)
[![Crates.io](https://img.shields.io/crates/v/egui_dock)](https://crates.io/crates/egui_dock)
[![docs.rs](https://img.shields.io/docsrs/egui_dock)](https://docs.rs/egui_dock/)
[![egui_version](https://img.shields.io/badge/egui-0.24-blue)](https://github.com/emilk/egui)
[![egui_version](https://img.shields.io/badge/egui-0.25-blue)](https://github.com/emilk/egui)

Originally created by [@lain-dono](https://github.com/lain-dono), this library provides a docking system for `egui`.

Expand Down Expand Up @@ -32,8 +32,8 @@ Add `egui` and `egui_dock` to your project's dependencies.

```toml
[dependencies]
egui = "0.24"
egui_dock = "0.9"
egui = "0.25"
egui_dock = "0.10"
```

Then proceed by setting up `egui`, following its [quick start guide](https://github.com/emilk/egui#quick-start).
Expand Down
2 changes: 1 addition & 1 deletion src/dock_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<Tab> DockState<Tab> {
Self {
surfaces: vec![Surface::Main(Tree::new(tabs))],
focused_surface: None,
translations: Translations::default(),
translations: Translations::english(),
}
}

Expand Down
31 changes: 26 additions & 5 deletions src/dock_state/translations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
pub struct Translations {
/// Text overrides for buttons in tab context menus.
pub tab_context_menu: TabContextMenuTranslations,
/// Text overrides for buttons in windows.
pub window: WindowTranslations,
}

/// Specifies text in buttons displayed in the context menu displayed upon right-clicking on a tab.
Expand All @@ -16,21 +18,40 @@ pub struct TabContextMenuTranslations {
pub eject_button: String,
}

impl Default for Translations {
/// Specifies text in buttons displayed in the context menu displayed upon right-clicking on a tab.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct WindowTranslations {
/// Message in the tooltip shown while hovering over a grayed out X button of a window
/// containing non-closable tabs.
pub close_button_tooltip: String,
}

impl Translations {
/// Default English translations.
fn default() -> Self {
pub fn english() -> Self {
Self {
tab_context_menu: TabContextMenuTranslations::default(),
tab_context_menu: TabContextMenuTranslations::english(),
window: WindowTranslations::english(),
}
}
}

impl Default for TabContextMenuTranslations {
impl TabContextMenuTranslations {
/// Default English translations.
fn default() -> Self {
pub fn english() -> Self {
Self {
close_button: String::from("Close"),
eject_button: String::from("Eject"),
}
}
}

impl WindowTranslations {
/// Default English translations.
pub fn english() -> Self {
Self {
close_button_tooltip: String::from("This window contains non-closable tabs."),
}
}
}
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,24 @@
//! Example usage:
//!
//! ```rust
//! # use egui_dock::{DockState, TabContextMenuTranslations, Translations};
//! # use egui_dock::{DockState, TabContextMenuTranslations, Translations, WindowTranslations};
//! # type Tab = ();
//! let translations_pl = Translations {
//! tab_context_menu: TabContextMenuTranslations {
//! close_button: "Zamknij zakładkę".to_string(),
//! eject_button: "Przenieś zakładkę do nowego okna".to_string(),
//! },
//! window: WindowTranslations {
//! close_button_tooltip: "To okno zawiera zakładki, których nie można zamknąć.".to_string(),
//! }
//! };
//! let dock_state = DockState::<Tab>::new(vec![]).with_translations(translations_pl);
//!
//! // Alternatively:
//! let mut dock_state = DockState::<Tab>::new(vec![]);
//! dock_state.translations.tab_context_menu.close_button = "タブを閉じる".to_string();
//! dock_state.translations.tab_context_menu.eject_button = "タブを新しいウィンドウへ移動".to_string();
//! dock_state.translations.window.close_button_tooltip = "このウィンドウは閉じられないタブがある。".to_string();
//! ```

#![warn(missing_docs)]
Expand Down
66 changes: 66 additions & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ pub struct TabStyle {
/// Style of the tab when it is hovered.
pub hovered: TabInteractionStyle,

/// Style of the tab when it is inactive and has keyboard focus.
pub inactive_with_kb_focus: TabInteractionStyle,

/// Style of the tab when it is active and has keyboard focus.
pub active_with_kb_focus: TabInteractionStyle,

/// Style of the tab when it is focused and has keyboard focus.
pub focused_with_kb_focus: TabInteractionStyle,

/// Style for the tab body.
pub tab_body: TabBodyStyle,

Expand Down Expand Up @@ -357,6 +366,15 @@ impl Default for TabStyle {
text_color: Color32::BLACK,
..Default::default()
},
active_with_kb_focus: TabInteractionStyle::default(),
inactive_with_kb_focus: TabInteractionStyle {
text_color: Color32::DARK_GRAY,
..Default::default()
},
focused_with_kb_focus: TabInteractionStyle {
text_color: Color32::BLACK,
..Default::default()
},
tab_body: TabBodyStyle::default(),
hline_below_active_tab_name: false,
minimum_width: None,
Expand Down Expand Up @@ -532,6 +550,9 @@ impl TabStyle {
inactive: TabInteractionStyle::from_egui_inactive(style),
focused: TabInteractionStyle::from_egui_focused(style),
hovered: TabInteractionStyle::from_egui_hovered(style),
active_with_kb_focus: TabInteractionStyle::from_egui_active_with_kb_focus(style),
inactive_with_kb_focus: TabInteractionStyle::from_egui_inactive_with_kb_focus(style),
focused_with_kb_focus: TabInteractionStyle::from_egui_focused_with_kb_focus(style),
tab_body: TabBodyStyle::from_egui(style),
..Default::default()
}
Expand Down Expand Up @@ -609,6 +630,51 @@ impl TabInteractionStyle {
..TabInteractionStyle::from_egui_inactive(style)
}
}

/// Derives relevant fields from `egui::Style` for an active tab with keyboard focus and sets the remaining fields to their default values.
///
/// Fields overwritten by [`egui::Style`] are:
/// - [`TabInteractionStyle::outline_color`]
/// - [`TabInteractionStyle::bg_fill`]
/// - [`TabInteractionStyle::text_color`]
/// - [`TabInteractionStyle::rounding`]
pub fn from_egui_active_with_kb_focus(style: &egui::Style) -> Self {
Self {
text_color: style.visuals.strong_text_color(),
outline_color: style.visuals.widgets.hovered.bg_stroke.color,
..TabInteractionStyle::from_egui_active(style)
}
}

/// Derives relevant fields from `egui::Style` for an inactive tab with keyboard focus and sets the remaining fields to their default values.
///
/// Fields overwritten by [`egui::Style`] are:
/// - [`TabInteractionStyle::outline_color`]
/// - [`TabInteractionStyle::bg_fill`]
/// - [`TabInteractionStyle::text_color`]
/// - [`TabInteractionStyle::rounding`]
pub fn from_egui_inactive_with_kb_focus(style: &egui::Style) -> Self {
Self {
text_color: style.visuals.strong_text_color(),
outline_color: style.visuals.widgets.hovered.bg_stroke.color,
..TabInteractionStyle::from_egui_inactive(style)
}
}

/// Derives relevant fields from `egui::Style` for a focused tab with keyboard focus and sets the remaining fields to their default values.
///
/// Fields overwritten by [`egui::Style`] are:
/// - [`TabInteractionStyle::outline_color`]
/// - [`TabInteractionStyle::bg_fill`]
/// - [`TabInteractionStyle::text_color`]
/// - [`TabInteractionStyle::rounding`]
pub fn from_egui_focused_with_kb_focus(style: &egui::Style) -> Self {
Self {
text_color: style.visuals.strong_text_color(),
outline_color: style.visuals.widgets.hovered.bg_stroke.color,
..TabInteractionStyle::from_egui_focused(style)
}
}
}

impl TabBodyStyle {
Expand Down
Loading

0 comments on commit e07d9c4

Please sign in to comment.