@ -360,6 +360,10 @@ impl Margin {
pub fn right_bottom ( & self ) -> Vec2 {
vec2 ( self . right , self . bottom )
}
pub fn is_same ( & self ) -> bool {
self . left = = self . right & & self . left = = self . top & & self . left = = self . bottom
}
}
impl From < f32 > for Margin {
@ -464,6 +468,11 @@ pub struct Visuals {
pub window_rounding : Rounding ,
pub window_shadow : Shadow ,
pub window_fill : Color32 ,
pub window_stroke : Stroke ,
/// Panel background color
pub panel_fill : Color32 ,
pub popup_shadow : Shadow ,
@ -495,7 +504,7 @@ impl Visuals {
}
pub fn weak_text_color ( & self ) -> Color32 {
crate ::ecolor ::tint_color_towards ( self . text_color ( ) , self . window_fill ( ) )
self . gray_out ( self . text_color ( ) )
}
#[ inline(always) ]
@ -506,12 +515,25 @@ impl Visuals {
/// Window background color.
#[ inline(always) ]
pub fn window_fill ( & self ) -> Color32 {
self . widgets . noninteractive . bg _fill
self . window _fill
}
#[ inline(always) ]
pub fn window_stroke ( & self ) -> Stroke {
self . widgets . noninteractive . bg_stroke
self . window_stroke
}
/// When fading out things, we fade the colors towards this.
// TODO(emilk): replace with an alpha
#[ inline(always) ]
pub fn fade_out_to_color ( & self ) -> Color32 {
self . widgets . noninteractive . bg_fill
}
/// Returned a "grayed out" version of the given color.
#[ inline(always) ]
pub fn gray_out ( & self , color : Color32 ) -> Color32 {
crate ::ecolor ::tint_color_towards ( color , self . fade_out_to_color ( ) )
}
}
@ -651,7 +673,7 @@ impl Default for Spacing {
Self {
item_spacing : vec2 ( 8.0 , 3.0 ) ,
window_margin : Margin ::same ( 6.0 ) ,
menu_margin : Margin ::same ( 1 .0) ,
menu_margin : Margin ::same ( 6 .0) ,
button_padding : vec2 ( 4.0 , 1.0 ) ,
indent : 18.0 , // match checkbox/radio-button with `button_padding.x + icon_width + icon_spacing`
interact_size : vec2 ( 40.0 , 18.0 ) ,
@ -694,8 +716,14 @@ impl Visuals {
code_bg_color : Color32 ::from_gray ( 64 ) ,
warn_fg_color : Color32 ::from_rgb ( 255 , 143 , 0 ) , // orange
error_fg_color : Color32 ::from_rgb ( 255 , 0 , 0 ) , // red
window_rounding : Rounding ::same ( 6.0 ) ,
window_shadow : Shadow ::big_dark ( ) ,
window_fill : Color32 ::from_gray ( 27 ) ,
window_stroke : Stroke ::new ( 1.0 , Color32 ::from_gray ( 60 ) ) ,
panel_fill : Color32 ::from_gray ( 27 ) ,
popup_shadow : Shadow ::small_dark ( ) ,
resize_corner_size : 12.0 ,
text_cursor_width : 2.0 ,
@ -718,7 +746,13 @@ impl Visuals {
code_bg_color : Color32 ::from_gray ( 230 ) ,
warn_fg_color : Color32 ::from_rgb ( 255 , 100 , 0 ) , // slightly orange red. it's difficult to find a warning color that pops on bright background.
error_fg_color : Color32 ::from_rgb ( 255 , 0 , 0 ) , // red
window_shadow : Shadow ::big_light ( ) ,
window_fill : Color32 ::from_gray ( 248 ) ,
window_stroke : Stroke ::new ( 1.0 , Color32 ::from_gray ( 190 ) ) ,
panel_fill : Color32 ::from_gray ( 248 ) ,
popup_shadow : Shadow ::small_light ( ) ,
. . Self ::dark ( )
}
@ -757,8 +791,8 @@ impl Widgets {
pub fn dark ( ) -> Self {
Self {
noninteractive : WidgetVisuals {
bg_fill : Color32 ::from_gray ( 27 ) , // window background
bg_stroke : Stroke ::new ( 1.0 , Color32 ::from_gray ( 60 ) ) , // separators, indentation lines, windows outlines
bg_fill : Color32 ::from_gray ( 27 ) ,
bg_stroke : Stroke ::new ( 1.0 , Color32 ::from_gray ( 60 ) ) , // separators, indentation lines
fg_stroke : Stroke ::new ( 1.0 , Color32 ::from_gray ( 140 ) ) , // normal text color
rounding : Rounding ::same ( 2.0 ) ,
expansion : 0.0 ,
@ -797,8 +831,8 @@ impl Widgets {
pub fn light ( ) -> Self {
Self {
noninteractive : WidgetVisuals {
bg_fill : Color32 ::from_gray ( 248 ) , // window background - should be distinct from TextEdit background
bg_stroke : Stroke ::new ( 1.0 , Color32 ::from_gray ( 190 ) ) , // separators, indentation lines, windows outlines
bg_fill : Color32 ::from_gray ( 248 ) ,
bg_stroke : Stroke ::new ( 1.0 , Color32 ::from_gray ( 190 ) ) , // separators, indentation lines
fg_stroke : Stroke ::new ( 1.0 , Color32 ::from_gray ( 80 ) ) , // normal text color
rounding : Rounding ::same ( 2.0 ) ,
expansion : 0.0 ,
@ -954,64 +988,8 @@ impl Spacing {
ui . add ( slider_vec2 ( item_spacing , 0. 0 . . = 20.0 , "Item spacing" ) ) ;
let margin_range = 0. 0 . . = 20.0 ;
ui . horizontal ( | ui | {
ui . add (
DragValue ::new ( & mut window_margin . left )
. clamp_range ( margin_range . clone ( ) )
. prefix ( "left: " ) ,
) ;
ui . add (
DragValue ::new ( & mut window_margin . right )
. clamp_range ( margin_range . clone ( ) )
. prefix ( "right: " ) ,
) ;
ui . label ( "Window margins x" ) ;
} ) ;
ui . horizontal ( | ui | {
ui . add (
DragValue ::new ( & mut window_margin . top )
. clamp_range ( margin_range . clone ( ) )
. prefix ( "top: " ) ,
) ;
ui . add (
DragValue ::new ( & mut window_margin . bottom )
. clamp_range ( margin_range . clone ( ) )
. prefix ( "bottom: " ) ,
) ;
ui . label ( "Window margins y" ) ;
} ) ;
ui . horizontal ( | ui | {
ui . add (
DragValue ::new ( & mut menu_margin . left )
. clamp_range ( margin_range . clone ( ) )
. prefix ( "left: " ) ,
) ;
ui . add (
DragValue ::new ( & mut menu_margin . right )
. clamp_range ( margin_range . clone ( ) )
. prefix ( "right: " ) ,
) ;
ui . label ( "Menu margins x" ) ;
} ) ;
ui . horizontal ( | ui | {
ui . add (
DragValue ::new ( & mut menu_margin . top )
. clamp_range ( margin_range . clone ( ) )
. prefix ( "top: " ) ,
) ;
ui . add (
DragValue ::new ( & mut menu_margin . bottom )
. clamp_range ( margin_range )
. prefix ( "bottom: " ) ,
) ;
ui . label ( "Menu margins y" ) ;
} ) ;
margin_ui ( ui , "Window margin:" , window_margin ) ;
margin_ui ( ui , "Menu margin:" , menu_margin ) ;
ui . add ( slider_vec2 ( button_padding , 0. 0 . . = 20.0 , "Button padding" ) ) ;
ui . add ( slider_vec2 ( interact_size , 4. 0 . . = 60.0 , "Interact size" ) )
@ -1079,6 +1057,55 @@ impl Spacing {
}
}
fn margin_ui ( ui : & mut Ui , text : & str , margin : & mut Margin ) {
let margin_range = 0. 0 . . = 20.0 ;
ui . horizontal ( | ui | {
ui . label ( text ) ;
let mut same = margin . is_same ( ) ;
ui . checkbox ( & mut same , "Same" ) ;
if same {
let mut value = margin . left ;
ui . add ( DragValue ::new ( & mut value ) . clamp_range ( margin_range . clone ( ) ) ) ;
* margin = Margin ::same ( value ) ;
} else {
if margin . is_same ( ) {
// HACK: prevent collapse:
margin . right = margin . left + 1.0 ;
margin . bottom = margin . left + 2.0 ;
margin . top = margin . left + 3.0 ;
}
ui . add (
DragValue ::new ( & mut margin . left )
. clamp_range ( margin_range . clone ( ) )
. prefix ( "L: " ) ,
)
. on_hover_text ( "Left margin" ) ;
ui . add (
DragValue ::new ( & mut margin . right )
. clamp_range ( margin_range . clone ( ) )
. prefix ( "R: " ) ,
)
. on_hover_text ( "Right margin" ) ;
ui . add (
DragValue ::new ( & mut margin . top )
. clamp_range ( margin_range . clone ( ) )
. prefix ( "T: " ) ,
)
. on_hover_text ( "Top margin" ) ;
ui . add (
DragValue ::new ( & mut margin . bottom )
. clamp_range ( margin_range )
. prefix ( "B: " ) ,
)
. on_hover_text ( "Bottom margin" ) ;
}
} ) ;
}
impl Interaction {
pub fn ui ( & mut self , ui : & mut crate ::Ui ) {
let Self {
@ -1210,9 +1237,16 @@ impl Visuals {
code_bg_color ,
warn_fg_color ,
error_fg_color ,
window_rounding ,
window_shadow ,
window_fill ,
window_stroke ,
panel_fill ,
popup_shadow ,
resize_corner_size ,
text_cursor_width ,
text_cursor_preview ,
@ -1223,7 +1257,8 @@ impl Visuals {
ui . collapsing ( "Background Colors" , | ui | {
ui_color ( ui , & mut widgets . inactive . bg_fill , "Buttons" ) ;
ui_color ( ui , & mut widgets . noninteractive . bg_fill , "Windows" ) ;
ui_color ( ui , window_fill , "Windows" ) ;
ui_color ( ui , panel_fill , "Panels" ) ;
ui_color ( ui , faint_bg_color , "Faint accent" ) . on_hover_text (
"Used for faint accentuation of interactive things, like striped grids." ,
) ;
@ -1233,8 +1268,8 @@ impl Visuals {
ui . collapsing ( "Window" , | ui | {
// Common shortcuts
ui_color ( ui , & mut widgets . noninteractive . bg _fill, "Fill" ) ;
stroke_ui ( ui , & mut widgets . noninteractive . bg _stroke, "Outline" ) ;
ui_color ( ui , window _fill, "Fill" ) ;
stroke_ui ( ui , window _stroke, "Outline" ) ;
rounding_ui ( ui , window_rounding ) ;