Improve styling of tabs
* Enforce a min width per tab * Center the title within tab, regardless of icon * Render icon over the top of the tab title * Ensure there is always a fixed minimum amount of filler to the right of all tabs Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
36699dc095
commit
3f71867af8
@@ -3,7 +3,7 @@ use crate::{
|
||||
LayoutContext, PaintContext, SizeConstraint,
|
||||
};
|
||||
use json::ToJson;
|
||||
use pathfinder_geometry::vector::{vec2f, Vector2F};
|
||||
use pathfinder_geometry::vector::Vector2F;
|
||||
use serde_json::json;
|
||||
|
||||
pub struct Align {
|
||||
@@ -19,8 +19,13 @@ impl Align {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn top_center(mut self) -> Self {
|
||||
self.alignment = vec2f(0.0, -1.0);
|
||||
pub fn top(mut self) -> Self {
|
||||
self.alignment.set_y(-1.0);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn right(mut self) -> Self {
|
||||
self.alignment.set_x(1.0);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ impl ConstrainedBox {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_min_width(mut self, min_width: f32) -> Self {
|
||||
self.constraint.min.set_x(min_width);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_max_width(mut self, max_width: f32) -> Self {
|
||||
self.constraint.max.set_x(max_width);
|
||||
self
|
||||
@@ -33,6 +38,12 @@ impl ConstrainedBox {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_width(mut self, width: f32) -> Self {
|
||||
self.constraint.min.set_x(width);
|
||||
self.constraint.max.set_x(width);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_height(mut self, height: f32) -> Self {
|
||||
self.constraint.min.set_y(height);
|
||||
self.constraint.max.set_y(height);
|
||||
@@ -51,6 +62,7 @@ impl Element for ConstrainedBox {
|
||||
) -> (Vector2F, Self::LayoutState) {
|
||||
constraint.min = constraint.min.max(self.constraint.min);
|
||||
constraint.max = constraint.max.min(self.constraint.max);
|
||||
constraint.max = constraint.max.max(constraint.min);
|
||||
let size = self.child.layout(constraint, ctx);
|
||||
(size, ())
|
||||
}
|
||||
|
||||
@@ -43,6 +43,18 @@ impl Container {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_horizontal_padding(mut self, padding: f32) -> Self {
|
||||
self.padding.left = padding;
|
||||
self.padding.right = padding;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_vertical_padding(mut self, padding: f32) -> Self {
|
||||
self.padding.top = padding;
|
||||
self.padding.bottom = padding;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_uniform_padding(mut self, padding: f32) -> Self {
|
||||
self.padding = Padding {
|
||||
top: padding,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::any::Any;
|
||||
use std::{any::Any, f32::INFINITY};
|
||||
|
||||
use crate::{
|
||||
json::{self, ToJson, Value},
|
||||
@@ -88,9 +88,13 @@ impl Element for Flex {
|
||||
let mut remaining_space = constraint.max_along(self.axis) - fixed_space;
|
||||
let mut remaining_flex = total_flex;
|
||||
for child in &mut self.children {
|
||||
let space_per_flex = remaining_space / remaining_flex;
|
||||
if let Some(flex) = Self::child_flex(&child) {
|
||||
let child_max = space_per_flex * flex;
|
||||
let child_max = if remaining_flex == 0.0 {
|
||||
remaining_space
|
||||
} else {
|
||||
let space_per_flex = remaining_space / remaining_flex;
|
||||
space_per_flex * flex
|
||||
};
|
||||
let child_constraint = match self.axis {
|
||||
Axis::Horizontal => SizeConstraint::new(
|
||||
vec2f(0.0, constraint.min.y()),
|
||||
|
||||
Reference in New Issue
Block a user