From cbc96614d0b41ccecbc015c8e2e2ce88d9c52744 Mon Sep 17 00:00:00 2001 From: EinTim23 Date: Sun, 12 Jan 2025 15:11:52 +0100 Subject: [PATCH] fixed placeholder text on password inputs --- .github/workflows/build.yml | 65 ++++++++++++++++++++++++------------- src/main.cpp | 34 +++++++++++++++---- 2 files changed, 70 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index caa5338..b28e20a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,14 +50,15 @@ jobs: - name: Download linuxdeploy run: | - wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage - chmod +x linuxdeploy-x86_64.AppImage + wget "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage" + wget "https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh" + chmod +x linuxdeploy-x86_64.AppImage linuxdeploy-plugin-gtk.sh sudo mv linuxdeploy-x86_64.AppImage /usr/local/bin/linuxdeploy - name: Create AppImage run: | cp -r build/PlayerLink linux/AppDir/usr/bin/ - linuxdeploy --appdir=linux/AppDir --output appimage + linuxdeploy --appdir=linux/AppDir --plugin gtk --output appimage - name: Upload AppImage artifact uses: actions/upload-artifact@v4 @@ -126,35 +127,53 @@ jobs: path: PlayerLink.dmg create-release: + if: startsWith(github.ref, 'refs/tags/') needs: [build-linux, build-windows, build-macos] - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - name: Download AppImage artifact + - name: Download artifacts uses: actions/download-artifact@v4 with: - name: PlayerLink-AppImage path: ./release-assets - - - name: Download Windows artifact - uses: actions/download-artifact@v4 - with: - name: PlayerLink-Windows-Executable - path: ./release-assets - - - name: Download macOS DMG artifact - uses: actions/download-artifact@v4 - with: - name: PlayerLink-macOS-DMG - path: ./release-assets - + merge-multiple: true + - name: Display structure of downloaded files + run: ls -R ./release-assets - name: Create GitHub Release uses: actions/create-release@v1 + id: create_release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ github.ref_name }} release_name: Release ${{ github.ref_name }} draft: false prerelease: false - files: | - ./release-assets/*.AppImage - ./release-assets/*.exe - ./release-assets/*.dmg + - name: Upload AppImage + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./release-assets/PlayerLink-x86_64.AppImage + asset_name: PlayerLink-x86_64.AppImage + asset_content_type: application/octet-stream + + - name: Upload Windows Executable + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./release-assets/PlayerLink.exe + asset_name: PlayerLink.exe + asset_content_type: application/octet-stream + + - name: Upload macOS DMG + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./release-assets/PlayerLink.dmg + asset_name: PlayerLink.dmg + asset_content_type: application/octet-stream diff --git a/src/main.cpp b/src/main.cpp index 9bb172f..5794174 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -184,30 +184,37 @@ public: const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "textCtrl") - : wxTextCtrl(parent, id, value, pos, size, style, validator, name), placeholder(""), showPlaceholder(true) { + : wxTextCtrl(parent, id, value, pos, size, style, validator, name), + placeholder(""), + showPlaceholder(true), + isPassword((style & wxTE_PASSWORD) != 0) { + Bind(wxEVT_SET_FOCUS, &wxTextCtrlWithPlaceholder::OnFocus, this); Bind(wxEVT_KILL_FOCUS, &wxTextCtrlWithPlaceholder::OnBlur, this); } void SetPlaceholderText(const wxString& p) { placeholder = p; - SetValue(placeholder); - Refresh(); + if (GetValue().IsEmpty() || showPlaceholder) + UpdatePlaceholder(); } protected: void OnFocus(wxFocusEvent& event) { - if (GetValue() == placeholder) + if (showPlaceholder && GetValue() == placeholder) { Clear(); + if (isPassword) + SetStyleToPassword(); + } showPlaceholder = false; event.Skip(); } void OnBlur(wxFocusEvent& event) { - if (GetValue().IsEmpty() || GetValue() == "") { - SetValue(placeholder); + if (GetValue().IsEmpty()) { showPlaceholder = true; + UpdatePlaceholder(); } event.Skip(); } @@ -215,6 +222,21 @@ protected: private: wxString placeholder; bool showPlaceholder; + bool isPassword; + + void UpdatePlaceholder() { + if (isPassword) + SetStyleToNormal(); + SetValue(placeholder); + } + + void SetStyleToPassword() { + SetWindowStyle(GetWindowStyle() | wxTE_PASSWORD); + } + + void SetStyleToNormal() { + SetWindowStyle(GetWindowStyle() & ~wxTE_PASSWORD); + } }; class PlayerLinkFrame : public wxFrame {