libbhoo 0.3.0

Minimal UI foundations for SpectreOS
Documentation
1
2
3
4
5
6
7
use bhoo::*;
const VIEW:Rect=Rect{x:0.,y:0.,width:240.,height:60.};
fn frame(ui:&mut Ui,time:f64,selected:bool,enabled:bool)->Vec<DrawCommand>{ui.frame(Input{time,..Input::default()},VIEW,0.,|f|{f.radio(5,"Choice",selected,enabled);})}
fn dot_width(commands:&[DrawCommand])->f32{commands.iter().find_map(|cmd|match cmd{DrawCommand::RoundedRect{bounds,..} if bounds.width<=10.0&&bounds.height<=10.0=>Some(bounds.width),_=>None}).unwrap_or(0.0)}
#[test] fn selected_dot_grows_and_ring_has_no_background_fill(){let mut ui=Ui::default();let initial=frame(&mut ui,0.,false,true);assert!(initial.iter().any(|cmd|matches!(cmd,DrawCommand::Outline{bounds,width,..} if bounds.width==20.0&&*width==2.0)));assert!(!initial.iter().any(|cmd|matches!(cmd,DrawCommand::RoundedRect{bounds,color,..} if bounds.width==16.0&&*color==ui.theme.background)));frame(&mut ui,1.,true,true);let mid=frame(&mut ui,1.08,true,true);let w=dot_width(&mid);assert!(w>0.0&&w<10.0,"{w}");assert_eq!(dot_width(&frame(&mut ui,1.4,true,true)),10.0);}
#[test] fn reduced_motion_and_disabled_selection_are_immediate(){let mut ui=Ui::default();frame(&mut ui,0.,false,true);ui.motion_preference=MotionPreference::Reduced;assert_eq!(dot_width(&frame(&mut ui,1.,true,true)),10.0);ui.motion_preference=MotionPreference::Full;let mut disabled=Ui::default();let cmds=frame(&mut disabled,1.,true,false);assert_eq!(dot_width(&cmds),10.0);assert!(cmds.iter().any(|cmd|matches!(cmd,DrawCommand::Outline{color,..} if *color==disabled.theme.text.opacity(0.38))));}
#[test] fn rtl_group_mirrors_indicators_and_preserves_selection_behavior(){let mut ui=Ui::default();let mut selected=11;let choices=[Choice{id:11,label:"One",enabled:true},Choice{id:12,label:"Two",enabled:true},Choice{id:13,label:"Disabled",enabled:false}];let b=Rect{x:0.,y:0.,width:240.,height:240.};let commands=ui.frame(Input::default(),b,0.,|f|{f.radio_group_directional(10,"Group",&choices,&mut selected,true,true);});assert!(commands.iter().any(|c|matches!(c,DrawCommand::Outline{bounds,..} if bounds.x==210.&&bounds.width==20.)));assert!(commands.iter().any(|c|matches!(c,DrawCommand::Text{text,bounds,style,..} if text.as_ref()=="One"&&bounds.x==0.&&style.align==2)));let second=ui.semantics().iter().find(|n|n.label.as_ref()=="Two").unwrap().bounds;let p=Some([second.x+20.,second.y+20.]);for (pressed,released,time) in [(true,false,1.),(false,true,1.1)] {ui.frame(Input{pointer:p,pressed,released,time,..Input::default()},b,0.,|f|{f.radio_group_directional(10,"Group",&choices,&mut selected,true,true);});}assert_eq!(selected,12);}