diff --git a/mainApk.pas b/mainApk.pas index f18c469..9f6ab90 100644 --- a/mainApk.pas +++ b/mainApk.pas @@ -99,7 +99,12 @@ type FLayList: TLayout; FSearch: TEdit; FSearchHint: TLabel; - FFolderBox: TComboBox; + /// Choix du dossier : un bouton peint, et un panneau de selection montre + /// a la demande. FFolders[0] est toujours « tous les dossiers ». + FBtnFolder: TRectangle; + FFolderPanel: TRectangle; + FFolderNames: TArray; + FFolderSel: Integer; FList: TListBox; FCount: TLabel; /// Icones decodees une fois par coffre, pas a chaque frappe : la liste est @@ -162,6 +167,8 @@ type procedure LockVault; procedure OnSearchChanged(Sender: TObject); + procedure OnFolderTap(Sender: TObject); + procedure OnFolderPick(Sender: TObject); procedure PopulateFolders; procedure RebuildIcons; procedure OnItemTap(const Sender: TCustomListBox; const AItem: TListBoxItem); @@ -349,7 +356,7 @@ end; procedure TForm8.BuildList; var LBar, LTop: TLayout; - LBtnLock: TRectangle; + LBtnLock, LSearchBox: TRectangle; begin FLayList := TLayout.Create(Self); FLayList.Parent := Self; @@ -394,17 +401,28 @@ begin // Pas de filtre d'etiquette : la recherche texte couvre deja les etiquettes, // en taper le nom suffit. Les dossiers, eux, ne se devinent pas. - FFolderBox := TComboBox.Create(Self); - FFolderBox.Parent := LTop; - FFolderBox.Align := TAlignLayout.Right; - FFolderBox.Width := 140; - FFolderBox.Margins.Left := 8; - FFolderBox.OnChange := OnSearchChanged; + // + // Bouton peint et non TComboBox : le combo etait l'un des deux derniers + // controles a porter encore le style, et il jurait avec le reste. + FBtnFolder := FlatButton(LTop, 'Tous les dossiers', OnFolderTap); + FBtnFolder.Align := TAlignLayout.Right; + FBtnFolder.Width := 170; + FBtnFolder.Margins.Left := 8; + + // Le champ de saisie reste natif - il faut un clavier - mais son fond vient + // de nous : LSearchBox le porte, l'editeur par-dessus est transparent. + LSearchBox := Surface(LTop); + LSearchBox.Align := TAlignLayout.Client; + LSearchBox.Fill.Color := COL_SURFACE; FSearch := TEdit.Create(Self); - FSearch.Parent := LTop; + FSearch.Parent := LSearchBox; FSearch.Align := TAlignLayout.Client; + FSearch.Margins.Rect := RectF(6, 0, 6, 0); FSearch.OnChangeTracking := OnSearchChanged; + // Gabarit transparent : present dans les styles livres. S'il manquait, on + // retomberait sur le fond du style, sans casse. + FSearch.StyleLookup := 'transparentedit'; // Invite dessinee par nous, pas par TextPrompt : Dark.style ne comporte pas // l'objet que le style est cense fournir pour l'afficher, et le champ @@ -1142,21 +1160,57 @@ begin // Le choix courant survit a un rafraichissement de fond : le voir retomber // sur "tous" tout seul, sans avoir rien touche, serait deroutant. LPrev := ''; - if FFolderBox.ItemIndex > 0 then - LPrev := FFolderBox.Items[FFolderBox.ItemIndex]; + if (FFolderSel > 0) and (FFolderSel <= High(FFolderNames)) then + LPrev := FFolderNames[FFolderSel]; - FFolderBox.Items.BeginUpdate; - try - FFolderBox.Items.Clear; - FFolderBox.Items.Add('Tous les dossiers'); - for LF in FVault.Folders do FFolderBox.Items.Add(LF); - finally - FFolderBox.Items.EndUpdate; + SetLength(FFolderNames, 1); + FFolderNames[0] := 'Tous les dossiers'; + for LF in FVault.Folders do + begin + SetLength(FFolderNames, Length(FFolderNames) + 1); + FFolderNames[High(FFolderNames)] := LF; end; - I := FFolderBox.Items.IndexOf(LPrev); - if I < 0 then I := 0; - FFolderBox.ItemIndex := I; + FFolderSel := 0; + for I := 1 to High(FFolderNames) do + if FFolderNames[I] = LPrev then FFolderSel := I; + SetButtonText(FBtnFolder, FFolderNames[FFolderSel]); +end; + +procedure TForm8.OnFolderTap(Sender: TObject); +var + I: Integer; + LRow: TRectangle; + LH: Single; +begin + Touch; + FreeAndNil(FFolderPanel); + if Length(FFolderNames) < 2 then Exit; // rien a choisir + + LH := 54; + // PLACEMENT EXPLICITE, aucune convention d'alignement : l'ordre d'empilement + // de FMX s'est revele instable des qu'on detruit et recree des enfants. + FFolderPanel := Surface(FLayList); + FFolderPanel.Align := TAlignLayout.None; + FFolderPanel.SetBounds(16, 66, FLayList.Width - 32, + Length(FFolderNames) * LH + 12); + FFolderPanel.Fill.Color := COL_SURFACE; + + for I := 0 to High(FFolderNames) do + begin + LRow := FlatButton(FFolderPanel, FFolderNames[I], OnFolderPick, I = FFolderSel); + LRow.Align := TAlignLayout.None; + LRow.SetBounds(6, 6 + I * LH, FFolderPanel.Width - 12, LH - 6); + LRow.Tag := I; + end; +end; + +procedure TForm8.OnFolderPick(Sender: TObject); +begin + if Sender is TRectangle then FFolderSel := TRectangle(Sender).Tag; + SetButtonText(FBtnFolder, FFolderNames[FFolderSel]); + FreeAndNil(FFolderPanel); + OnSearchChanged(nil); end; procedure TForm8.OnSearchChanged(Sender: TObject); @@ -1176,8 +1230,8 @@ begin Touch; FSearchHint.Visible := FSearch.Text = ''; LFolder := ''; - if FFolderBox.ItemIndex > 0 then // 0 = tous les dossiers - LFolder := FFolderBox.Items[FFolderBox.ItemIndex]; + if (FFolderSel > 0) and (FFolderSel <= High(FFolderNames)) then + LFolder := FFolderNames[FFolderSel]; // 0 = tous les dossiers FFiltered := FVault.Search(FSearch.Text, LFolder); FList.BeginUpdate;